github.com/GoogleContainerTools/kaniko@v1.23.0/run_in_docker.sh (about) 1 #!/bin/bash 2 3 # Copyright 2018 Google LLC 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -e 18 19 if [ $# -lt 3 ]; then 20 echo "Usage: run_in_docker.sh <path to Dockerfile> <context directory> <image tag> <cache>" 21 exit 1 22 fi 23 24 dockerfile=$1 25 context=$2 26 destination=$3 27 28 cache="false" 29 if [[ ! -z "$4" ]]; then 30 cache=$4 31 fi 32 33 if [[ $destination == *"gcr"* ]]; then 34 if [[ ! -e $HOME/.config/gcloud/application_default_credentials.json ]]; then 35 echo "Application Default Credentials do not exist. Run [gcloud auth application-default login] to configure them" 36 exit 1 37 fi 38 docker run \ 39 -v "$HOME"/.config/gcloud:/root/.config/gcloud \ 40 -v "$context":/workspace \ 41 gcr.io/kaniko-project/executor:latest \ 42 --dockerfile "${dockerfile}" --destination "${destination}" --context dir:///workspace/ \ 43 --cache="${cache}" 44 else 45 docker run \ 46 -v "$context":/workspace \ 47 gcr.io/kaniko-project/executor:latest \ 48 --dockerfile "${dockerfile}" --destination "${destination}" --context dir:///workspace/ \ 49 --cache="${cache}" 50 fi