-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Publish production ready Docker image to AWS ECR #16234
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
base: main
Are you sure you want to change the base?
Changes from all commits
c895dfd
84b3216
f1cf2c1
de37f86
0d9fed0
ef60bf1
4455867
63e735e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .git | ||
| .github | ||
| node_modules | ||
| dist | ||
|
Copilot marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,14 @@ jobs: | |
| packages: write | ||
| uses: ./.github/workflows/container.yml | ||
|
|
||
| production-container: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
||
| 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 | ||
|
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 }} | ||
| 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!
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"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/bash | ||
| #!/bin/sh | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| # Automatically copy over required settings for vscode | ||
| if [ ! -f .vscode/settings.json ] ; | ||
|
|
||
There was a problem hiding this comment.
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
cdkdirectory, however the resulting image will be minimal. That is, this.dockerignoreis mainly aimed at speeding up the process of building the image locally as there are fewer files toCOPY . /app.