CI / CD
Inna Ivashchuk
Senior Software Engineer
JS developer, music fan, movie-dependent and Star Wars fan 🤓
May the Force be with you!
Dmytro Bielik
Senior Software Engineer
3+ years experience in DevOps
7+ years experience in IT engineering
build
checks
developer
artifact
CI
VCS
(Docker image)
Code checks using TypeScript ESLint:
Write and run tests is always a good idea
Time to build our application
Danger runs during your CI process and gives teams the chance to automate common code review chores.
This provides another logical step in your build, through this Danger can help lint your rote tasks in daily code review.
Reviewdog provides a way to post review comments to code hosting service, such as GitHub, automatically by integrating with any linter tools with ease. It uses an output of lint tools and posts them as a comment if findings are in diff of patches to review.
artifact
CD
dev
production
(docker image)
write automated tests
CI server/service to monitor the main repository and run the tests automatically for every new commits pushed
merge changes as often as possible, at least once a day
less bugs get shipped to production
building the release is easy
less context switching as developers are alerted as soon as they break the build
testing costs are reduced – CI server can run hundreds of tests in a matter of seconds
QA team spend less time testing and can focus on significant improvements to the quality culture
a strong foundation in CI and test suite needs to cover enough of a codebase
deployments need to be automated
use feature flags so that incomplete features do not affect customers in production (Launch Darkly service)
the complexity of deploying software has been taken away. Team doesn't have to spend days preparing for a release anymore
release more often
less pressure on decisions for small changes, hence encouraging iterating faster
Build into GitHub
​fully integrated and doesn't require an external server/service
Multi-container testing
multiple templates for all kinds of CI
ability to create your own templates and publish it as an Action on the Github Marketplace
Great free plan
completely free for every open-source repository
2000 free build minutes per month for all your private repositories
Actions - the smallest portable building block of a workflow and can be combined as steps to create a job
Events - specific activities that trigger a workflow run
Runner - a machine with the Github Actions runner application installed
Job - made up of multiple steps and runs in an instance of the virtual environment
Steps - a set of tasks that can be executed by a job. Steps can run commands or actions
Workflow - an automated process that is made up of one or multiple jobs and can be triggered by an event (defined using a YAML file)
# Triggers the workflow on push or pull request events
on: [push, pull_request]1. On the main page of a repository navigate to Actions.
2. Pick a template you would like to use and click Set up this workflow
3. We can make changes in the editor and commit the action to your repository using the Start commit button
Action templates can be found on the Github Marketplace or directly in the workflow editor on the far right side.
The template can be added by copying the code of the actions and pasting it into your .yml file. The unique action name and version number need to be defined with the uses keyword.
name: Test, build and Deploy
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# Install deps with Yarn
- name: Install dependencies
run: yarn
working-directory: ./user-service
# Run linter checks
- name: Run TS lint
run: yarn lint
working-directory: ./user-service
# Run tests
- name: Run tests
run: yarn test
working-directory: ./user-service
deploy:
if: github.event_name == 'push'
runs-on: ubuntu-latest
# only run if build job complte successfully
needs: [tests]
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Docker login
env:
DOCKER_USER: ${{secrets.DOCKER_HUB_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_HUB_PASSWORD}}
run: |
docker login -u ${{secrets.DOCKER_HUB_USERNAME}} -p ${{secrets.DOCKER_HUB_PASSWORD}}
- name: Build the Docker image
run: docker build ./user-service --file ./user-service/Dockerfile --tag innaifox/jsprocamp-user-service:latest
- name: Docker Push
run: docker push innaifox/jsprocamp-user-service
There are many possible ways, how workflow can be configured. It helps us to make the build faster and more flexible.
Examples: