Skip to content

Commit 2b16da0

Browse files
committed
Add docker container and CI to build it
1 parent 580ccfb commit 2b16da0

File tree

5 files changed

+218
-125
lines changed

5 files changed

+218
-125
lines changed

.github/workflows/docker.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
env:
8+
CI_REGISTRY_IMAGE: "${{ secrets.CI_REGISTRY }}/self-host-web"
9+
10+
jobs:
11+
build-docker:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v2
17+
- name: Login to DockerHub
18+
uses: docker/login-action@v2
19+
with:
20+
registry: ${{ secrets.CI_REGISTRY }}
21+
username: ${{ secrets.CI_REGISTRY_USER }}
22+
password: ${{ secrets.CI_REGISTRY_PASSWORD }}
23+
24+
- name: Docker Build
25+
uses: docker/build-push-action@v2
26+
with:
27+
cache-from: ${{ env.CI_REGISTRY_IMAGE }}:latest
28+
pull: true
29+
file: Dockerfile
30+
tags: ${{ env.CI_REGISTRY_IMAGE }}:${{ github.sha }}
31+
push: true
32+
- uses: beeper/docker-retag-push-latest@main
33+
with:
34+
image: ${{ env.CI_REGISTRY_IMAGE }}

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Install dependencies only when needed
2+
FROM node:20-alpine AS deps
3+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
4+
RUN apk add --no-cache libc6-compat
5+
WORKDIR /app
6+
7+
# Install dependencies based on the preferred package manager
8+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
9+
RUN \
10+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
11+
elif [ -f package-lock.json ]; then npm ci; \
12+
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
13+
else echo "Lockfile not found." && exit 1; \
14+
fi
15+
16+
17+
# Rebuild the source code only when needed
18+
FROM node:20-alpine AS builder
19+
WORKDIR /app
20+
COPY --from=deps /app/node_modules ./node_modules
21+
COPY . .
22+
23+
# Next.js collects completely anonymous telemetry data about general usage.
24+
# Learn more here: https://nextjs.org/telemetry
25+
# Uncomment the following line in case you want to disable telemetry during the build.
26+
# ENV NEXT_TELEMETRY_DISABLED 1
27+
28+
RUN yarn build
29+
30+
# If using npm comment out above and use below instead
31+
# RUN npm run build
32+
33+
# Production image, copy all the files and run next
34+
FROM node:20-alpine AS runner
35+
WORKDIR /app
36+
37+
ENV NODE_ENV production
38+
# Uncomment the following line in case you want to disable telemetry during runtime.
39+
# ENV NEXT_TELEMETRY_DISABLED 1
40+
41+
RUN addgroup --system --gid 1001 nodejs
42+
RUN adduser --system --uid 1001 nextjs
43+
44+
COPY --from=builder /app/public ./public
45+
46+
# Automatically leverage output traces to reduce image size
47+
# https://nextjs.org/docs/advanced-features/output-file-tracing
48+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
49+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
50+
51+
USER nextjs
52+
53+
EXPOSE 3000
54+
55+
ENV PORT 3000
56+
57+
CMD ["node", "server.js"]

next.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {}
2+
const nextConfig = {
3+
output: "standalone"
4+
}
35

46
module.exports = nextConfig

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
},
1111
"dependencies": {
1212
"@types/node": "20.4.8",
13-
"@types/react": "18.2.18",
14-
"@types/react-dom": "18.2.7",
13+
"@types/react": "^18.3.3",
14+
"@types/react-dom": "^18.3.0",
1515
"autoprefixer": "10.4.14",
1616
"eslint": "8.46.0",
1717
"eslint-config-next": "13.4.13",
1818
"graphql": "^16.7.1",
1919
"graphql-request": "^6.1.0",
20-
"next": "13.4.13",
20+
"next": "^14.2.4",
2121
"postcss": "8.4.27",
22-
"react": "18.2.0",
23-
"react-dom": "18.2.0",
22+
"react": "^18.3.1",
23+
"react-dom": "^18.3.1",
2424
"tailwindcss": "3.3.3",
2525
"typescript": "5.1.6"
2626
},

0 commit comments

Comments
 (0)