Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to debian12 #1381

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-kiwis-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': minor
---

format: Switch Distroless image from `nodejs-debian11` to `nodejs-debian12`
8 changes: 4 additions & 4 deletions docs/deep-dives/arm64.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Replace the relevant `--platform` values in your Dockerfile(s),
then ensure that you run your builds on AMD64 hardware:

```diff
- FROM --platform=arm64 gcr.io/distroless/nodejs20-debian11 AS runtime
+ FROM --platform=${BUILDPLATFORM:-amd64} gcr.io/distroless/nodejs20-debian11 AS runtime
- FROM --platform=arm64 gcr.io/distroless/nodejs20-debian12 AS runtime
+ FROM --platform=${BUILDPLATFORM:-amd64} gcr.io/distroless/nodejs20-debian12 AS runtime

- FROM --platform=${BUILDPLATFORM:-arm64} gcr.io/distroless/nodejs20-debian11 AS runtime
+ FROM --platform=${BUILDPLATFORM:-amd64} gcr.io/distroless/nodejs20-debian11 AS runtime
- FROM --platform=${BUILDPLATFORM:-arm64} gcr.io/distroless/nodejs20-debian12 AS runtime
+ FROM --platform=${BUILDPLATFORM:-amd64} gcr.io/distroless/nodejs20-debian12 AS runtime
```

For a [Gantry] service, modify the `cpuArchitecture` property in your `gantry.build.yml` and `gantry.apply.yml` resource files:
Expand Down
8 changes: 4 additions & 4 deletions src/cli/__snapshots__/format.int.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Patch skipped: Add empty exports to Jest files for compliance with TypeScript is

Patch skipped: Update Renovate config to support private SEEK packages - owner does not map to a SEEK preset

Patch skipped: Upgrade Node.js Distroless Docker image to -debian11 variant - no Dockerfile found
Patch skipped: Upgrade Node.js Distroless Docker image to -debian12 variant - no Dockerfile found

Patch skipped: Add keepAliveTimeout to server listener - no listener file found

Expand Down Expand Up @@ -79,7 +79,7 @@ Patch skipped: Add empty exports to Jest files for compliance with TypeScript is

Patch skipped: Update Renovate config to support private SEEK packages - owner does not map to a SEEK preset

Patch skipped: Upgrade Node.js Distroless Docker image to -debian11 variant - no Dockerfile found
Patch skipped: Upgrade Node.js Distroless Docker image to -debian12 variant - no Dockerfile found

Patch skipped: Add keepAliveTimeout to server listener - no listener file found

Expand Down Expand Up @@ -139,7 +139,7 @@ Patch skipped: Add empty exports to Jest files for compliance with TypeScript is

Patch skipped: Update Renovate config to support private SEEK packages - owner does not map to a SEEK preset

Patch skipped: Upgrade Node.js Distroless Docker image to -debian11 variant - no Dockerfile found
Patch skipped: Upgrade Node.js Distroless Docker image to -debian12 variant - no Dockerfile found

Patch skipped: Add keepAliveTimeout to server listener - no listener file found

Expand Down Expand Up @@ -172,7 +172,7 @@ Patch skipped: Add empty exports to Jest files for compliance with TypeScript is

Patch skipped: Update Renovate config to support private SEEK packages - owner does not map to a SEEK preset

Patch skipped: Upgrade Node.js Distroless Docker image to -debian11 variant - no Dockerfile found
Patch skipped: Upgrade Node.js Distroless Docker image to -debian12 variant - no Dockerfile found

Patch skipped: Add keepAliveTimeout to server listener - no listener file found

Expand Down
2 changes: 1 addition & 1 deletion src/cli/configure/upgrade/patches/7.3.1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const patches: Patches = [
},
{
apply: tryPatchDockerfile,
description: 'Upgrade Node.js Distroless Docker image to -debian11 variant',
description: 'Upgrade Node.js Distroless Docker image to -debian12 variant',
},
{
apply: tryPatchServerListener,
Expand Down
77 changes: 74 additions & 3 deletions src/cli/configure/upgrade/patches/7.3.1/patchDockerfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,27 @@ FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs:
WORKDIR /workdir
`;

const dockerfileDebian11 = `
ARG BASE_IMAGE
ARG BASE_TAG

FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian11 AS runtime

WORKDIR /workdir
`;

const dockerfileNonDistroless = `
ARG BASE_IMAGE
ARG BASE_TAG

FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} node:20-alpine AS runtime

