CircleCI config.yml for nodejs - node.js

version: 2
jobs:
test:
docker:
- image: circleci/node:12.16
steps:
- checkout
- run: echo "Running tests"
- run: npm install
- run: npm test
build:
docker:
- image: circleci/node:12.16
steps:
- checkout
- run: echo "build project"
- npm install
- npm run build
workflows:
version: 2
test_build:
jobs:
- test
- build:
requires:
- test
The above YAML is my config.yml for CircleCI, but I get this error
Config does not conform to schema: {:workflows {:test_and_build {:jobs [nil {:build (not (map? nil)), :requires (not (map? a-clojure.lang.LazySeq))}]}}}
Another observation is if I run the jobs in parallel, they run without any errors.
That is if I remove the requires: - test as shown below
workflows:
version: 2
test_build:
jobs:
- test
- build

build is a job, just like test, and should be indented the same way it is:
version: 2
jobs:
test:
docker:
- image: circleci/node:12.16
steps:
- checkout
- run: echo "Running tests"
- run: npm install
- run: npm test
build:
docker:
- image: circleci/node:12.16
steps:
- checkout
- run: echo "build project"
- npm install
- npm run build
workflows:
version: 2
test_build:
jobs:
- test
- build:
requires:
- test

I tried this one and it worked. The problem with the previous one seemed to be related to versioning. CircleCI cloud 2.1 and CircleCI server 2. Also, I decided to use the node orbs this time.
version: 2.1
orbs:
node: circleci/node#3.0.1
jobs:
build:
working_directory: ~/backend_api
executor: node/default
steps:
- checkout
- node/install-npm
- node/install-packages:
app-dir: ~/backend_api
cache-path: node_modules
override-ci-command: npm i
- persist_to_workspace:
root: .
paths:
- .
test:
docker:
- image: cimg/node:current
steps:
- attach_workspace:
at: .
- run:
name: Test
command: npm test
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build

Related

Github Actions not working giving error Invalid type for `on`

When I am pushing my project on github it pipeline should work but it's telling Invalid type for on
name: NASA Project CI
on:
push: branches:[master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Use Node.js version 16
- uses: actions/setup-node#v2
with: node-version:'16'
- run: npm install
- run: npm run build --prefix client
YAML, the format that GitHub uses for Actions, is sensitive to space and indentation. You'll probably want to write the push: entries on separate lines, indented, like so:
name: NASA Project CI
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Use Node.js version 16
- uses: actions/setup-node#v2
with: node-version:'16'
- run: npm install
- run: npm run build --prefix client

Pushing tags triggers CI/CD loop

Im using CircleCI for CI/CD and recently wanted to start tagging my releases to main bransch.
This is my config.yml
version: 2.1
orbs:
node: circleci/node#1.1.6
jobs:
build:
executor:
name: node/default
steps:
- checkout
- node/with-cache:
steps:
- run: git pull
- run: npm install standard-version
- run: npm run release
- run: git push --follow-tags origin master
- node/with-cache:
steps:
- run: echo 'deploying master branch'
Ofcourse this triggers and endless loop since it creates a new push which triggers CircleCI... I've read that you can skip builds in commit messages by adding [ci skip] but pushing tags does not give that option.
How do I get around this? I want the semantic releases to be tagged automatically when a new version is released... Can I somehow get around this?
Im using standard-version for tagging and updating package.json.
Any help would be greatly appriciated
The solution was the following changes to my config.yml:
version: 2.1
orbs:
node: circleci/node#1.1.6
jobs:
build:
executor:
name: node/default
steps:
- checkout
- node/with-cache:
steps:
- checkout
- run: npm install
- run: npm run test
- run: npx semantic-release
- node/with-cache:
steps:
- run: echo 'deploying master branch'
- run: ssh -v -o "StrictHostKeyChecking no" user#xxxx.xxx "cd ~/projects/xxx; git pull --rebase; ./publish.sh"
workflows:
version: 2
build_project:
jobs:
- build:
filters:
branches:
only: master
When doing this with "- run: npx semantic-release", the version bumping step will be auto incremented and the commit tagged with [skip ci] so it doesnt loop.

Two separate deploy configurations on travis

os:
- osx
language: node_js
node_js:
- '12'
dist: xenial
services:
- xvfb
before_script:
- export DISPLAY=:99.0
install:
- npm set progress=false
- npm install
script:
- ng lint
- npm run build:electron
deploy:
provider: releases
api_key: "$GITHUB_OAUTH_TOKEN"
file_glob: true
file:
- "release/*.dmg"
- "release/*.dmg.blockmap"
name: Build $(date +'%d.%m.%Y %R')
language: node_js
node_js:
- '12'
branches:
only:
- web-app
before_script:
- npm install -g #angular/cli
script:
- npm install
- npm run build
deploy:
skip_cleanup: true
provider: firebase
token:
secure: ""
I have two config files for travis.
How to merge them?
I tried different ways, but it makes errors like: 'duplicate deploy keyword'.
I want to deploy first part from branch master and second from web-app.
You can create and populate a Dockerfile.dev file with your first code block and populate the second code block into a Dockerfile. Then create a docker-compose.yml file (still in your root directory) it would connect and run both files
something structured like this
version: '3'
services:
web:
stdin_open: true
tty: true
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "1500:1500"
volumes:
- /app/node_modules
- .:/app

GitLab CI: configure yaml file on NodeJS

I have problem with test scss-lint in my project on nodejs.
When tests reach scss-lint, it gives an error.
How to make sure that tests do not fall with the successful result of the test itself?
My gitlab-ci.yml
image: node:wheezy
cache:
paths:
- node_modules/
stages:
- build
- test
gem_lint:
image: ruby:latest
stage: build
script:
- gem install scss_lint
artifacts:
paths:
- node_modules/
only:
- dev
except:
- master
install_dependencies:
stage: build
script:
- npm install
artifacts:
paths:
- node_modules/
only:
- dev
except:
- master
scss-lint:
stage: test
script:
- npm run lint:scss-lint
artifacts:
paths:
- node_modules/
only:
- dev
except:
- master
You are doing it wrong.
Each job you define (gem_lint, install_dependencies, and scss-lint) is run with its own context.
So your problem here is that during the last step, it doesn't find the scss-lint gem you installed because it switched its context.
You should execute all the scripts at the same time in the same context :
script:
- gem install scss_lint
- npm install
- npm run lint:scss-lint
Of course for this you need to have a docker image that has both npm and gem installed maybe you can find one on docker hub), or you can choose one (for example : ruby:latest) and add as the first script another one that would install npm :
- curl -sL https://deb.nodesource.com/setup_6.x | bash -

