From 8d82dc2e06a2a607c868ac138fae1d4d72d0f538 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 13 Jan 2025 09:29:40 +0000 Subject: [PATCH] Use cache for Playwright testcontainers images Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .github/workflows/end-to-end-tests.yaml | 15 +++++++++++++++ .github/workflows/playwright-image-updates.yaml | 2 +- playwright/services.ts | 2 +- playwright/testcontainers/synapse.ts | 6 +++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index 4232993fa0b..fb4c56e270c 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -48,6 +48,7 @@ jobs: outputs: num-runners: ${{ env.NUM_RUNNERS }} runners-matrix: ${{ steps.runner-vars.outputs.matrix }} + docker-cache-key: ${{ steps.runner-vars.outputs.docker-cache-key }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -80,6 +81,12 @@ jobs: run: | yarn build + # Heuristic for calculating a cache key which is based on all images we pass to testcontainers + - name: Calculate docker cache key + run: | + grep -hr "Container(\"" --exclude-dir=snapshots --exclude-dir=sample-files playwright >> _docker_cache_key + grep -hr -C1 "super(" playwright/testcontainers/ >> _docker_cache_key + - name: Upload Artifact uses: actions/upload-artifact@v4 with: @@ -90,11 +97,14 @@ jobs: - name: Calculate runner variables id: runner-vars uses: actions/github-script@v7 + env: + DOCKER_CACHE_KEY: ${{ hashFiles('_docker_cache_key') }} with: script: | const numRunners = parseInt(process.env.NUM_RUNNERS, 10); const matrix = Array.from({ length: numRunners }, (_, i) => i + 1); core.setOutput("matrix", JSON.stringify(matrix)); + core.setOutput("docker-cache-key", process.env.DOCKER_CACHE_KEY); playwright: name: "Run Tests [${{ matrix.project }}] ${{ matrix.runner }}/${{ needs.build.outputs.num-runners }}" @@ -164,6 +174,11 @@ jobs: if: matrix.project == 'WebKit' && steps.playwright-cache.outputs.cache-hit == 'true' run: yarn playwright install-deps webkit + - name: Docker image cache + uses: ScribeMD/docker-cache@fb28c93772363301b8d0a6072ce850224b73f74e # 0.5.0 + with: + key: ${{ needs.build.outputs.docker-cache-key }} + # We skip tests tagged with @mergequeue when running on PRs, but run them in MQ and everywhere else - name: Run Playwright tests run: | diff --git a/.github/workflows/playwright-image-updates.yaml b/.github/workflows/playwright-image-updates.yaml index e5e2f739c09..61e5e11e7cd 100644 --- a/.github/workflows/playwright-image-updates.yaml +++ b/.github/workflows/playwright-image-updates.yaml @@ -17,7 +17,7 @@ jobs: docker pull "$IMAGE" INSPECT=$(docker inspect --format='{{index .RepoDigests 0}}' "$IMAGE") DIGEST=${INSPECT#*@} - sed -i "s/const TAG.*/const TAG = \"develop@$DIGEST\";/" playwright/testcontainers/synapse.ts + sed -i "s,`$IMAGE.*`,`$IMAGE@$DIGEST`," playwright/testcontainers/synapse.ts env: IMAGE: ghcr.io/element-hq/synapse:develop diff --git a/playwright/services.ts b/playwright/services.ts index b480cbc4054..85be6a2dee5 100644 --- a/playwright/services.ts +++ b/playwright/services.ts @@ -50,7 +50,7 @@ export const test = base.extend<{}, Services>({ ], postgres: [ async ({ logger, network }, use) => { - const container = await new PostgreSqlContainer() + const container = await new PostgreSqlContainer("postgres:13.3-alpine") .withNetwork(network) .withNetworkAliases("postgres") .withLogConsumer(logger.getConsumer("postgres")) diff --git a/playwright/testcontainers/synapse.ts b/playwright/testcontainers/synapse.ts index 5111a6f0a66..cc33958bf69 100644 --- a/playwright/testcontainers/synapse.ts +++ b/playwright/testcontainers/synapse.ts @@ -17,8 +17,6 @@ import { Credentials } from "../plugins/homeserver"; import { deepCopy } from "../plugins/utils/object.ts"; import { HomeserverContainer, StartedHomeserverContainer } from "./HomeserverContainer.ts"; -const TAG = "develop@sha256:b69222d98abe9625d46f5d3cb01683d5dc173ae339215297138392cfeec935d9"; - const DEFAULT_CONFIG = { server_name: "localhost", public_baseurl: "", // set by start method @@ -144,7 +142,9 @@ export class SynapseContainer extends GenericContainer implements HomeserverCont private config: typeof DEFAULT_CONFIG; constructor() { - super(`ghcr.io/element-hq/synapse:${TAG}`); + super( + `ghcr.io/element-hq/synapse:develop@sha256:b69222d98abe9625d46f5d3cb01683d5dc173ae339215297138392cfeec935d9`, + ); this.config = deepCopy(DEFAULT_CONFIG); this.config.registration_shared_secret = randB64Bytes(16);