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
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.
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
I have seen similar questions to this but I have a specific use case here which maybe be of interest, I am receiving an error which obviously means firebase-functions is not being installed properly on docker container, everything work fine on local.
Entire deployment works perfect and file structure created in docker container looks right, with node_modules being placed in correct folder, everything.
Does docker need to be enabled to expose port to firebase deploy to get correct download? Anyone have experience with this?
Error
[2022-10-08T08:09:34.513Z] Building nodejs source
i functions: Loaded environment variables from .env.development.
[2022-10-08T08:09:34.518Z] Could not find functions.yaml. Must use http discovery
[2022-10-08T08:09:34.533Z] Error: spawn ./node_modules/.bin/firebase-functions ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
action.yml
deploy-cloud:
name: Deploy Cloud
needs: e2e-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: '16'
- name: Checkout Repo
uses: actions/checkout#master
- name: Make envfile
uses: docker://xxxxxx/create-envfile:master
with:
...env vars...
directory: functions
file_name: .env.development
fail_on_empty: false
- name: Install Dependencies
working-directory: functions
run: yarn
- name: Build
working-directory: functions
run: yarn build
- name: Deploy to Firebase
uses: docker://xxxxxx/firebase-action:master
with:
args: deploy --project development --only functions --debug
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Dockerfile for deploy action
FROM node:16.16.0-buster
LABEL version="0.0.1"
LABEL repository="https://github.com/xxxxxx/firebase-action"
LABEL homepage="https://github.com/xxxxxx/firebase-action"
LABEL maintainer="xxxxxx"
LABEL com.github.actions.name="GitHub Action for Firebase"
LABEL com.github.actions.description="Wraps the firebase-tools CLI to enable common commands."
LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="gray-dark"
RUN apt update && apt-get install -y jq openjdk-11-jre
RUN npm i -g npm#8.10.0
RUN npm i -g firebase-tools#11.8.0
COPY LICENSE README.md /
COPY "entrypoint.sh" "/entrypoint.sh"
ENTRYPOINT ["/entrypoint.sh"]
CMD ["--help"]
I can confirm downgrading to firebase-tools 10.0.0 fixes this issue
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'm trying to build and then deploy the artifacts (jar) by the bitbucket pipeline. The build is working but the deploy of the artifacts doesnt work as I want it.
When the pipeline is finished I have all code files (src/main/java etc) instead of the jar on the ftp server.
Do you see where I do the mistake? Actually I also looked for a another ftp function but failed.
Pipeline:
# This is a sample build configuration for Java (Maven).
# Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: maven:3.3.9
pipelines:
default:
- step:
name: Build
caches:
- maven
script:
- apt-get update
- apt-get install -y openjfx
- mvn install -DskipTests
artifacts:
- /opt/atlassian/pipelines/agent/build/target/**
- target/**
# - /**.jar
- step:
name: Deploy
script:
- apt-get update
- apt-get -qq install git-ftp
- git ftp init --user $user --passwd $pw -v sftp://$host:5544/$folder
To solve this problem I added the SSH-Key to Bitbucket. Then I could do the deploy by sftp using lftp and docker images.
pipelines:
branches:
master:
- step:
name: Build
image: tgalopin/maven-javafx
caches:
- maven
script:
- mvn install
artifacts:
- target/**
- step:
name: Deploy
image: alpacadb/docker-lftp
script:
- lftp sftp://$user:$pw#$host:$port -e "put /my-file; bye"