Sources for practice lecture about containers used in NSWI026 MFF UK and SEPA4M33SEP, FEL CVUT. This should be a simple example for CI/CD, it's not recommended for a production usage.
-
Take a look on basic usage of GitHub workflows.
-
Take a look on script in
task_a. Try it locally:- (Optional) Prepare an env
python3 -m venv venv, activate itsource venv/bin/activateand install dependenciespip3 install -r requirements.txt. - (Optional) Try to execute tests
pytest task_a.py.
- (Optional) Prepare an env
- Make one test failing and fill a GitHub workflow to execute tests.
- Change
.github/workflows/task-a-cd.ymland push it to your GitHub.
- Change
- Try to speed up testing using cache on one of following methods.
- Using
cache: 'pip'inactions/setup-python - Using
actions/cache
- Using
- Generate an html report for PyTest with
--html=report.htmland upload it to GitHub usingactions/upload-artifact - Run tests on multiple operating systems and Python versions using matrix option.
runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.10", "3.11", "pypy3.10"] exclude: - os: macos-latest python-version: "3.10" - os: windows-latest python-version: "3.10"
- Don't forget to use matrix value
${{ matrix.os }}injobs.test.runs-onand${{ matrix.python-version }}injobs.test.steps[2].with.python-version - Rename artifact to
Report-${{ matrix.os }}-${{ matrix.python-version }}get rid of name conflicts - Take a look on reports, check Platform section if everything works as expected
- Don't forget to use matrix value
- Change "task-a-cd.yml" to
task-a-ci.ymland change to be executed on a pull-request, take a look onpull_request. - Run this pull request only on changes tu folder
task_a, take a look onpaths.
- Try a manual workflow "task-b manual".
- Build a docker image, using
docker/build-push-action, you could reuse following lines- Create an workflow input
tagfor image tag - Tag image like
ghcr.io/${{ github.repository }}:${{ inputs.tag }}
- Create an workflow input
- Build a dependent job
test- It should depend on
dockerjob - It should run docker container from previous step as service container
- Call
curl 127.0.0.1:8080/index.htmlto fetchindex.html
- It should depend on
- Get own repository for FlightLog
- CI - Test application on pull-request
- CD - Build a docker image on push to master / develop