Skip to content

Commit 5a2b9ee

Browse files
committed
DevOps: Add Docker image to collection
1 parent 6ac7568 commit 5a2b9ee

File tree

6 files changed

+98
-32
lines changed

6 files changed

+98
-32
lines changed

collection/Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This template uses Automatically Copying Traced Files feature
2+
# so you need to setup your Next Config file to use `output: 'standalone'`
3+
# Please read this for more information https://nextjs.org/docs/pages/api-reference/next-config-js/output
4+
FROM node:18-alpine AS builder
5+
6+
ENV NEXT_TELEMETRY_DISABLED=1
7+
WORKDIR /build
8+
9+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
10+
RUN apk add --no-cache libc6-compat
11+
COPY package.json package-lock.json* ./
12+
RUN npm ci
13+
COPY project.json project.json
14+
COPY nx.json nx.json
15+
COPY .eslint* .
16+
COPY jest* .
17+
COPY tsconfig.base.json tsconfig.base.json
18+
COPY collection collection
19+
COPY common common
20+
RUN npx nx run collection:prisma-generate
21+
RUN npx nx run collection:build
22+
23+
# Production image, copy all the files and run next
24+
FROM docker.io/node:lts-alpine AS runner
25+
RUN apk add --no-cache dumb-init
26+
27+
ENV NODE_ENV=production
28+
ENV PORT=3000
29+
ENV HOSTNAME="0.0.0.0"
30+
31+
WORKDIR /app
32+
33+
# Set the correct permission for prerender cache
34+
RUN mkdir /app/.next
35+
RUN chown node:node /app/.next
36+
37+
COPY --from=builder /build/collection/next.config.js ./
38+
COPY --from=builder /build/collection/public ./public
39+
COPY --from=builder /build/collection/prisma ./prisma
40+
COPY --from=builder /build/collection/.next/standalone/collection ./
41+
COPY --from=builder /build/collection/.next/standalone/common ./
42+
COPY --from=builder /build/collection/.next/standalone/package.json ./
43+
COPY --from=builder /build/collection/.next/standalone/node_modules ./node_modules
44+
COPY --from=builder /build/collection/.next/static ./.next/static
45+
COPY --from=builder --chown=node:node /build/collection/prisma ./prisma
46+
47+
48+
# RUN npm i sharp
49+
RUN chown -R node:node .
50+
51+
USER node
52+
EXPOSE 3000
53+
# COPY --chown=node:node ./tools/scripts/entrypoints/api.sh /usr/local/bin/docker-entrypoint.sh
54+
# ENTRYPOINT [ "docker-entrypoint.sh" ]
55+
# Next.js collects completely anonymous telemetry data about general usage.
56+
# Learn more here: https://nextjs.org/telemetry
57+
# Uncomment the following line in case you want to disable telemetry.
58+
ENV NEXT_TELEMETRY_DISABLED=1
59+
CMD ["dumb-init", "node", "server.js"]

collection/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const nextConfig = {
4141
experimental: {
4242
instrumentationHook: true,
4343
},
44+
output: "standalone",
4445
};
4546

4647
const plugins = [

collection/project.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
},
4141
"prisma-validate": {
4242
"executor": "@nx-tools/nx-prisma:validate"
43+
},
44+
"container": {
45+
"executor": "@nx-tools/nx-container:build",
46+
"dependsOn": [],
47+
"options": {
48+
"engine": "docker",
49+
"metadata": {
50+
"images": [
51+
"docsoc/collection"
52+
],
53+
"load": true,
54+
"tags": [
55+
"type=schedule",
56+
"type=ref,event=branch",
57+
"type=ref,event=tag",
58+
"type=ref,event=pr",
59+
"type=sha,prefix=sha-"
60+
]
61+
}
62+
}
4363
}
4464
}
4565
}

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@babel/preset-react": "^7.24.7",
1313
"@monodon/rust": "^1.4.0",
1414
"@nx-tools/container-metadata": "^6.0.1",
15-
"@nx-tools/nx-container": "^6.0.1",
15+
"@nx-tools/nx-container": "^6.0.2",
1616
"@nx-tools/nx-prisma": "^6.1.0",
1717
"@nx/devkit": "19.4.3",
1818
"@nx/esbuild": "19.4.3",

tsconfig.base.json

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,18 @@
1010
"importHelpers": true,
1111
"target": "es2022",
1212
"module": "esnext",
13-
"lib": [
14-
"es2020",
15-
"dom"
16-
],
13+
"lib": ["es2020", "dom"],
1714
"skipLibCheck": true,
1815
"skipDefaultLibCheck": true,
1916
"baseUrl": ".",
2017
"resolveJsonModule": true,
2118
"esModuleInterop": true,
2219
"paths": {
23-
"@docsoc/eactivities": [
24-
"common/eactivities/src/index.ts"
25-
],
26-
"@docsoc/mailmerge": [
27-
"email/mailmerge/src/index.ts"
28-
],
29-
"@docsoc/mailmerge-cli": [
30-
"email/mailmerge-cli/src/index.ts"
31-
],
32-
"@docsoc/util": [
33-
"common/util/src/index.ts"
34-
]
20+
"@docsoc/eactivities": ["common/eactivities/src/index.ts"],
21+
"@docsoc/mailmerge": ["email/mailmerge/src/index.ts"],
22+
"@docsoc/mailmerge-cli": ["email/mailmerge-cli/src/index.ts"],
23+
"@docsoc/util": ["common/util/src/index.ts"]
3524
}
3625
},
37-
"exclude": [
38-
"node_modules",
39-
"tmp"
40-
]
41-
}
26+
"exclude": ["node_modules", "tmp"]
27+
}

0 commit comments

Comments
 (0)