How to use CircleCI Environment Variables in Firebase Functions - node.js

I'm new to Continous Intregration and recently I setup my first project in CircleCI.
Unfortunately I seems like it's not completely working as expected.
I want to deploy my application to Firebase (Hosting and Functions).
Of course I added Environment Variables to the project in CircleCI.
But Firebase Functions doesn't access my Environment Variables so it's running into errors.
In the Functions folder I created a new nodejs application incl. the dotenv package and I'm calling the variables with process.env.CIRCLECI_VARIABLE.
Would be great if someone could give me a hint what's missing.
config.yml
version: 2.1
jobs:
build:
docker:
- image: circleci/node:10
steps:
- checkout
- run:
name: Install packages
command: yarn install
- run:
name: Build project
command: yarn build
- run:
name: Install functions packages
command: cd ./functions && yarn install
deploy:
docker:
- image: circleci/node:10
steps:
- checkout
- run:
name: Install packages
command: yarn install
- run:
name: Build project
command: yarn build
- run:
name: Install functions packages
command: cd ./functions && yarn install
- run:
name: Installing Firebase-Tools
command: yarn add firebase-tools
- run:
name: Firebase Deploy
command: ./node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN"
workflows:
build_and_deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master

I've found the solution
I didn't know that I have to add the Environment Variables to the Google Cloud Function.
Now everything is working as expected

Related

Serverless command "offline" not found Node 14.X

Description problem
I have a problem with serverless-offline because I try to install this local and global, and it doesn't work.
serverless-offline image error
When executing the command I get this information
sls offline
Serverless command "offline" not found. Run "serverless help" for a list of all available commands.
This is my configuration in the serverless file.
provider:
name: aws
runtime: nodejs14.x
environment:
NODE_ENV: ${env:NODE_ENV}
plugins:
- serverless-plugin-typescript
- serverless-offline
This commands I used to install
In the machine environment
npm i -g serverless-offline
In the file project:
yarn add serverless-offline -D
Issue in git
Serverles environment configurated image
Try in your project with the npx prefix. So npx sls offline or npx serverless offline.

CircleCI: Use nodejs version 12

My CircleCI file is provided:
version: 2.1
orbs:
node: circleci/node#4.1.0
aws-cli: circleci/aws-cli#2.0.3
eb: circleci/aws-elastic-beanstalk#2.0.1
jobs:
build:
docker:
- image: "cimg/base:stable"
steps:
- node/install
- checkout
- aws-cli/setup
- eb/setup
- run:
name: Check current version of node
command: node -v
- run:
name: Get and install node version manager.
command: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
- run:
name: Install Node version 12 using NVM
command: nvm install 12
- run:
name: Use Node version 12
command: nvm use 12
- run:
name: Back-End Install
command: |
npm run backend:install
- run:
name: Front-End Install
command: |
npm run frontend:install
- run:
name: Back-End Build
command: |
npm run backend:build
- run:
name: Front-End Build
command: |
npm run frontend:build
- run:
name: Back-End Deploy
command: |
npm run backend:deploy
- run:
name: Front-End Deploy
command: |
npm run frontend:deploy
During the setup, the CircleCI install node version of v16.9.0 and I need to use v12. So, I run additional command to use v12 using NVM.
Is there easier way to use specific version of the Node during the time of setup?
Using cimg with node version as a docker image should work. You don't have to manually install using nvm.
jobs:
build:
docker:
- image: cimg/node:12.16
https://hub.docker.com/r/cimg/node
I'm using cimg/node:16.13.2 and it works fine.
I think the issue was with the orbs as after I update to the node: circleci/node#4.7.0, I had no issue with NodeJS installation and build the project.
This makes sense as the cI/CD pipeline not suppose to run the software and hence, the NodeJS version should be irrelevent.

Gitlab CI/CD hangs when committing changes

Good Evening,
I am trying to implement Gitlab CI/CD using the Angular ng test command. The pipeline runs,
but hangs. I know Karma uses chrome. I am not sure what to add. Any help is appreciated thank you.
image: node:latest
before_script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- npm link #angular/cli
stages:
- test
- production
unit-test:
stage: test
image: trion/ng-cli-karma:${CLI_VERSION}
script:
- npm install
- ng test
only:
- master
production:
type: deploy
stage: production
image: ruby:latest
script:
- dpl --provider=heroku --app=$HEROKU_APP_PRODUCTION --api-key=$HEROKU_API_KEY
only:
- master
Do the tests run and then the pipeline hangs? If that is the case, I bet it is because ng test runs in watch mode and is always running looking for changes.
To fix it, change ng test to ng test --watch=false --browsers=ChromeHeadless.
I changed the browser to be headless Chrome as well (optional) and this should bring a slight increase in speed in your CI/CD
The flags can be found here.

How to run build and tests in production environment when devDependencies don't get installed?

I'm sure this is a common issue but I can't seem to find a definitive answer.
I have a node application which in order to build requires some devDependencies such as babel. In order to run my tests also requires devDependencies such as jest. But when CI runs in production environment, it obviously doesn't install any devDependencies so I get errors where the package isn't found.
What is the best practice for running builds and tests in prod without devDependencies?
If it helps, I am running my build in GitLab Pipelines:
image: node:8.11.2
stages:
- prepare
- test
- deploy
install_and_build:
stage: prepare
script:
- npm install yarn
- yarn
- yarn build
only:
- master
test:
stage: test
script:
- yarn test
only:
- master
deploy_production:
type: deploy
stage: deploy
image: ruby:latest
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=app-name --api-key=$HEROKU_API_KEY
only:
- master
From this answer,
You will want to follow have your process to the effect of the
following:
First, you need to "install with all dependencies".
npm install
Then do your tests.
npm test
Then "prune" your dev dependencies as below, as detailed in the
docs doing this
"will remove the packages specified in your devDependencies".
npm prune --production

Build and deploy node app to Openshift using Gitlab CI

Just mount a Gitlab in digitalocean to keep track of versions of some projects, but now I've read a little about Gitlab I wonder if you can set Gitlab CI so that each time you do a commit automatically make a build of application and if the build is successful can do a deploy to OpenShift.
I think my .gitlab-ci.yml should look something like this:
stages:
- build
- deploy
before_script:
- npm install
job_build:
stage: build
script:
- grunt build
job_deploy:
stage: deploy
But I really do not know if this is as valid and neither tell Gitlab CI must only make a git push to OpenShift repository.
After much reading and searching finally found documentation about this [1], in the end I have resolved some file using the following .gitlab-ci.yml
stages:
- build
- deploy
job_build:
stage: build
script:
- npm install -g grunt-cli
- npm rebuild node-sass
- npm install
- grunt build
job_deploy:
stage: deploy
script:
- apt-get update -yq
- apt-get install -y ruby-dev rubygems
- gem install dpl
- dpl --provider=openshift --user=$OPENSHIFT_USER --password=$OPENSHIFT_PASS --domain=mydomain --app=example
only:
- master
The magic happens with a Travis library call dpl [2] that supports a lot of providers [3]
[1]http://doc.gitlab.com/ce/ci/deployment/README.html
[2]https://github.com/travis-ci/dpl
[3]https://github.com/travis-ci/dpl#supported-providers

Resources