For our CD process we need to install the Google Cloud Engine CLI and Kubernetes CLI. Installing these are where most of our time is spent. Is there a way to cache them, and only run the commands if there is no cache?
Here are the commands
- sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update --version 131.0.0
- sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update --version 131.0.0 kubectl
- echo $GCLOUD_SERVICE_KEY | base64 --decode -i > ${HOME}/gcloud-service-key.json
- sudo /opt/google-cloud-sdk/bin/gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json
- sudo /opt/google-cloud-sdk/bin/gcloud config set project $PROJECT_NAME
- sudo /opt/google-cloud-sdk/bin/gcloud --quiet config set container/cluster $CLUSTER_NAME
- sudo /opt/google-cloud-sdk/bin/gcloud config set compute/zone ${CLOUDSDK_COMPUTE_ZONE}
- sudo /opt/google-cloud-sdk/bin/gcloud --quiet container clusters get-credentials $CLUSTER_NAME
- docker build -t us.gcr.io/${PROJECT_NAME}/${APP_NAME}:$CIRCLE_SHA1 .
- docker tag us.gcr.io/${PROJECT_NAME}/${APP_NAME}:$CIRCLE_SHA1 us.gcr.io/${PROJECT_NAME}/${APP_NAME}:latest
- sudo /opt/google-cloud-sdk/bin/gcloud --quiet container clusters get-credentials ${CLUSTER_NAME}
- sudo /opt/google-cloud-sdk/bin/gcloud docker push us.gcr.io/${PROJECT_NAME}/${APP_NAME}
- sudo chown -R ubuntu:ubuntu /home/ubuntu/.kube
- /opt/google-cloud-sdk/bin/kubectl patch deployment ${APP_NAME} -p '{"spec":{"template":{"spec":{"containers":[{"name":"'"${APP_NAME}"'","image":"us.gcr.io/'"${PROJECT_NAME}"'/'"${APP_NAME}"':'"$CIRCLE_SHA1"'"}]}}}}'