Skip to content

Instantly share code, notes, and snippets.

@markhilton
Created January 15, 2021 20:00
Show Gist options
  • Save markhilton/3d53b2edcbbce584f1844dfc484f4ea7 to your computer and use it in GitHub Desktop.
Save markhilton/3d53b2edcbbce584f1844dfc484f4ea7 to your computer and use it in GitHub Desktop.
Cloud Build for Firebase NodeJS app with start/complete/fail slack notifications
steps:
# build docker image
- name: "gcr.io/cloud-builders/docker"
entrypoint: "bash"
args:
- "-c"
- |
curl -X POST -H "Content-type: application/json" --data \
'{"text":"`gcr.io/$PROJECT_ID/$REPO_NAME:$BRANCH_NAME$TAG_NAME` build ID `$BUILD_ID` started!"}' $_WEBHOOK_URL
docker build \
--build-arg PROJECT_ID=$PROJECT_ID \
--build-arg NPM_TOKEN=$_NPM_TOKEN \
--build-arg FIREBASE_TOKEN=$_FIREBASE_TOKEN \
-t gcr.io/$PROJECT_ID/$REPO_NAME:$BRANCH_NAME$TAG_NAME . \
&& curl -X POST -H "Content-type: application/json" --data \
'{"text":"`gcr.io/$PROJECT_ID/$REPO_NAME:$BRANCH_NAME$TAG_NAME` build ID `$BUILD_ID` completed!"}' $_WEBHOOK_URL \
|| curl -X POST -H "Content-type: application/json" --data \
'{"text":"`gcr.io/$PROJECT_ID/$REPO_NAME:$BRANCH_NAME$TAG_NAME` build ID `$BUILD_ID` failed!"}' $_WEBHOOK_URL
timeout: 1500s
# push docker image to the repository
- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/$REPO_NAME:$BRANCH_NAME$TAG_NAME"]
timeout: 1500s
# store artifact
images: ["gcr.io/$PROJECT_ID/$REPO_NAME:$BRANCH_NAME$TAG_NAME"]
# user high CPU machine for the build
# options:
# machineType: "N1_HIGHCPU_8"
# arguments
substitutions:
_NPM_TOKEN: default_npm_access_token
_FIREBASE_TOKEN: default_firebase_deployment_token
_WEBHOOK_URL: default_slack_notification_webhook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment