Last active
August 16, 2018 09:32
-
-
Save koistya/8f82c63201b0bd079e5b18ff746c5cc8 to your computer and use it in GitHub Desktop.
Deploy a specific Git commit to Firebase using Cloud Build. Example: ./deploy.sh $COMMIT_SHA
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
#!/bin/bash | |
COMMIT_SHA=$1 | |
PROJECT=bay6-next | |
REPO_NAME=github-<user/organisation>-<repo> | |
BUILD_BUCKET=gs://builds.example.com | |
TOKEN=$(gcloud auth application-default print-access-token) | |
curl https://cloudbuild.googleapis.com/v1/projects/${PROJECT}/builds \ | |
--request POST \ | |
--header "Content-Type: application/json" \ | |
--header "Authorization: Bearer $TOKEN" \ | |
--data @- << EOF | |
{ | |
"source": { | |
"repoSource": { | |
"projectId": "$PROJECT", | |
"repoName": "$REPO_NAME", | |
"commitSha": "$COMMIT_SHA" | |
} | |
}, | |
"tags": [ | |
"deploy" | |
], | |
"steps": [ | |
{ | |
"name": "gcr.io/cloud-builders/gsutil", | |
"args": [ | |
"cp", | |
"gs://$BUILD_BUCKET/$COMMIT_SHA.tar.gz", | |
"$COMMIT_SHA.tar.gz" | |
] | |
}, | |
{ | |
"name": "alpine", | |
"entrypoint": "tar", | |
"args": [ | |
"-xzvf", | |
"$COMMIT_SHA.tar.gz" | |
] | |
}, | |
{ | |
"name": "gcr.io/$PROJECT/firebase", | |
"args": [ | |
"deploy", | |
"--project", | |
"$PROJECT", | |
"--token", | |
"<token>" | |
] | |
} | |
] | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment