Wade Stern Projects

CI Pipeline and Docker

Input: Whenever a commit is made to one of the projects on GitHub the pipeline automatically starts. Output: The result of running the CI pipeline is a new docker image gets pushed to the dockerhub. These images are used later in the pipeline to create Kubernetes pods.

CI Image

The CI part of the pipeline differs between the frontend and backend versions. The backend uses Python, so the testing framework and linting tools are different from the javascript version of the frontend. They also use different docker images to run tests.

Steps

test-python

The first step in the CI pipeline is to test the new code to ensure that it is functional. Whenever a new version of frontend or backend is pushed to git, it runs unit tests for the type that was updated. These test results are put into an XML file so that the pipeline can interpret the response. If any tests during the pipeline result in failures, the pipeline fails and stops running. The next step is running linting software on the code. The frontend uses eslint and the backend uses flake8.

Code for test-python
test-python:
    docker:
      - image: cimg/python:3.10
    steps:
      - checkout
      - python/install-packages
      - python/install-packages:
          args: pytest
          pkg-manager: pip
          pypi-cache: false
      - run:
          name: Run tests
          command: pytest test_main.py --junitxml=junit.xml
      - store_test_results:
          path: junit.xml
      - run:
          name: Lint Python code
          command: |
            pip install flake8
            flake8 .
          when: always

Build-docker-image

After testing is complete, the application is packaged into a docker image. The docker image is then uploaded to Dockerhub so that it can be accessed by other parts of the pipeline.

Code for build_docker_image
build_docker_image:
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: false
      - run:
          name: Build Docker image
          command: |
            export TAG=0.2.<< pipeline.number >>
            export IMAGE_NAME=tastybackend           
            docker build -t $DOCKER_LOGIN/$IMAGE_NAME -t 
            $DOCKER_LOGIN/$IMAGE_NAME:$TAG .
            echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN
             --password-stdin
            docker push $DOCKER_LOGIN/$IMAGE_NAME