Skip to content

Commit

Permalink
Lab 3 bonus: CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kolayne committed Feb 16, 2024
1 parent 5a6e285 commit a4b0886
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/go-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Go application

on:
push:
paths:
- .github/workflows/**
- app_go/**

permissions:
contents: read

jobs:
lint-test-snyk:

runs-on: ubuntu-latest

strategy:
matrix:
go-version: ["1.21", "1.22"]

defaults:
run:
working-directory: ./app_go

steps:
- uses: actions/checkout@v4
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: app_go/go.sum
- name: Build
run: go build
- name: Lint with `go vet`
run: go vet
- name: Test with `go test`
run: |
go test
- name: Check for vulnerabilities with Snyk
uses: snyk/actions/golang@master
with:
args: app_go/
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}


docker-build-push:
needs: [ lint-test-snyk ]

runs-on: ubuntu-latest

steps:
- name: Cache Docker images
uses: ScribeMD/[email protected]
with:
key: docker-app_go
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: kolay0ne
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push docker image
uses: docker/build-push-action@v5
with:
push: true
context: "{{defaultContext}}:app_go/"
tags: kolay0ne/app_go:${{ github.ref_name }}
14 changes: 14 additions & 0 deletions app_go/CI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CI for `app_python`

## Best practices

- Runs on push only if files in related directories have changed.

- Uses matrix strategy: runs tests with different python versions,
can be extended further, e.g., to use different operating systems.

- In the lint&test job, dependencies are cached and reused. Cache is
updated when newer versions of dependent libraries are released.

- In the docker build&push job, docker layers are cached and reused.
Cache is updated when any of the layers change.
7 changes: 7 additions & 0 deletions app_go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ Replace `kolay0ne/app_go` with your image/tag name if you built it manually.
## Unit Tests

To run unit tests, navigate to the project directory and run `go test`.

## CI

On every push to the repository that changes files under `app_go/`,
the code is linted and tested, and checked for vulnerabilities. On success,
an image is built and published in DockerHub under the name `kolay0ne/app_go`
with a tag matching the branch name.

0 comments on commit a4b0886

Please sign in to comment.