Skip to content

Commit

Permalink
Add support for GCP_SA_KEY as an alternative to FIREBASE_TOKEN (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torbjørn Vatn authored Feb 7, 2020
1 parent 17e2620 commit 40e688f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

.history/
.idea/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ COPY LICENSE README.md /
COPY "entrypoint.sh" "/entrypoint.sh"

ENTRYPOINT ["/entrypoint.sh"]
CMD ["--help"]
CMD ["--help"]
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ This Action for [firebase-tools](https://github.com/firebase/firebase-tools) ena

## Environment variables

* `FIREBASE_TOKEN` - **Required**. The token to use for authentication. This token can be aquired through the `firebase login:ci` command.
* `FIREBASE_TOKEN` - **Required if GCP_SA_KEY is not set**. The token to use for authentication. This token can be aquired through the `firebase login:ci` command.

* `GCP_SA_KEY` - **Required if FIREBASE_TOKEN is not set**. A base64 encoded private key (json format) for a Service Account with the `Firebase Admin` role in the project, and if your deploying functions you would also need the `Cloud Functions Developer` role.
And since the deploy service account is using the App Engine default service account in the deploy process, it also
needs the `Service Account User` role.
If your only doing Hosting `Firebase Hosting Admin` is enough.

* `PROJECT_ID` - **Optional**. To specify a specific project to use for all commands, not required if you specify a project in your `.firebaserc` file.

Expand Down Expand Up @@ -60,6 +65,13 @@ jobs:
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
```
Alternatively:
```yaml
env:
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
```
If you have multiple hosting environments you can specify which one in the args line.
e.g. `args: deploy --only hosting:[environment name]`
Expand Down
17 changes: 12 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

set -e

if [ -z "$FIREBASE_TOKEN" ]; then
echo "FIREBASE_TOKEN is required to run commands with the firebase cli"
exit 126
if [ -z "$FIREBASE_TOKEN" ] && [ -z "$GCP_SA_KEY" ]; then
echo "Either FIREBASE_TOKEN or GCP_SA_KEY is required to run commands with the firebase cli"
exit 126
fi

if [ -n "$GCP_SA_KEY" ]; then
echo "Storing GCP_SA_KEY in /opt/gcp_key.json"
echo "$GCP_SA_KEY" | base64 -d > /opt/gcp_key.json
echo "Exporting GOOGLE_APPLICATION_CREDENTIALS=/opt/gcp_key.json"
export GOOGLE_APPLICATION_CREDENTIALS=/opt/gcp_key.json
fi

if [ -n "$PROJECT_PATH" ]; then
cd $PROJECT_PATH
cd "$PROJECT_PATH"
fi

if [ -n "$PROJECT_ID" ]; then
echo "setting firebase project to $PROJECT_ID"
firebase use --add $PROJECT_ID
firebase use --add "$PROJECT_ID"
fi

sh -c "firebase $*"

0 comments on commit 40e688f

Please sign in to comment.