Gitlab Pipelines Stages take hours or days to show result (passed, failed) - docker, node app

I'm using Gitlab continuous integration (.gitlab-ci.yml) and docker, docker-compose to build, test and deploy my node app, but build and test takes so much time to complete on gitlab pipeline (in my local docker app builds and tests are running smoothly), I think this is not normal behavior of gitlab ci and i think i'm missing something or i'm using a wrong configuration
please check the configuration (.gitlab-ci.yml) below and screen shot of pipelines at the bottom
.gitlab-ci.yml
# GitLab CI Docker Image
image: node:6.10.0
# Build - Build necessary JS files
# Test - Run tests
# Deploy - Deploy application to ElasticBeanstalk
stages:
- build
- test
- deploy
# Configuration
variables:
POSTGRES_DB: f_ci
POSTGRES_USER: f_user
POSTGRES_PASSWORD: sucof
services:
- postgres:latest
cache:
paths:
- node_modules/
# Job: Build
# Installs npm packages
# Passes node_modules/ onto next steps using artifacts
build:linux:
stage: build
script:
- npm install
artifacts:
paths:
- node_modules/
tags:
- f-api
# Job: Test
# Run tests against our application
# If this fails, we do not deploy
test:linux:
stage: test
variables:
NODE_ENV: continuous_integration
script:
- ./node_modules/.bin/sequelize db:migrate --env=continuous_integration
- ./node_modules/.bin/sequelize db:seed:all --env=continuous_integration
- npm test
tags:
- f-api
# Job: Deploy
# Staging environment
deploy:staging:aws:
stage: deploy
script:
- apt-get update -qq
- apt-get -qq install python3 python3-dev
- curl -O https://bootstrap.pypa.io/get-pip.py
- python3 get-pip.py
- pip install awsebcli --upgrade
- mkdir ~/.aws/
- touch ~/.aws/credentials
- printf "[default]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/credentials
- touch ~/.aws/config
- printf "[profile adm-eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/config
- eb deploy f-api-stg
environment:
name: staging
url: http://f-api-stg.gxnvwbgfma.ap-southeast-1.elasticbeanstalk.com
tags:
- f-api
only:
- staging
# Job: Deploy
# Production environment
deploy:prod:aws:
stage: deploy
script:
- echo "Deploy to production server"
environment:
name: production
url: http://f-api.gxnvwbgfma.ap-southeast-1.elasticbeanstalk.com
when: manual
tags:
- f-api
only:
- master
Dockerfile
FROM node:6.10.0
MAINTAINER Theodore GARSON-CORBEAUX <tgcorbeaux#maltem.com>
# Create app directory
ENV HOME=/usr/src/app
RUN mkdir -p $HOME
WORKDIR $HOME
# Install api dependencies
ADD package.json /usr/src/app/package.json
RUN npm install
ADD . /usr/src/app
EXPOSE 3000
CMD ["npm","start"]
docker-compose.yml
version: "2.1"
services:
db_dev:
image: postgres:latest
ports:
- "49170:5432"
environment:
- POSTGRES_USER=f_user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=f_dev
healthcheck:
test: "exit 0"
db_test:
image: postgres:latest
ports:
- "49171:5432"
environment:
- POSTGRES_USER=f_user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=f_test
healthcheck:
test: "exit 0"
app:
build: .
environment:
- NODE_ENV=development
command: "npm start"
ports:
- "49160:3000"
depends_on:
db_dev:
condition: service_healthy
migrate:
build: .
environment:
- NODE_ENV
command: "./node_modules/.bin/sequelize db:migrate --env ${NODE_ENV}"
depends_on:
db_dev:
condition: service_healthy
db_test:
condition: service_healthy
healthcheck:
test: "exit 0"
populate_db:
build: .
environment:
- NODE_ENV
command: "./node_modules/.bin/sequelize db:seed:all --env ${NODE_ENV}"
depends_on:
migrate:
condition: service_healthy
healthcheck:
test: "exit 0"
depopulate_db:
build: .
environment:
- NODE_ENV
command: "./node_modules/.bin/sequelize db:seed:undo:all --env ${NODE_ENV}"
depends_on:
migrate:
condition: service_healthy
healthcheck:
test: "exit 0"
test:
build: .
environment:
- NODE_ENV=test
command: "npm test"
depends_on:
populate_db:
condition: service_healthy

Resources