Skip to content

Instantly share code, notes, and snippets.

@MirzaLeka
Created March 26, 2023 12:15
Show Gist options
  • Save MirzaLeka/58f80ed1e194c82d7af4acd723065c90 to your computer and use it in GitHub Desktop.
Save MirzaLeka/58f80ed1e194c82d7af4acd723065c90 to your computer and use it in GitHub Desktop.
Circle CI JavaScript / Node.js Setup (CI/CD)

Circle CI JavaScript Setup (CI/CD)

Circle CI is Continuous integration Continuous delivery platform. Alternative to Github Actions. The service is free to use, but there are paid packages as well.

Setting up Circle CI

  • Go to Circle CI and create an account (sign up with Github)
  • Connect your repository
  • Choose the branch for Circle CI to observe. Everytime you push to this branch (e.g.) Circle CI will trigger.
  • Create .circleci directory in root directory of your project
  • Create inside config.yml and write your config

JS / Node.js CI Config Example

version: 2 # first couple of steps are copied from the docs
jobs:
  build:
    docker:
      - image: circleci/node:12 # docker image for Node.js from the Docs

    working_directory: ~/repo

    steps: # any steps you want
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI

CI/CD Example with AWS Elastic Beanstalk

version: 2.1

orbs:
  aws-elasticbeanstalk: circleci/aws-elasticbeanstalk@0.2.1

jobs:
  build:
    docker:
      - image: circleci/node:16
    working_directory: ~/app
    steps:
      - checkout
      - run: npm install
      - run: npm run build

  deploy:
    docker:
      - image: circleci/python:3.8
    steps:
      - checkout
      - run: pip install awsebcli
      - aws-elasticbeanstalk/deploy:
          application: my-application
          environment: production
          version: $CIRCLE_SHA1
          region: us-east-1 # region nearest to you
          aws-access-key-id: $AWS_ACCESS_KEY_ID
          aws-secret-access-key: $AWS_SECRET_ACCESS_KEY

workflows:
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          context: my-aws-credentials

In this example, there are two jobs defined: build and deploy.

The build job uses the circleci/node Docker image to run the npm install and npm run build commands to build the application.

The deploy job uses the circleci/python Docker image to install the AWS Elastic Beanstalk CLI and deploy the application. It specifies the application name, environment name, and version label using environment variables.

The workflows section defines a build-and-deploy workflow that runs the build job first, then runs the deploy job if the build job succeeds. The context key is used to specify the AWS credentials context created in CircleCI project settings.

Replace my-application with the name of your Elastic Beanstalk application, and update the region and environment name to match your deployment settings.

Also, make sure to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables in your CircleCI project settings.

Handful Tutorials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment