diff --git a/.github/workflows/pre-merge-checks.yml b/.github/workflows/pre-merge-checks.yml index daba3e1db..2d8951f84 100644 --- a/.github/workflows/pre-merge-checks.yml +++ b/.github/workflows/pre-merge-checks.yml @@ -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 diff --git a/.github/workflows/test-sidecar.yml b/.github/workflows/test-sidecar.yml index 99c3caaed..1d89e79f8 100644 --- a/.github/workflows/test-sidecar.yml +++ b/.github/workflows/test-sidecar.yml @@ -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 diff --git a/basic-auth-sidecar/Dockerfile b/basic-auth-sidecar/Dockerfile index 8b7c6450d..522c2421a 100644 --- a/basic-auth-sidecar/Dockerfile +++ b/basic-auth-sidecar/Dockerfile @@ -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 @@ -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 \ diff --git a/package.json b/package.json index 119a4e0e3..762e6842b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/basic-auth-sidecar/basic-auth-sidecar.test.ts b/test/basic-auth-sidecar/basic-auth-sidecar.test.ts index 918bd1634..1cd0c469a 100644 --- a/test/basic-auth-sidecar/basic-auth-sidecar.test.ts +++ b/test/basic-auth-sidecar/basic-auth-sidecar.test.ts @@ -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 = { @@ -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") @@ -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( @@ -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 () => { diff --git a/yarn.lock b/yarn.lock index 1396175f2..45127d43b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -2614,13 +2626,20 @@ debug@2.6.9: dependencies: ms "2.0.0" -debug@4, debug@4.3.4, debug@^4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4: +debug@4, debug@4.3.4, 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"