Skip to content

Commit

Permalink
build: fix docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Mar 31, 2024
1 parent d25b0f0 commit 868aa34
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 51 deletions.
57 changes: 11 additions & 46 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Base Stage
FROM node:18-alpine AS base
FROM node:20-alpine AS base

RUN apk add --no-cache dumb-init jq
WORKDIR /home/node/app

RUN apk add --no-cache dumb-init jq libc6-compat curl

ENV YARN_DISABLE_GIT_HOOKS=1
ENV NEXT_TELEMETRY_DISABLED=1

ENTRYPOINT ["dumb-init", "--"]

# Dependencies stage
FROM base AS deps

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app
FROM base AS builder

COPY --chown=node:node package.json ./
COPY --chown=node:node yarn.lock ./
Expand All @@ -23,58 +20,26 @@ COPY --chown=node:node .yarn/ .yarn/

RUN yarn install --immutable

# Builder stage
FROM base AS builder

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules

COPY package.json ./
COPY yarn.lock ./
COPY .yarnrc.yml .
COPY .yarn/ .yarn/
COPY src/ src/
COPY scripts/ scripts/

RUN yarn build

# Runner stage
FROM base AS runner
WORKDIR /app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy package config
COPY --chown=nextjs:node package.json ./
COPY --chown=nextjs:node yarn.lock ./
COPY --chown=nextjs:node .yarnrc.yml .
COPY --chown=nextjs:node .yarn/ .yarn/
COPY --from=builder --chown=node:node /home/node/app/src/public ./src/public
COPY --from=builder --chown=node:node /home/node/app/src/.next/standalone ./
COPY --from=builder --chown=node:node /home/node/app/src/.next/static ./src/.next/static

# Copy public directory
COPY --from=builder --chown=nextjs:nodejs /app/src/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/src/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/src/.next/static ./.next/static

# Set the production env vars
ENV PORT 8281
ENV NODE_ENV="production"
ENV NODE_OPTIONS="--enable-source-maps"

# Install production dependencies only
RUN yarn workspaces focus --all --production

# Ensure proper ownership
RUN chown nextjs:nodejs /app
RUN chown -R node:node /home/node/app/

# Switch to NextJs user
USER nextjs
USER node

# Expose the port
EXPOSE 8281

CMD ["node", "server.js"]
CMD HOSTNAME="0.0.0.0" node src/server.js
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
skyra.pw:
image: skyrabot/skyra.pw:latest
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"constate": "^3.3.2",
"deepmerge": "^4.3.0",
"mui-sx": "^1.0.0",
"next": "^13.5.0",
"next": "^13.5.6",
"next-pwa": "^5.6.0",
"next-seo": "^5.15.0",
"nextjs-progressbar": "^0.0.16",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ __metadata:
lodash: ^4.17.21
mdi-react: ^9.1.0
mui-sx: ^1.0.0
next: ^13.5.0
next: ^13.5.6
next-pwa: ^5.6.0
next-seo: ^5.15.0
nextjs-progressbar: ^0.0.16
Expand Down Expand Up @@ -8067,7 +8067,7 @@ __metadata:
languageName: node
linkType: hard

"next@npm:^13.5.0":
"next@npm:^13.5.6":
version: 13.5.6
resolution: "next@npm:13.5.6"
dependencies:
Expand Down

0 comments on commit 868aa34

Please sign in to comment.