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.
Related
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
I'm facing the problem that I cant build my Angular app through the AWS Amplify Console:
"You are running version v8.12.0 of Node.js, which is not supported by Angular CLI 8.0+.
The official Node.js version that is supported is 10.9 or greater.
Please visit https://nodejs.org/en/ to find instructions on how to update Node.js."
Now I want to set the default node version of the docker container in the provision step to VERSION_NODE_10 which is already defined in the container.
# Framework Versions
ENV VERSION_NODE_8=8.12.0
ENV VERSION_NODE_6=6
ENV VERSION_NODE_10=10
ENV VERSION_NODE_DEFAULT=$VERSION_NODE_8 <-- Change this to $VERSION_NODE_10
ENV VERSION_RUBY_2_3=2.3.6
ENV VERSION_RUBY_2_4=2.4.3
ENV VERSION_RUBY_DEFAULT=$VERSION_RUBY_2_3
ENV VERSION_HUGO=0.51
ENV VERSION_YARN=1.13.0
amplify.yml:
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- node -v
- npm run-script build
artifacts:
baseDirectory: dist/cr-client
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Does anyone know how to change the default?
The correct answer actually isn't the right one.
You should use a custom build image of NodeJS to run your application properly without changing the node version by nvm.
To do that:
Open the "Amplify Console"
Open "All Apps"
Choose the app you're going to change the NodeJS version
Open "Build Settings"
Scroll down to "Build image settings" box and hit "edit" button
At "Build Image" dropdown, choose the option "Build image"
A new input field will appear just below this dropdown, now write the Docker Image Name (same used in Dockefile) you are looking for. For example node:12.16.1
Save
Redeploy any build.
AWS Amplify use nvm to handle node version. Try this:
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- nvm use $VERSION_NODE_10
- npm ci
build:
commands:
- nvm use $VERSION_NODE_10
- node -v
- npm run-script build
artifacts:
baseDirectory: dist/cr-client
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Custom build image of NodeJS is a lot of pain.
I usually do this:
App settings > Build Settings > Build Image Settings click Edit.
Live package updates : Node.js version > version.
The accepted answer did not work for me.
The only way to change the node version in the provision step is to have your own build setting.
However, there is an easier way to accomplish this.
In my case, I wanted the latest node 10 version. And adding nvm install in the prebuild step worked.
frontend:
phases:
preBuild:
commands:
- nvm install 10
You can install and use any node version in the amplify by installing it in prebuild steps. Use nvm to switch the node version.
preBuild:
commands:
- nvm install <node version>
Amplify Console output:
# Executing command: nvm install 10
2020-09-09T13:36:19.465Z [INFO]: Downloading and installing node v10.22.0...
2020-09-09T13:36:19.544Z [WARNING]: Downloading https://nodejs.org/dist/v10.22.0/node-v10.22.0-linux-x64.tar.gz...
2020-09-09T13:36:19.664Z [WARNING]: ########
2020-09-09T13:36:19.665Z [WARNING]: 11.9%
2020-09-09T13:36:19.765Z [WARNING]: #######
2020-09-09T13:36:19.765Z [WARNING]: ######################## 43.5%
2020-09-09T13:36:19.832Z [WARNING]: ################################
2020-09-09T13:36:19.832Z [WARNING]: ######################################## 100.0%
2020-09-09T13:36:19.844Z [WARNING]: Computing checksum with sha256sum
2020-09-09T13:36:19.934Z [WARNING]: Checksums matched!
2020-09-09T13:36:20.842Z [INFO]: Now using node v10.22.0 (npm v6.14.6)
Following on #richard's solution, you can put a .nvmrc ($ node --version > .nvmrc) file in the root of your repo with the specific Node version you used to build your project, and use nvm install instead of nvm use $VERSION_NODE_10
Update as of 4th Dec 2022:
What worked out for me was to use a custom build of the NodeJS Docker image on Docker Hub.
Here's what you would need to do:
Go to AWS Amplify
Go to "Build settings"
Scroll down to "Build image settings"
Click on "Edit" button
Under "Build image" click on the dropdown button
Select "Build Image" (by default Linux:2 is selected, at least for me)
In the text field type, for example, "node:18.12.1"
Go back to the latest deploy and click on the "Redeploy this version" app
Roll a J and smoke it, everything should be green now
In that way, you may use whatever build of NodeJS you would need. At least, NodeJS 18 worked for me, I didn't need another.
During build time you can see in the Provision tab they actually use the custom build from Docker Hub:
I tried two of the answers above and they did not work for me.
I didn't think of that. That approach was shared by "dncrews" user on Github.
Check this out.
February 2023
To do so, open amplify/backend/function/function-name/function-name-cloudformation-template.json and set the Runtime property in the LambdaFunction resource to nodejs18.x
https://docs.amplify.aws/cli/function/configure-options/#updating-the-runtime
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
I need to install npm using ansible. I am Referring to Ansible 2.3 : http://docs.ansible.com/ansible/npm_module.html
I have packed npm module using npm pack coffee-script and have coffee-script.tgz. now I want to install it using npm by using that file.
The closest thing I can find is :
- name: Install "coffee-script" node.js package from custom registry.
npm:
name: coffee-script
registry: 'http://registry.mysite.com'
But how to install from local file because my server doesn't have internet connection, hence I need to pack and install from the binary file.
I want to do something like this
- name: Install "coffee-script" node.js package from custom registry.
npm:
name: coffee-script
global : yes
source: '/usr/local/coffee-script.tgz'
Please use this:
- name: Install "coffee-script" node.js package from custom registry.
npm:
name: /usr/local/coffee-script.tgz
path: /app/location
global: yes
I ended up using npmbox which solve my problem perfectly.
from my machine I run command npmbox coffee-script which give me coffee-script.npmbox
then I paste to my offline server and run npmunbox -g coffee-script.npmbox
But you need to install npmunbox on your offline server too.
run : npmbox npmbox on your online machine
paste npmbox.npmbox it to offline server
run : tar --no-same-owner --no-same-permissions -xvzf npmbox.npmbox (or using unarhieve command in ansible)
run : npm install --global --cache ./.npmbox.cache --optional --cache-min 99999999999 --shrinkwrap false npmbox
now you can install any npm package offline using npmunbox <package_name>.npmbox (for example : npmunbox pm2.npmbox or npmunbox coffee-script.npmbox
You can user module npm for offline installation.
- name: Install node.js package from custom registry.
npm:
name: "/tmp/pm2-3.5.1.tgz"
global: yes
For multiple installation you can use loop.
Sample tasks:
- name: Find all tgz files in temporary directory
find:
paths: "{{ tmp_node.path }}"
patterns: "*.tgz"
register: node_files
- set_fact:
node_list: "{{ node_files.files | map(attribute='path') | list }}"
- name: Install node.js package from custom registry.
npm:
name: "{{ item }}"
global: yes
loop: "{{ node_list | flatten(1) }}"
Where node_list it's list of .tgz npm packages placed in role in directory files.
I am trying to configure my gitlab-ci to use yarn install instead of npm install
My current gitlab-ci.yml looks like:
image: node:6.9.4
cache:
paths:
- node_modules/
- .yarn
before_script:
- apt-get update -qq && apt-get install -qy libelf1
stages:
- test
test_core:
stage: test
script:
- yarn config set cache-folder .yarn
- yarn install
- npm run build
- npm run test
tags:
- 2gb
But the build fails with the error:
/bin/bash: line 48: yarn: command not found
is there something I am missing?
I tried installing yarn with:
curl -o- -L https://yarnpkg.com/install.sh | bash
this gave me same error, probably because I need to reload the bash environment for the yarn command to become available.
The above config works perfect with npm install.
Please help me resolve this. If there is something missing in my config file or there is something wrong with the gitlab-ci.
Thanks.
Solved it by using the latest official node docker image.
Since image: 6.10.0, yarn is installed by default in the image.
But if you need node-gyp to build any package, it needs to be installed by adding a line to the script:
yarn global add node-gyp
Add the following to your ci script after yarn got installed:
export PATH=$HOME/.yarn/bin:$PATH
I use image:node:latest and sometimes it prompts the error. Clear Runner Caches do the job for me. Maybe the runner did not recover to the correct state after doing other jobs.
I solved it by using npx (package runner). It's better then extending docker-image only for this purpose
npx yarn someCommand