Im trying to setup a CI/CD pipeline but it keeps failing for my react app.
here is the script:
image: node:latest
.deploy: &deploy
- npm install -g firebase-tools
- firebase use $FIREBASE_PROJECT_ID --token $FIREBASE_TOKEN
- yarn
- yarn build
stages:
- deploy
deploy_preview:
stage: deploy
before_script:
- *deploy
script:
- firebase hosting:channel:deploy $FIREBASE_PROJECT_ID --token $FIREBASE_TOKEN
- echo "ENVIRONMENT_URL=$(firebase hosting:channel:open live --non-interactive | tail -1 | awk '{ print $3 }')"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
staging:
stage: deploy
before_script:
- *deploy
only:
- staging
script:
- firebase deploy -m "Pipe $CI_PIPELINE_ID Build $CI_BUILD_ID" --only hosting:staging --non-interactive --token $FIREBASE_TOKEN
production:
stage: deploy
before_script:
- *deploy
only:
- main
when: manual
allow_failure: false
script:
- firebase deploy -m "Pipe $CI_PIPELINE_ID Build $CI_BUILD_ID" --only hosting:prod --non-interactive --token $FIREBASE_TOKEN
but I keep getting the error:
added 612 packages in 22s
34 packages are looking for funding
run `npm fund` for details
$ firebase use $FIREBASE_PROJECT_ID --token $FIREBASE_TOKEN
error: option '--token <token>' argument missing
Cleaning up project directory and file based variables
ERROR: Job failed: exit code
from gitlab about why the pipeline is failing
Im not sure why its complaining about the token. I do have the gitlab variables also set up correctly.
Found out that its because the var was PROTECTED, which means only the branches that were PROTECTED would work with it
Related
I'm following this Medium article to deploy firebase functions using Github actions.
This is the workflow in .github/workflows/firebase-deploy.yml
name: Deploy Cloud Functions
on:
workflow_dispatch:
push:
branches:
- master
- pre-production
- github-actions
- "feature/**"
paths:
- "functions/**"
jobs:
build_and_deploy:
runs-on: macos-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 16.x
- uses: actions/cache#v2
with:
path: ~/.npm
key: macOS-node-${{ hashFiles('**/functions/package-lock.json') }}
restore-keys: |
macOS-node-
- name: Build Cloud Functions
run: npm ci
working-directory: functions
- name: Create SA key
run: echo '${{ secrets.FIREBASE_DEV_SERVICE_ACCOUNT }}' > gcloud.json
working-directory: functions
- name: Print json
run: echo "$(cat gcloud.json)"
working-directory: functions
- name: Install firebase tools
run: npm install -g firebase-tools
working-directory: functions
- name: Deploy Cloud Functions
run: export GOOGLE_APPLICATION_CREDENTIALS=gcloud.json && npx firebase-tools deploy --only functions --json
working-directory: functions
In the step Deploy Cloud Functions of the github action, I get the following error:
Run export GOOGLE_APPLICATION_CREDENTIALS=gcloud.json && npx firebase-tools deploy --only functions --json
export GOOGLE_APPLICATION_CREDENTIALS=gcloud.json && npx firebase-tools deploy --only functions --json
shell: /bin/bash -e ***0***
***
"status": "error",
"error": "No project active, but project aliases are available.\n\nRun \u001b[1mfirebase use <alias>\u001b[22m with one of these options:\n\n dev (web3army-pre-prod)\n prod (blockchainarmy-6ed76)"
***
Error: Process completed with exit code 1.
When deploying normally on the terminal without github actions, I use firebase use dev. Here the project dev is specified inside the json that I created with the google service account and also used to create the secret in the repo as explained in the tutorial. It seems like that GOOGLE_APPLICATION_CREDENTIALS is not initialized correctly with gcloud.json.
I tried to print the content of the json to check if it was okay but the result is encrypted with ***, so it's difficult to understand what is going wrong. Thanks a lot.
I'm using Firebase to host my personal website and wanted to integrate CircleCI for faster integration. However I receive this error on the step for deployment:
Note
Adding sudo before the deploy command causes the build to fail also
/home/circleci/project/node_modules/configstore/index.js:52
throw error;
^
Error: EACCES: permission denied, open '/home/circleci/.config/configstore/firebase-tools.json'
You don't have access to this file.
Below is my project's yaml configuration:
---
commands:
restore_cache_cmd:
description: "Restore cached npm install"
steps:
- restore_cache:
key: 'dependency-cache-{{checksum "package.json"}}'
save_cache_cmd:
description: "Saving npm install"
steps:
- save_cache:
key: 'dependency-cache-{{ checksum "package.json"}}'
paths:
- "./node_modules"
update:
description: "Installing project's dependencies"
steps:
- checkout
- restore_cache_cmd
- run: sudo npm i -g npm#latest
- run: sudo npm i
- save_cache_cmd
build_deploy:
description: "Building project"
steps:
- run:
name: Build
command: sudo npm run build
- run:
name: Deploy
command: ./node_modules/.bin/firebase deploy --token=$FIREBASE_DEPLOY_TOKEN -- only hosting
executors:
docker-executor:
docker:
- image: "cimg/node:12.14.1"
jobs:
build_site:
executor: docker-executor
working_directory: ~/Darryls-Personal-Site
steps:
- update
- build_deploy
version: 2.1
workflows:
build_site:
jobs:
- build_site:
filters:
branches:
only: master
Steps that I have already completed from other questions:
Used firebase login:ci to obtain refresh token and placed into an environment variable within my CircleCI project environment
Used npm install --save-dev firebase-tools
I think the problem is that you run all your npm commands with sudo except the firebase deploy command.
You should definitely run everything with the current user and not the superuser.
You will see in official tutorials that nothing is run with sudo except for very specific cases.
Also, instead of doing this ./node_modules/.bin/firebase deploy you could use npx run firebase deploy which first look in the local node_modules then in the global ones.
I followed this blog to deploy my Gatsby site to Firebase using circleCI
https://circleci.com/blog/automatically-deploy-a-gatsby-site-to-firebase-hosting/
The config.yml file is as follows
# CircleCI Firebase Deployment Config
version: 2
jobs:
build:
docker:
- image: circleci/node:10
working_directory: ~/gatsby-site
steps:
- checkout
- restore_cache:
keys:
# Find a cache corresponding to this specific package-lock.json
- v1-npm-deps-{{ checksum "package-lock.json" }}
# Fallback cache to be used
- v1-npm-deps-
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: v1-npm-deps-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- run:
name: Gatsby Build
command: npm run build
- run:
name: Firebase Deploy
command: ./node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN"
This caused an error
#!/bin/bash -eo pipefail
./node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN"
/bin/bash: ./node_modules/.bin/firebase: No such file or directory
Exited with code exit status 127
CircleCI received exit code 127
I haven't used yml files or focused on devops before so did some digging around. Found a few other people with this issue and there was a suggestion to use workspaces and workflow. So I amended my yml file to support this
# CircleCI Firebase Deployment Config
version: 2
jobs:
#build jobs
build:
docker:
- image: circleci/node:10
working_directory: ~/gatsby-site
steps:
- checkout
- restore_cache:
keys:
# Find a cache corresponding to this specific package-lock.json
- v1-npm-deps-{{ checksum "package-lock.json" }}
# Fallback cache to be used
- v1-npm-deps-
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: v1-npm-deps-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- persist_to_workspace:
root: ./
paths:
- ./
- run:
name: Gatsby Build
command: npm run build
- persist_to_workspace:
root: ./
paths:
- ./
# deploy jobs
deploy-production:
docker:
- image: circleci/node:10
steps:
- attach_workspace:
at: ./
- run:
name: Firebase Deploy
command: ./node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN"
workflows:
version: 2
build:
jobs:
#build
- build
#deploy
- deploy-production:
requires:
- build
Same issue
#!/bin/bash -eo pipefail
./node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN"
/bin/bash: ./node_modules/.bin/firebase: No such file or directory
Exited with code exit status 127
CircleCI received exit code 127
I assume it must be something to do with the paths and it's looking in the wrong directory? Any idea of how I can get it to find the module required?
Apparently I can't read. The fix was in the instructions
We’ll also need to install the firebase-tools package locally to our
project as a devDependency. This will come in handy later on when
integrating with CircleCI, which does not allow installing packages
globally by default. So let’s install it right now:
npm install -D firebase-tools
I have a react project that is hosted in firebase. I am using circleci for builds. This has been working fine. However, I want to include firebase firestore rules and index config and firebase storeage rules in the build.
I have added them to my firebase.json file as follows:
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
}
If I do a firebase deployment from the command line, the rules and indexes I've configured work fine.
My problem comes when I try and do a build in circleci. I get to the deploying stage and then I get this error:
i deploying firestore, hosting
Error: Error reading rules file firestore.rules
Exited with code 1
This is the relevant part of the config.yml:
deploy_uat:
docker:
- image: google/cloud-sdk
steps:
- run: echo $(printenv)
- type: shell
name: "Provisioning infrastructure"
command: |
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get -qq install -y build-essential nodejs
echo "node version -> $(node --version)"
echo "npm version -> $(npm --version)"
# Firebase tools include native code and need npm 5.x to install into a special dir since it won't have permission to access '/usr/lib/node_modules/'
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
npm install -g firebase-tools
- type: shell
name: "Downloading & configuring archive prior to deployment"
command: |
echo ${GCP_SERVICE_ACCOUNT_AMCE_API_ADMIN_CIRCLECI} | base64 --decode > key.json
gcloud auth activate-service-account --key-file key.json
gcloud config set compute/zone us-central1
gcloud config set project AMCE-45
mkdir tmp
cd tmp
gsutil cp gs://AMCE-45-AMCE-admin-archive-web/${CIRCLE_PROJECT_REPONAME}-${CIRCLE_SHA1}.tgz .
tar xfz ${CIRCLE_PROJECT_REPONAME}-${CIRCLE_SHA1}.tgz
ls -al
- type: shell
name: "Deploying"
command: |
export PATH=~/.npm-global/bin:$PATH
ls -al build
echo "Using env -> $(cat build/env.js)"
firebase list --token "${FIREBASE_AUTH_TOKEN_AMCE_WEB_CUSTOMER_UAT}"
firebase deploy -P uat --token "${FIREBASE_AUTH_TOKEN_AMCE_WEB_CUSTOMER_UAT}"
Is there some additional dependency that I need to add? I've played around trying to add various firebase dependencies but just generate errors.
After a nights sleep, the solution was obvious...
I hadn't added firestore.rules, storage.rules and firestore.indexes.json to my config.yml file. Once I added them it built fine.
ls -al
tar -zcvf ${CIRCLE_PROJECT_REPONAME}-${CIRCLE_SHA1}.tgz .firebaserc firebase.json firestore.rules storage.rules firestore.indexes.json build
I want to deploy from Travis multiple firebase hosting projects at the same time that is possible??, if yes I gonna be happy :)
Because I have 10 projects right now that all are the same code I think is easier for me to deploy from 1 git repo to all my websites at the same time, now I do that 1 in the time and is take me 4-5 hours to do that
my .travis.yml
language: node_js
node_js:
- "7"
branches:
only:
- master
before_script:
- npm install -g firebase-tools
- npm install -g #angular/cli
script:
- ng build --prod
after_success:
- firebase deploy --token $FIREBASE_TOKEN_1 <-- this is for https://project1.firebaseapp.com
- firebase deploy --token $FIREBASE_TOKEN_2 <-- this is for https://project2.firebaseapp.com
- firebase deploy --token $FIREBASE_TOKEN_3 <-- this is for https://project3.firebaseapp.com
- firebase deploy --token $FIREBASE_TOKEN_4 <-- this is for https://project4.firebaseapp.com
- firebase deploy --token $FIREBASE_TOKEN_5 <-- this is for https://project5.firebaseapp.com
- firebase deploy --token $FIREBASE_TOKEN_6 <-- this is for https://project6.firebaseapp.com
notifications:
email:
on_failure: change
on_success: change
Is that possible?
Yes, absolutely. Just declare the projects in your .firebaserc file
{
"projects": {
"project1": "firebase-project-id-1",
"project1": "firebase-project-id-1",
...
"project10": "firebase-project-id-10"
}
}
And then you just switch active project between each firebase deploy
- firebase use project1 --token $FIREBASE_DEPLOY_KEY1
- firebase deploy --non-interactive --token $FIREBASE_DEPLOY_KEY1
...
- firebase use project10 --token $FIREBASE_DEPLOY_KEY10
- firebase deploy --non-interactive --token $FIREBASE_DEPLOY_KEY10
Building on Dennis' great answer. After configuring the aliases, you can simplify even a little bit more.
Instead of switching the 'active' project with firebase use, you can explicitly set the project for the current command, i.e. when deploying you can set the corresponding project using the -P or --project flag
firebase deploy --token $FIREBASE_TOKEN_1 -P project1
or
firebase deploy --token $FIREBASE_TOKEN_1 --project project1
From the documentation:
You can override what's being used as the currently active project by passing the --project flag with any CLI command. [...] If you want to run a single command against the Firebase project that you've assigned the prod alias, then you can run, for example, firebase deploy --project=prod.
... or in the help section of the CLI:
$ firebase --help | grep '\--project'
-P, --project <alias_or_project_id> the Firebase project to use for this command
One more addition: I assume that you have access to all the projects with the same user. This is not explicitly specified in the documentation, but the tokens are associated with your user, not the project. That means you should be able to use the same token to successfully deploy to every environment.
So, your build script could be reduced to
after_success:
- firebase deploy --token $FIREBASE_TOKEN -P project1
- firebase deploy --token $FIREBASE_TOKEN -P project2
- firebase deploy --token $FIREBASE_TOKEN -P project3
- firebase deploy --token $FIREBASE_TOKEN -P project4
- firebase deploy --token $FIREBASE_TOKEN -P project5
- firebase deploy --token $FIREBASE_TOKEN -P project6