Skip to content

Commit

Permalink
Try out caching in docke build actions (#958)
Browse files Browse the repository at this point in the history
* Try out caching in docke build actions

See https://docs.docker.com/build/cache/backends/gha/

* Gradle build action suggest migrating to setup-gradle, which it is now pointing to anyways

* Wait for backend/website image as late as possible

* Cache preprocessor docker build as well

* Cache website docker image build

* Run e2e when workflow changed as well

* Use separate scopes for each docker build cache
  • Loading branch information
corneliusroemer committed Feb 9, 2024
1 parent e6dc7f9 commit d7b85ee
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
SECOND_TAG=$(echo "${{ steps.dockerMetadata.outputs.tags }}" | head -n 2 | tail -n 1)
echo "secondTag=$SECOND_TAG" >> $GITHUB_OUTPUT
- name: Build Docker Image For Branch
uses: gradle/gradle-build-action@v3
uses: gradle/actions/setup-gradle@v3
env:
USER: ${{ github.actor }}
TOKEN: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/config-preprocessor-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ jobs:
context: ./kubernetes/config-processor
push: true
tags: ${{ steps.dockerMetadata.outputs.tags }}
cache-from: type=gha,scope=config-preprocessor=${{ github.ref }}
cache-to: type=gha,mode=max,scope=config-preprocessor=${{ github.ref }}
4 changes: 3 additions & 1 deletion .github/workflows/dummyPreprocessing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ jobs:
with:
context: ./preprocessing/dummy
push: true
tags: ${{ steps.dockerMetadata.outputs.tags }}
tags: ${{ steps.dockerMetadata.outputs.tags }}
cache-from: type=gha,scope=dummy${{ github.ref }}
cache-to: type=gha,mode=max,scope=dummy-${{ github.ref }}
222 changes: 111 additions & 111 deletions .github/workflows/e2e-k3d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ on:
workflow_dispatch:
push:
paths:
- 'website/**'
- 'backend/**'
- 'kubernetes/**'
- 'preprocessing/**'
- 'deploy.py'
- "website/**"
- "backend/**"
- "kubernetes/**"
- "preprocessing/**"
- "deploy.py"
- ".github/workflows/e2e-test.yml"

concurrency:
group: ci-${{ github.ref }}-e2e-k3d
cancel-in-progress: true

jobs:
k3d-e2e:

permissions:
packages: read
contents: read
Expand All @@ -25,108 +25,108 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install k3d
run: |
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
- name: Create k3d cluster
run: |
./deploy.py cluster
- name: Test helm template
uses: WyriHaximus/github-action-helm3@v3
with:
exec: helm template does-not-matter ./kubernetes/loculus > defaultTemplate.yaml

- name: Upload default helm template
uses: actions/upload-artifact@v4
with:
name: default-helm-template
path: defaultTemplate.yaml

- name: Wait for Backend Docker Image
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.ref }}
check-name: Build Backend Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Wait for Website Docker Image
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.ref }}
check-name: Build Website Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy with helm
uses: WyriHaximus/github-action-helm3@v3
with:
exec: ./deploy.py helm --branch ${{ github.ref_name }} --dockerconfigjson ${{ secrets.GHCR_DOCKER_CONFIG }}

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Cache .npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('website/**/package-lock.json') }}

- name: Install dependencies
run: cd website && npm i

- name: Get Installed Playwright Version
id: playwright-version
run: cd website && echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').packages['node_modules/@playwright/test'].version)")" >> $GITHUB_ENV

- name: Cache Playwright Browsers
uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}

- name: Install Playwright Browsers and System Dependencies
run: cd website && npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'

- name: Install only System Dependencies
run: cd website && npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'
- name: Wait for the pods to be ready
run: ./.github/scripts/wait_for_pods_to_be_ready.py
- name: Sleep for 20 secs
run: sleep 20
- name: Run E2E test
run: cd website && npm run e2e
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: playwright-report
path: website/playwright-report/
retention-days: 30

- name: List running pods
if: ${{ !cancelled() }}
run: kubectl get pods --all-namespaces
- name: Describe pods
if: ${{ !cancelled() }}
run: kubectl describe pods -l app=loculus -n loculus
- name: Show events
if: ${{ !cancelled() }}
run: kubectl get events -n loculus

- name: Save logs from all containers to file
if: ${{ !cancelled() }}
run: ./.github/scripts/collect_kubernetes_logs.sh
- name: Upload Kubernetes logs
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: kubernetes-logs
path: kubernetes_logs/
- name: Checkout repository
uses: actions/checkout@v4

- name: Install k3d
run: |
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
- name: Create k3d cluster
run: |
./deploy.py cluster
- name: Test helm template
uses: WyriHaximus/github-action-helm3@v3
with:
exec: helm template does-not-matter ./kubernetes/loculus > defaultTemplate.yaml

- name: Upload default helm template
uses: actions/upload-artifact@v4
with:
name: default-helm-template
path: defaultTemplate.yaml

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Cache .npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('website/**/package-lock.json') }}

- name: Install dependencies
run: cd website && npm i

- name: Get Installed Playwright Version
id: playwright-version
run: cd website && echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').packages['node_modules/@playwright/test'].version)")" >> $GITHUB_ENV

- name: Cache Playwright Browsers
uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}

- name: Install Playwright Browsers and System Dependencies
run: cd website && npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'

- name: Install only System Dependencies
run: cd website && npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'

- name: Wait for Backend Docker Image
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.ref }}
check-name: Build Backend Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Wait for Website Docker Image
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.ref }}
check-name: Build Website Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy with helm
uses: WyriHaximus/github-action-helm3@v3
with:
exec: ./deploy.py helm --branch ${{ github.ref_name }} --dockerconfigjson ${{ secrets.GHCR_DOCKER_CONFIG }}

- name: Wait for the pods to be ready
run: ./.github/scripts/wait_for_pods_to_be_ready.py
- name: Sleep for 20 secs
run: sleep 20
- name: Run E2E test
run: cd website && npm run e2e
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: playwright-report
path: website/playwright-report/
retention-days: 30

- name: List running pods
if: ${{ !cancelled() }}
run: kubectl get pods --all-namespaces
- name: Describe pods
if: ${{ !cancelled() }}
run: kubectl describe pods -l app=loculus -n loculus
- name: Show events
if: ${{ !cancelled() }}
run: kubectl get events -n loculus

- name: Save logs from all containers to file
if: ${{ !cancelled() }}
run: ./.github/scripts/collect_kubernetes_logs.sh
- name: Upload Kubernetes logs
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: kubernetes-logs
path: kubernetes_logs/
2 changes: 2 additions & 0 deletions .github/workflows/preprocessing-nextclade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ jobs:
context: ./preprocessing/nextclade
push: true
tags: ${{ steps.dockerMetadata.outputs.tags }}
cache-from: type=gha,scope=nextclade-${{ github.ref }}
cache-to: type=gha,mode=max,scope=nextclade-${{ github.ref }}
5 changes: 3 additions & 2 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: actions/cache@v4
Expand Down Expand Up @@ -83,3 +82,5 @@ jobs:
context: ./website
push: true
tags: ${{ steps.dockerMetadata.outputs.tags }}
cache-from: type=gha,scope=website-${{ github.ref }}
cache-to: type=gha,mode=max,scope=website-${{ github.ref }}

0 comments on commit d7b85ee

Please sign in to comment.