Skip to content

Make Docker setup less memory-intensive & build deps at container start #1033

Make Docker setup less memory-intensive & build deps at container start

Make Docker setup less memory-intensive & build deps at container start #1033

Workflow file for this run

name: Testing
on:
push:
branches:
- main
- dev
- experimental
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
jobs:
# For the setup idea using Docker Buildx, see StackOverflow answer [1].
# [2] might also be very useful. [3] and [4] are generally about Docker
# cache management (within GitHub Actions). Note that the GitHub Actions cache
# is different from the GitHub Container Registry (ghcr).
#
# [1] https://stackoverflow.com/a/75544124/
# [2] https://www.deploysentinel.com/blog/docker-buildx-cache-with-github-actions
# [3] https://docs.docker.com/build/ci/github-actions/cache/
# [4] https://docs.docker.com/build/cache/backends/
build-mampf:
name: Build MaMpf
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push docker image to GHCR
working-directory: docker/test
run: >
docker buildx bake
--allow=fs.read=/home/runner/work/mampf/mampf
-f ./docker-compose.yml -f ./docker-compose.cicd.yml
-f ./../../.github/workflows/docker-compose-cache.json
unit-tests:
name: Unit tests
environment: testing
runs-on: ubuntu-latest
permissions: write-all
needs: build-mampf
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
# see https://github.com/orgs/MaMpf-HD/packages?repo_name=mampf
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull MaMpf image (from GHCR)
working-directory: docker/test
run: >
docker image pull ghcr.io/mampf-hd/mampf-test:cache
- name: Run unit tests
working-directory: docker/test
run: >
docker compose -f docker-compose.yml -f docker-compose.cicd.yml
run --entrypoint="" mampf sh -c
"RAILS_ENV=test NODE_ENV=test-ci bundle exec rspec --format RSpec::Github::Formatter"
- name: Report test coverage to codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: ./coverage/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
# Cypress end-to-end (e2e) tests
e2e-tests:
name: e2e (Cypress)
environment: testing
runs-on: ubuntu-latest
permissions: write-all
needs: build-mampf
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
# see https://github.com/orgs/MaMpf-HD/packages?repo_name=mampf
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull MaMpf image (from GHCR)
working-directory: docker/test
run: >
docker image pull ghcr.io/mampf-hd/mampf-test:cache
- name: Run Cypress tests
working-directory: docker/test
run: >
docker compose
-f ./docker-compose.yml -f docker-compose.cicd.yml
-f ./cypress.yml
run cypress -e NODE_ENV=test-ci