Skip to content

Commit

Permalink
AUT-1984: Implement caching in pre-merge-checks
Browse files Browse the repository at this point in the history
- Cache yarn dependencies, based on the yarn.lock file
- Pre-build the sidecar container and the sidecar httpie container
  and cache them
  • Loading branch information
whi-tw committed May 24, 2024
1 parent 214eb4e commit 5344d1e
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 28 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/pre-merge-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18.12.1
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install
- name: Check formatting
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/test-sidecar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,38 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 18.12.1
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: build sidecar container
uses: docker/build-push-action@v5
with:
context: basic-auth-sidecar
push: false
tags: "basic-auth-sidecar-test:latest"
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: build sidecar httpie container
uses: docker/build-push-action@v5
with:
context: basic-auth-sidecar
file: basic-auth-sidecar/Dockerfile.httpie
push: false
tags: "basic-auth-sidecar-test-httpie:latest"
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run sidecar tests
run: yarn test:sidecar
5 changes: 2 additions & 3 deletions basic-auth-sidecar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG NGINX_FROM_IMAGE=nginx:mainline-alpine
FROM ${NGINX_FROM_IMAGE} as builder
FROM nginx:mainline-alpine as builder

ARG ENABLED_MODULES=headers-more

Expand Down Expand Up @@ -61,7 +60,7 @@ RUN set -ex \
done \
&& echo "BUILT_MODULES=\"$BUILT_MODULES\"" > /tmp/packages/modules.env

FROM ${NGINX_FROM_IMAGE}
FROM nginx:mainline-alpine
COPY --from=builder /tmp/packages /tmp/packages
RUN set -ex \
&& . /tmp/packages/modules.env \
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"@types/cheerio": "^0.22.31",
"@types/cookie-parser": "^1.4.2",
"@types/csurf": "^1.11.2",
"@types/debug": "^4.1.12",
"@types/express": "^4.17.13",
"@types/express-session": "^1.17.4",
"@types/i18next-fs-backend": "^1.1.1",
Expand All @@ -125,6 +126,7 @@
"cheerio": "^1.0.0-rc.10",
"concurrently": "^8.2.2",
"copyfiles": "^2.4.1",
"debug": "^4.3.4",
"decache": "^4.6.1",
"dotenv": "^16.4.1",
"eslint": "^8.57.0",
Expand Down
50 changes: 26 additions & 24 deletions test/basic-auth-sidecar/basic-auth-sidecar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ import {
} from "testcontainers";
import { Environment } from "testcontainers/build/types";
import path from "path";
import debug from "debug";

describe("BasicAuthSidecar", function () {
let network: StartedNetwork;
if (process.env.RUNNER_DEBUG === "1") {
debug.enable("testcontainers*");
}

const isDebug: boolean = process.env.RUNNER_DEBUG === "1";

let sidecarContainer: StartedTestContainer;
let requesterContainer: StartedTestContainer;
const isGitHubActions = process.env.GITHUB_ACTIONS === "true";

let network: StartedNetwork;
let sidecarImage: GenericContainer;
let requesterImage: GenericContainer;

let sidecarContainer: StartedTestContainer;
let requesterContainer: StartedTestContainer;

let requesterContainerIp: string;

const backendConfig = {
Expand All @@ -53,10 +57,16 @@ describe("BasicAuthSidecar", function () {
)
.start();

requesterImage = await GenericContainer.fromDockerfile(
path.join(path.dirname(__filename), "../../basic-auth-sidecar"),
"Dockerfile.httpie"
).build("basic-auth-sidecar-test-httpie", { deleteOnExit: false });
if (isGitHubActions) {
requesterImage = new GenericContainer(
"basic-auth-sidecar-test-httpie:latest"
);
} else {
requesterImage = await GenericContainer.fromDockerfile(
path.join(path.dirname(__filename), "../../basic-auth-sidecar"),
"Dockerfile.httpie"
).build("basic-auth-sidecar-test-httpie", { deleteOnExit: false });
}
requesterContainer = await requesterImage
.withNetwork(network)
.withNetworkAliases("requester")
Expand All @@ -65,9 +75,13 @@ describe("BasicAuthSidecar", function () {

requesterContainerIp = requesterContainer.getIpAddress(network.getName());

sidecarImage = await GenericContainer.fromDockerfile(
path.join(path.dirname(__filename), "../../basic-auth-sidecar")
).build("basic-auth-sidecar-test", { deleteOnExit: false });
if (isGitHubActions) {
sidecarImage = new GenericContainer("basic-auth-sidecar-test:latest");
} else {
sidecarImage = await GenericContainer.fromDockerfile(
path.join(path.dirname(__filename), "../../basic-auth-sidecar")
).build("basic-auth-sidecar-test", { deleteOnExit: false });
}
});

async function doRequestInDockerNetwork(
Expand Down Expand Up @@ -162,18 +176,6 @@ describe("BasicAuthSidecar", function () {
])
)
.start();

if (isDebug) {
// if RUNNER_DEBUG is set, stream logs to console
// this is set if the gha job is rerun with 'Enable debug logging' checked.

/* eslint-disable no-console */
(await sidecarContainer.logs())
.on("data", (line) => console.log(line))
.on("err", (line) => console.error(line))
.on("end", () => console.log("Stream closed"));
/* eslint-enable no-console */
}
}

afterEach(async () => {
Expand Down
21 changes: 20 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,13 @@
dependencies:
"@types/express-serve-static-core" "*"

"@types/debug@^4.1.12":
version "4.1.12"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917"
integrity sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==
dependencies:
"@types/ms" "*"

"@types/docker-modem@*":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@types/docker-modem/-/docker-modem-3.0.6.tgz#1f9262fcf85425b158ca725699a03eb23cddbf87"
Expand Down Expand Up @@ -1472,6 +1479,11 @@
"@types/express" "*"
"@types/sinon" "*"

"@types/ms@*":
version "0.7.34"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433"
integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==

"@types/node@*", "@types/node@^16.7.13":
version "16.11.10"
resolved "https://registry.npmjs.org/@types/node/-/node-16.11.10.tgz"
Expand Down Expand Up @@ -2614,13 +2626,20 @@ [email protected]:
dependencies:
ms "2.0.0"

debug@4, [email protected], debug@^4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4:
debug@4, [email protected], debug@^4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2:
version "4.3.4"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

decache@^4.6.1:
version "4.6.1"
resolved "https://registry.npmjs.org/decache/-/decache-4.6.1.tgz"
Expand Down

0 comments on commit 5344d1e

Please sign in to comment.