-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #55: Update CircleCI config to automatically deploy application
The build config now creates a new Docker image, tags it with latest, pushes it to Google Container Registry and deploys to Google Compute Engine.
- Loading branch information
1 parent
a8fc5c1
commit 68ad40f
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "$IMAGE_NAME" ]; then | ||
echo "IMAGE_NAME env variable is empty. Exiting." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$GOOGLE_PROJECT_ID" ]; then | ||
echo "GOOGLE_PROJECT_ID env variable is empty. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Authenticate to Google Container Registry | ||
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io | ||
|
||
if [ "$CIRCLE_BRANCH" = "issue_55_cd" ]; then | ||
echo "Deploying application to Staging environment" | ||
|
||
# Injects firebase DB file | ||
echo $FIREBASE_DB_STAG | base64 -di > src/db/firebaseDB/keys/index.js | ||
|
||
# Builds Docker image | ||
docker build -t ${IMAGE_NAME} . | ||
|
||
# Tags newly created image | ||
docker tag ${IMAGE_NAME} gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:stag | ||
|
||
# Pushes image to Container Registry | ||
docker push gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:stag | ||
|
||
# Deploys application | ||
gcloud --quiet compute ssh stick-sessions --zone us-east1-b -- "cd /home/app && ./restart_service.sh gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:stag" | ||
elif [ "$CIRCLE_BRANCH" = "master" ]; then | ||
echo "Deploying application to Production environment" | ||
|
||
# Injects firebase DB file | ||
echo $FIREBASE_DB | base64 -di > src/db/firebaseDB/keys/index.js | ||
|
||
# Builds Docker image | ||
docker build -t ${IMAGE_NAME} . | ||
|
||
# Tags newly created image | ||
docker tag ${IMAGE_NAME} gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:${CIRCLE_SHA1} | ||
docker tag ${IMAGE_NAME} gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:latest | ||
|
||
# Pushes image to Container Registry | ||
docker push gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:${CIRCLE_SHA1} | ||
docker push gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:latest | ||
|
||
# Deploys application | ||
gcloud --quiet compute ssh stick-sessions --zone us-east1-b -- "cd /home/app && ./restart_service.sh gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_NAME}:latest" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "$GCLOUD_SERVICE_KEY" ]; then | ||
echo "GCLOUD_SERVICE_KEY env variable is empty. Exiting." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$GOOGLE_PROJECT_ID" ]; then | ||
echo "GOOGLE_PROJECT_ID env variable is empty. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Set service account key | ||
echo $GCLOUD_SERVICE_KEY | base64 -di > ${HOME}/gcloud-service-key.json | ||
|
||
# Authenticate gcloud | ||
gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json | ||
|
||
# Set project ID | ||
gcloud --quiet config set project ${GOOGLE_PROJECT_ID} |