Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Try to speed up the CI for testing by building and caching in ghcr #972

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
88f3548
Do not build in `docker-compose.yml`
suricactus Jun 22, 2024
f983aa9
Build and push image to ghcr.io in tests
suricactus Jun 22, 2024
5ad5221
Fix worker wrapper build
suricactus Jun 22, 2024
f6e8ef1
Build without a PR
suricactus Jun 22, 2024
7107598
Add permissions to create records to ghcr.io
suricactus Jun 22, 2024
59844f6
Optimize building worker_wrapper as part of the app matrix
suricactus Jun 22, 2024
6604b3c
Set specific docker image names for the containers in testing
suricactus Jun 22, 2024
40e8b51
Disable tests and see the config
suricactus Jun 23, 2024
d3ca458
Fix envvars
suricactus Jun 23, 2024
c588201
List files
suricactus Jun 23, 2024
1d115f9
Fix docker compose override test
suricactus Jun 23, 2024
a6e8265
Re-enable the tests
suricactus Jun 23, 2024
1e8b2c7
Enable all tests
suricactus Jun 23, 2024
5402fcb
Remove on push
suricactus Jun 23, 2024
da8fc06
Bump all deps
suricactus Jun 23, 2024
6a571b5
Restore missing .env
suricactus Jun 23, 2024
3f11df2
Reenable tmate
suricactus Jun 23, 2024
1d22c78
Move all 3rd party services to their own docker-compose file
suricactus Jun 23, 2024
279850f
Hopefully fixed?
suricactus Jun 23, 2024
736f6f1
Add the testing image
suricactus Jun 23, 2024
8661f55
Better step name
suricactus Jun 23, 2024
1ad9585
Make geodb use the same base image as db
suricactus Jun 24, 2024
68240f2
Update test.yml
suricactus Jul 23, 2024
4c7e435
DOCKER_BUILDKIT added
Sep 26, 2024
eec7c5b
matrix added to flaky loop to exclude all tests
Sep 26, 2024
b00a884
running with authentication test only
Sep 27, 2024
c772948
run baseline build
Sep 27, 2024
b4417fe
test procedure aligned from master
Sep 27, 2024
d03b37a
test procedure aligend from master for ghcr.io caching test
Sep 27, 2024
9735b71
test_baseline name changed
Sep 27, 2024
f71d8ae
build activated for base line test
Sep 27, 2024
d916896
run only baseline test
Sep 27, 2024
660fbeb
fix baseline test
Sep 27, 2024
84e547e
remove second build step in test procedure
Sep 27, 2024
f6016ea
fix issues baseline testing
Sep 27, 2024
e59b6ac
fix issues baseline auth test
Sep 27, 2024
7f2ebef
switch to ghcr.io caching
Sep 27, 2024
bb64959
DOCKER_BUILDKT deactivated (local caching)
Sep 27, 2024
0da4226
script to manage actions-cache created
Sep 29, 2024
98e36a0
Test ghcr.io caching 1
Sep 29, 2024
738e379
reforce test build
Sep 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 99 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test ghcr.io caching 1

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -11,40 +11,122 @@ on:
- release
pull_request:

permissions:
contents: read
packages: write

jobs:
lint:
if: '! github.event.pull_request.draft'
name: Lint code base
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Pre-commit
uses: pre-commit/action@v3.0.0


build:
name: Build image
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
service_name:
- app
- nginx
- qgis
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push `qfieldcloud-${{ matrix.service_name }}`
uses: docker/build-push-action@v6
with:
context: ./docker-${{ matrix.service_name }}
file: ./docker-${{ matrix.service_name }}/Dockerfile
push: true
tags: ghcr.io/opengisch/qfieldcloud-${{ matrix.service_name }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push `qfieldcloud-worker_wrapper` (if needed)
if: ${{ matrix.service_name == 'app' }}
uses: docker/build-push-action@v6
with:
context: ./docker-app
file: ./docker-app/Dockerfile
target: 'worker_wrapper_runtime'
push: true
tags: ghcr.io/opengisch/qfieldcloud-worker_wrapper:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push `qfieldcloud-app-testing` (if needed)
if: ${{ matrix.service_name == 'app' }}
uses: docker/build-push-action@v6
with:
context: ./docker-app
file: ./docker-app/Dockerfile
target: 'webserver_test'
push: true
tags: ghcr.io/opengisch/qfieldcloud-app-testing:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
github-token: ${{ secrets.GITHUB_TOKEN }}

test:
name: Run tests
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs:
- build
strategy:
fail-fast: false
matrix:
django_app:
- authentication
- notifs
- subscription
- core
- __flaky__
# - notifs
# - subscription
# - core
# - __flaky__
continue-on-error: true
env:
QFIELDCLOUD_IMAGE_NAME_FOR_APP: "ghcr.io/opengisch/qfieldcloud-app-testing:${{ github.sha }}"
QFIELDCLOUD_IMAGE_NAME_FOR_WORKER_WRAPPER: "ghcr.io/opengisch/qfieldcloud-worker_wrapper:${{ github.sha }}"
QFIELDCLOUD_IMAGE_NAME_FOR_QGIS: "ghcr.io/opengisch/qfieldcloud-qgis:${{ github.sha }}"
QFIELDCLOUD_IMAGE_NAME_FOR_NGINX: "ghcr.io/opengisch/qfieldcloud-nginx:${{ github.sha }}"
COMPOSE_FILE: docker-compose.yml:docker-compose.override.services.yml:docker-compose.override.test.yml
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -56,18 +138,18 @@ jobs:
run: |
scripts/check_envvars.sh

- name: Export the env variables file
- name: Prepare the `.env` file
run: |
cp .env.example .env
sed -ri 's/^COMPOSE_FILE=(.*)/COMPOSE_FILE=\1:docker-compose.override.test.yml/g' .env
eval $(egrep "^[^#;]" .env | xargs -d'\n' -n1 | sed -E 's/(\w+)=(.*)/export \1='"'"'\2'"'"'/g')

- name: Pull docker containers
run: docker compose pull
# - name: Pull docker containers
# run: docker compose pull

- name: Build and run docker containers
run: |
docker compose up -d --build
docker compose up -d

- name: Initial manage.py commands
run: |
Expand All @@ -85,7 +167,7 @@ jobs:
run: |
docker compose run app python manage.py test --keepdb -v2 --tag="flaky" qfieldcloud

- name: "failure logs"
- name: Print failure logs
if: failure()
run: |
docker compose logs
Expand All @@ -99,7 +181,7 @@ jobs:
gchat_webhook_url: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}

# - name: Setup tmate session
# if: ${{ failure() }}
## if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 30
# with:
Expand Down
Loading
Loading