Skip to content

Commit 7921273

Browse files
authored
Add template NextJS dockerfile + build job (#2)
for work relating to 8696kuv0g
1 parent f8f9cfc commit 7921273

File tree

6 files changed

+118
-2
lines changed

6 files changed

+118
-2
lines changed

.github/workflows/ts-build.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Typescript Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- typescript-demo/**
9+
pull_request:
10+
paths:
11+
- 'typescript-demo/**'
12+
release:
13+
types: [created]
14+
15+
jobs:
16+
docker:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v3
25+
if: ${{ github.event_name == 'release' }}
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Build
31+
uses: docker/build-push-action@v6
32+
if: ${{ github.event_name != 'release' }}
33+
with:
34+
context: "{{defaultContext}}:typescript-demo"
35+
push: false
36+
- name: Build and push
37+
uses: docker/build-push-action@v6
38+
if: ${{ github.event_name == 'release' }}
39+
with:
40+
context: "{{defaultContext}}:typescript-demo"
41+
push: true
42+
tags: "ghcr.io/british-oceanographic-data-centre/amrit-repos/typescript/app:${{ github.ref_name }}"

.github/workflows/ts-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
run: npm install
2323
- name: Run ESLint
2424
working-directory: ./typescript-demo
25-
run: npm run lint
25+
run: npm run lint

typescript-demo/.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
README.md
6+
.next
7+
.git

typescript-demo/Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM cgr.dev/chainguard/node AS base
2+
3+
LABEL org.opencontainers.image.authors="matcor@noc.ac.uk"
4+
LABEL org.opencontainers.image.description="Example OCI image for a NextJS application."
5+
LABEL org.opencontainers.image.url="https://github.com/British-Oceanographic-Data-Centre/amrit-repos"
6+
LABEL org.opencontainers.image.source="https://github.com/British-Oceanographic-Data-Centre/amrit-repos"
7+
LABEL org.opencontainers.image.documentation="https://github.com/British-Oceanographic-Data-Centre/amrit-repos/wiki"
8+
LABEL org.opencontainers.image.licenses="TBD"
9+
LABEL org.opencontainers.image.vendor="Advance Marine Research Infrastructures Together (AMRIT)"
10+
11+
USER root
12+
13+
# Install dependencies only when needed
14+
FROM base AS deps
15+
16+
WORKDIR /app
17+
18+
COPY package.json package-lock.json ./
19+
RUN npm ci
20+
21+
# Rebuild the source code only when needed
22+
FROM base AS builder
23+
WORKDIR /app
24+
COPY --from=deps /app/node_modules ./node_modules
25+
COPY . .
26+
27+
# Next.js collects completely anonymous telemetry data about general usage.
28+
# Learn more here: https://nextjs.org/telemetry
29+
# Uncomment the following line in case you want to disable telemetry during the build.
30+
# ENV NEXT_TELEMETRY_DISABLED=1
31+
32+
RUN npm run build
33+
34+
# Production image, copy all the files and run next
35+
FROM base AS runner
36+
WORKDIR /app
37+
38+
ENV NODE_ENV=production
39+
# Uncomment the following line in case you want to disable telemetry during runtime.
40+
# ENV NEXT_TELEMETRY_DISABLED=1
41+
42+
RUN addgroup --system --gid 1001 nodejs
43+
RUN adduser --system --uid 1001 nextjs
44+
45+
COPY --from=builder /app/public ./public
46+
47+
# Set the correct permission for prerender cache
48+
RUN mkdir .next
49+
RUN chown nextjs:nodejs .next
50+
51+
# Automatically leverage output traces to reduce image size
52+
# https://nextjs.org/docs/advanced-features/output-file-tracing
53+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
54+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
55+
56+
USER nextjs
57+
58+
EXPOSE 3000
59+
60+
ENV PORT=3000
61+
62+
# server.js is created by next build from the standalone output
63+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
64+
ENV HOSTNAME="0.0.0.0"
65+
CMD ["server.js"]

typescript-demo/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
22

3+
Docker image is available publicly using `docker pull ghcr.io/british-oceanographic-data-centre/amrit-repos/typescript/app:{TAG}`.
4+
35
## Getting Started
46

57

typescript-demo/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4-
/* config options here */
4+
output: "standalone",
55
};
66

77
export default nextConfig;

0 commit comments

Comments
 (0)