Skip to content

Commit

Permalink
Use cache for Playwright testcontainers images
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jan 13, 2025
1 parent effef7e commit 8d82dc2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/end-to-end-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playwright-image-updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion playwright/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 3 additions & 3 deletions playwright/testcontainers/synapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8d82dc2

Please sign in to comment.