-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·48 lines (40 loc) · 2.1 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# This is optimized for CircleCI
# Thanks to: https://github.com/circleci/docker-hello-google
# user defined variables:
# - REPO_NAME
# - PROJECT_NAME
# - CLUSTER_NAME
# - CLOUDSDK_COMPUTE_ZONE
# - GCLOUD_SERVICE_KEY
# Exit on any error
set -e
# Kubernetes Configuration
IMAGE_REGISTRY="us.gcr.io"
if [ ! -z "$GITHUB_API_TOKEN" ]; then
RELEASE_TAG_NAME="v1.$CIRCLE_BUILD_NUM.0"
curl -H "Content-Type: application/json" -H "Authorization: token ${GITHUB_API_TOKEN}" -X POST -d '{"tag_name":"'$RELEASE_TAG_NAME'","name":"'$REPO_NAME' '$RELEASE_TAG_NAME'"}' https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/releases
echo "Released $RELEASE_TAG_NAME on github"
fi
if [ -z "$GCLOUD_SERVICE_KEY" ]; then
echo "GCLOUD_SERVICE_KEY is not set on your CI"
exit 1;
else
# Update k8s and log in
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update kubectl
echo $GCLOUD_SERVICE_KEY | base64 --decode -i > ${HOME}/account-auth.json
sudo /opt/google-cloud-sdk/bin/gcloud auth activate-service-account --key-file ${HOME}/account-auth.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 container clusters get-credentials $CLUSTER_NAME
# Deploy
sudo /opt/google-cloud-sdk/bin/gcloud docker -- push $IMAGE_REGISTRY/$PROJECT_NAME/$REPO_NAME:$CIRCLE_BUILD_NUM
sudo /opt/google-cloud-sdk/bin/gcloud docker -- push $IMAGE_REGISTRY/$PROJECT_NAME/$REPO_NAME:latest
sudo chown -R ubuntu:ubuntu /home/ubuntu/.kube
sudo GOOGLE_APPLICATION_CREDENTIALS=${HOME}/account-auth.json /opt/google-cloud-sdk/bin/kubectl set image deployment/$REPO_NAME $REPO_NAME=$IMAGE_REGISTRY/$PROJECT_NAME/$REPO_NAME:$CIRCLE_BUILD_NUM
sudo GOOGLE_APPLICATION_CREDENTIALS=${HOME}/account-auth.json /opt/google-cloud-sdk/bin/kubectl rollout status deployment/$REPO_NAME
fi
echo "Deployed !"
exit 0;