💻
Building and hosting a WebApp
  • Getting started
  • Project setup
    • Requirements
    • Files organisation
    • Lerna
    • Linter
    • Prettier
    • GitHook
    • Testing
    • Conclusion
  • Backend
    • Files organisation
    • Environment config
    • Express API
    • Security
    • Database
    • GraphQL
    • User authentication
    • Conclusion
  • Frontend
    • Create React App
    • Files organisation
    • Styles
    • Apollo Hooks
    • Form management
    • User authentication
    • Writing tests
    • Types generation
    • Conclusion
  • DevOps
    • CI/CD
    • AWS
      • Managing secrets
      • Pricing
      • RDS
      • S3
      • Route53
      • CloudFront
      • Serverless
      • Security
      • CloudFormation
    • Conclusion
  • 🚧Stripe payment
  • 🚧File upload
Powered by GitBook
On this page
  • CircleCI
  • Environment variables

Was this helpful?

  1. DevOps

CI/CD

PreviousDevOpsNextAWS

Last updated 5 years ago

Was this helpful?

The first thing we're going to do is automating the tests. The CI will run the backend and frontend tests for each commit pushed.

Later, we will also automate the deployment of the app when we push to the master branch.

The end goal is to automate the pipeline from commit to deploy.

CircleCI

  1. Create a folder named .circleci and add a fileconfig.yml.

  2. Populate the config.yml with the contents of the sample .yml bellow.

  3. Change "test": "echo \"Error: no test specified\" && exit 1" to "test": "jest" in packages/api.

  4. Commit and push up to GitHub

  5. Go to CircleCI and watch your build.

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:10

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}-{{ checksum "packages/api/package.json" }}-{{ checksum "packages/web/package.json" }}
            - v1-dependencies-

      - run: yarn install

      - save_cache:
          paths:
            - node_modules
            - packages/web/node_modules
            - packages/api/node_modules
          key: v1-dependencies-{{ checksum "package.json" }}-{{ checksum "packages/api/package.json" }}-{{ checksum "packages/web/package.json" }}

      # run tests!
      - run: yarn --cwd packages/web test
      - run: yarn --cwd packages/api test

When tests are broken, CircleCI will let you know:

We can also see the build status on the commits:

You can configure GitHub to require the CI to pass before you merge into a branch in Setting> Branches > Rule settings > Require status checks to pass before merging.

  • Branch name pattern: master

  • Check CircleCI steps

Environment variables

Locally, we are reading the .env file. But this file is not committed to the repo. We have to setup the environment variables on CircleCI.

Go to the project's settings by clicking on the cog next to the project name:

Scroll down to BUILD SETTINGS and click Environment Variables then Add Variable. Add the variables from the .env file:

The tests should now be passing:

is a popular platform offering CI in the cloud. You get one container for free. Let's get started:

CircleCI
The ❌ on the right end side indicates the build is not passing.