Skip to content

Commit b4523d2

Browse files
authored
separate Docker files from Moda & Azure (#53633)
1 parent 48d7100 commit b4523d2

6 files changed

+117
-0
lines changed

.github/workflows/azure-preview-env-deploy-public.yml

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ jobs:
123123
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755
124124
with:
125125
context: .
126+
file: Dockerfile.azure
126127
push: true
127128
target: preview
128129
tags: ${{ env.DOCKER_IMAGE }}

.github/workflows/azure-preview-env-deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ jobs:
174174
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755
175175
with:
176176
context: .
177+
file: Dockerfile.azure
177178
push: true
178179
target: ${{ steps.with-translations.outputs.result == 'true' && 'production' || 'preview' }}
179180
tags: ${{ env.DOCKER_IMAGE }}

.github/workflows/azure-prod-build-deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ jobs:
104104
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755
105105
with:
106106
context: .
107+
file: Dockerfile.azure
107108
push: true
108109
target: production
109110
tags: ${{ env.DOCKER_IMAGE }}, ${{ env.DOCKER_IMAGE_CACHE_REF }}

.github/workflows/azure-staging-build-deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755
9595
with:
9696
context: .
97+
file: Dockerfile.azure
9798
push: true
9899
target: production
99100
tags: ${{ env.DOCKER_IMAGE }}

.github/workflows/main-preview-docker-cache.yml

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755
7272
with:
7373
context: .
74+
file: Dockerfile.azure
7475
push: true
7576
target: preview
7677
tags: ${{ env.DOCKER_IMAGE_CACHE_REF }}

Dockerfile.azure

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# This Dockerfile is used for docker-based deployments to Azure for both preview environments and production
2+
3+
# --------------------------------------------------------------------------------
4+
# BASE IMAGE
5+
# --------------------------------------------------------------------------------
6+
# To update the sha, run `docker pull node:$VERSION-alpine`
7+
# look for something like: `Digest: sha256:0123456789abcdef`
8+
FROM node:22-alpine@sha256:c13b26e7e602ef2f1074aef304ce6e9b7dd284c419b35d89fcf3cc8e44a8def9 AS base
9+
10+
# This directory is owned by the node user
11+
ARG APP_HOME=/home/node/app
12+
13+
# Make sure we don't run anything as the root user
14+
USER node
15+
16+
WORKDIR $APP_HOME
17+
18+
19+
# ---------------
20+
# ALL DEPS
21+
# ---------------
22+
FROM base AS all_deps
23+
24+
COPY --chown=node:node package.json package-lock.json ./
25+
26+
RUN npm ci --no-optional --registry https://registry.npmjs.org/
27+
28+
# For Next.js v12+
29+
# This the appropriate necessary extra for node:VERSION-alpine
30+
# Other options are https://www.npmjs.com/search?q=%40next%2Fswc
31+
RUN npm i @next/swc-linux-x64-musl --no-save || npm i @next/swc-linux-arm64-musl --no-save
32+
33+
34+
# ---------------
35+
# PROD DEPS
36+
# ---------------
37+
FROM all_deps AS prod_deps
38+
39+
RUN npm prune --production
40+
41+
42+
# ---------------
43+
# BUILDER
44+
# ---------------
45+
FROM all_deps AS builder
46+
47+
COPY src ./src
48+
# The star is because it's an optional directory
49+
COPY .remotejson-cache* ./.remotejson-cache
50+
# The star is because it's an optional file
51+
COPY .pageinfo-cache.json.br* ./.pageinfo-cache.json.br
52+
# Certain content is necessary for being able to build
53+
COPY content/index.md ./content/index.md
54+
COPY content/rest ./content/rest
55+
COPY data ./data
56+
57+
COPY next.config.js ./next.config.js
58+
COPY tsconfig.json ./tsconfig.json
59+
60+
RUN npm run build
61+
62+
# --------------------------------------------------------------------------------
63+
# PREVIEW IMAGE - no translations
64+
# --------------------------------------------------------------------------------
65+
66+
FROM base AS preview
67+
68+
# Copy just prod dependencies
69+
COPY --chown=node:node --from=prod_deps $APP_HOME/node_modules $APP_HOME/node_modules
70+
71+
# Copy our front-end code
72+
COPY --chown=node:node --from=builder $APP_HOME/.next $APP_HOME/.next
73+
74+
# We should always be running in production mode
75+
ENV NODE_ENV=production
76+
77+
# Preferred port for server.js
78+
ENV PORT=4000
79+
80+
ENV ENABLED_LANGUAGES="en"
81+
82+
# This makes it possible to set `--build-arg BUILD_SHA=abc123`
83+
# and it then becomes available as an environment variable in the docker run.
84+
ARG BUILD_SHA
85+
ENV BUILD_SHA=$BUILD_SHA
86+
87+
# Copy only what's needed to run the server
88+
COPY --chown=node:node package.json ./
89+
COPY --chown=node:node assets ./assets
90+
COPY --chown=node:node content ./content
91+
COPY --chown=node:node src ./src
92+
COPY --chown=node:node .remotejson-cache* ./.remotejson-cache
93+
COPY --chown=node:node .pageinfo-cache.json.br* ./.pageinfo-cache.json.br
94+
COPY --chown=node:node data ./data
95+
COPY --chown=node:node next.config.js ./
96+
COPY --chown=node:node tsconfig.json ./
97+
98+
EXPOSE $PORT
99+
100+
CMD ["node_modules/.bin/tsx", "src/frame/server.ts"]
101+
102+
# --------------------------------------------------------------------------------
103+
# PRODUCTION IMAGE - includes all translations
104+
# --------------------------------------------------------------------------------
105+
FROM preview AS production
106+
107+
# Override what was set for previews
108+
# Make this match the default of `Object.keys(languages)` in src/languages/lib/languages.js
109+
ENV ENABLED_LANGUAGES "en,zh,es,pt,ru,ja,fr,de,ko"
110+
111+
# Copy in all translations
112+
COPY --chown=node:node translations ./translations

0 commit comments

Comments
 (0)