WORKDIR /workdir
`;

describe('tryPatchDockerfile', () => {
describe('format mode', () => {
it('patches an existing Dockerfile', async () => {
it('patches a Dockerfile with nodejs:18', async () => {
vol.fromJSON({ Dockerfile: dockerfile });

await expect(tryPatchDockerfile('format')).resolves.toEqual({
Expand All @@ -33,7 +51,28 @@ describe('tryPatchDockerfile', () => {
ARG BASE_IMAGE
ARG BASE_TAG

FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs18-debian11 AS runtime
FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs18-debian12 AS runtime

WORKDIR /workdir
",
}
`);
});

it('patches a Dockerfile with nodejs18-debian11', async () => {
vol.fromJSON({ Dockerfile: dockerfileDebian11 });

await expect(tryPatchDockerfile('format')).resolves.toEqual({
result: 'apply',
});

expect(volToJson()).toMatchInlineSnapshot(`
{
"Dockerfile": "
ARG BASE_IMAGE
ARG BASE_TAG

FROM --platform=\${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime

WORKDIR /workdir
",
Expand All @@ -49,10 +88,20 @@ describe('tryPatchDockerfile', () => {
reason: 'no Dockerfile found',
});
});

it('ignores when a Dockerfile is not distroless', async () => {
vol.fromJSON({ Dockerfile: dockerfileNonDistroless });

await expect(tryPatchDockerfile('format')).resolves.toEqual({
result: 'skip',
});

expect(volToJson().Dockerfile).toEqual(dockerfileNonDistroless); // unchanged
});
});

describe('lint mode', () => {
it('patches an existing Dockerfile', async () => {
it('patches a Dockerfile with nodejs:18', async () => {
vol.fromJSON({ Dockerfile: dockerfile });

await expect(tryPatchDockerfile('lint')).resolves.toEqual({
Expand All @@ -62,13 +111,35 @@ describe('tryPatchDockerfile', () => {
expect(volToJson().Dockerfile).toEqual(dockerfile); // unchanged
});

it('patches a Dockerfile with nodejs18-debian11', async () => {
vol.fromJSON({ Dockerfile: dockerfileDebian11 });

await expect(tryPatchDockerfile('lint')).resolves.toEqual({
result: 'apply',
});

expect(volToJson().Dockerfile).toEqual(dockerfileDebian11); // unchanged
});

it('ignores when a Dockerfile is missing', async () => {
vol.fromJSON({});

await expect(tryPatchDockerfile('lint')).resolves.toEqual({
result: 'skip',
reason: 'no Dockerfile found',
});

expect(volToJson()).toEqual({}); // unchanged
});

it('ignores when a Dockerfile is not distroless', async () => {
vol.fromJSON({ Dockerfile: dockerfileNonDistroless });

await expect(tryPatchDockerfile('format')).resolves.toEqual({
result: 'skip',
});

expect(volToJson().Dockerfile).toEqual(dockerfileNonDistroless); // unchanged
});
});
});
12 changes: 6 additions & 6 deletions src/cli/configure/upgrade/patches/7.3.1/patchDockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { createDestinationFileReader } from '../../../analysis/project';

const DOCKERFILE_FILENAME = 'Dockerfile';

const VERSION_REGEX = /gcr.io\/distroless\/nodejs:(16|18|20)/g;
const VERSION_DEBIAN_REPLACE = 'gcr.io/distroless/nodejs$1-debian11';
const NON_DEBIAN_REGEX = /gcr.io\/distroless\/nodejs:(18|20)/g;
const DEBIAN_REGEX = /gcr.io\/distroless\/nodejs(18|20)-debian11/g;
const VERSION_DEBIAN_REPLACE = 'gcr.io/distroless/nodejs$1-debian12';

const patchDockerfile = async (
mode: 'format' | 'lint',
Expand All @@ -23,10 +24,9 @@ const patchDockerfile = async (
return { result: 'skip', reason: 'no Dockerfile found' };
}

const patched = maybeDockerfile.replaceAll(
VERSION_REGEX,
VERSION_DEBIAN_REPLACE,
);
const patched = maybeDockerfile
.replaceAll(NON_DEBIAN_REGEX, VERSION_DEBIAN_REPLACE)
.replaceAll(DEBIAN_REGEX, VERSION_DEBIAN_REPLACE);

if (patched === maybeDockerfile) {
return { result: 'skip' };
Expand Down
2 changes: 1 addition & 1 deletion template/express-rest-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN pnpm install --offline --prod

###

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian11 AS runtime
FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime

WORKDIR /workdir

Expand Down
2 changes: 1 addition & 1 deletion template/koa-rest-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN pnpm install --offline --prod

###

FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian11 AS runtime
FROM --platform=${BUILDPLATFORM:-<%- platformName %>} gcr.io/distroless/nodejs20-debian12 AS runtime

WORKDIR /workdir

Expand Down
Loading