Skip to content
Open
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
4 changes: 4 additions & 0 deletions .dockerignore

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file could include more things, such as the cdk directory, however the resulting image will be minimal. That is, this .dockerignore is mainly aimed at speeding up the process of building the image locally as there are fewer files to COPY . /app.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.github
node_modules
dist
Comment thread
Copilot marked this conversation as resolved.
8 changes: 8 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ jobs:
packages: write
uses: ./.github/workflows/container.yml

production-container:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This additional step is not required (yet), so hopefully doesn't negatively impact the DX. It'll become required once we inject the image digest to the CDK project.

permissions:
contents: read
id-token: write # Required to exchange for AWS credentials using OIDC
uses: ./.github/workflows/container-production.yml
secrets:
GU_RIFF_RAFF_ROLE_ARN: ${{ secrets.GU_RIFF_RAFF_ROLE_ARN }}

prettier:
uses: ./.github/workflows/prettier.yml

Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/container-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Production container
on:
workflow_call:
secrets:
GU_RIFF_RAFF_ROLE_ARN:
required: true
outputs:
imageDigest:
description: 'The digest of the generated container image'
value: ${{ jobs.build-production-image.outputs.imageDigest }}
Comment on lines +8 to +10

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image digest will eventually be used within CDK to form a reference to the image to run.

jobs:
facts:
runs-on: ubuntu-slim
Comment thread
akash1810 marked this conversation as resolved.
permissions: {} # This job doesn't need any permissions. Explicitly set it to an empty object to avoid inheriting any default permissions of the workflow.
outputs:
branchName: ${{ steps.get-build-facts.outputs.branchName }}
buildNumber: ${{ steps.get-build-facts.outputs.buildNumber }}
commitSha: ${{ steps.get-build-facts.outputs.commitSha }}
steps:
- uses: guardian/actions-build-facts@v0.0.1
id: get-build-facts

build-production-image:
runs-on: ubuntu-latest
needs:
- facts
permissions:
contents: read
id-token: write # Required to exchange for AWS credentials using OIDC
outputs:
imageDigest: ${{ steps.publish-image.outputs.imageDigest }}
steps:
- uses: actions/checkout@v6.0.2
Comment thread
akash1810 marked this conversation as resolved.
- name: Add commit hash for PRout
working-directory: dotcom-rendering
run: echo 'export const GIT_COMMIT_HASH = "${{ needs.facts.outputs.commitSha }}";' > src/server/prout.ts
- name: Build image
run: docker buildx build -f Production.dockerfile -t ${{ github.repository }}:latest .
- name: Publish Image
uses: guardian/actions-publish-image@v0.0.2
id: publish-image
with:
roleArn: ${{ secrets.GU_RIFF_RAFF_ROLE_ARN }}
branchName: ${{ needs.facts.outputs.branchName }}
buildNumber: ${{ needs.facts.outputs.buildNumber }}
commitSha: ${{ needs.facts.outputs.commitSha }}
34 changes: 34 additions & 0 deletions Production.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM dhi.io/node:24-alpine3.23-dev AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME/bin:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app

# Install dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /pnpm/store to speed up subsequent builds.
Comment on lines +5 to +9

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, however I think this could introduce too much complexity at this stage. Let's see how we go for now and make this optimisation later if needed.

FROM base AS dependencies
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
WORKDIR /app/dotcom-rendering
ENV PATH="node_modules/.bin:$PATH"
ENV NODE_ENV=production

# Build the application
FROM dependencies AS builder
RUN webpack --config webpack/webpack.config.js --progress
RUN node scripts/islands/island-descriptions.mjs

# Finally, create the production image with only the necessary files
FROM dhi.io/node:24-alpine3.23 AS application
WORKDIR /app
COPY --from=builder --chown=node:node /app/dotcom-rendering/dist /app

# Disable logging with Log4js as console logs will be forwarded to Central ELK with a sidecar
# TODO Maintain metrics
ENV DISABLE_LOGGING_AND_METRICS=true
Comment on lines +26 to +28

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd want to address this before running in production with reader traffic!

Comment thread
Copilot marked this conversation as resolved.
ENV NODE_ENV=production

# Expose the port that the application listens on
EXPOSE 9000

CMD ["node", "/app/server.js"]
2 changes: 1 addition & 1 deletion scripts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dhi.io/node:24-alpine3.23-dev Docker image is intentionally minimal and does not have bash. Using sh is compatible with this image and our machines.


# Automatically copy over required settings for vscode
if [ ! -f .vscode/settings.json ] ;
Expand Down
Loading