Skip to content

Instantly share code, notes, and snippets.

@koistya
Last active August 16, 2018 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koistya/8f82c63201b0bd079e5b18ff746c5cc8 to your computer and use it in GitHub Desktop.
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
#!/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