Skip to content

Commit ed717d8

Browse files
committed
fix: testing fly deploy with default docker setup
1 parent e505076 commit ed717d8

File tree

1 file changed

+62
-40
lines changed

1 file changed

+62
-40
lines changed

Dockerfile.fly

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,79 @@
1-
# syntax = docker/dockerfile:1
1+
FROM --platform=linux/amd64 node:20-alpine AS base
22

3-
# Adjust NODE_VERSION as desired
4-
ARG NODE_VERSION=20.11.0
5-
FROM node:${NODE_VERSION}-slim as base
6-
7-
LABEL fly_launch_runtime="Next.js/Prisma"
8-
9-
# Next.js/Prisma app lives here
3+
FROM base AS deps
4+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
5+
RUN apk add --no-cache libc6-compat openssl
106
WORKDIR /app
117

12-
# Set production environment
13-
# ENV NODE_ENV="production"
14-
ENV SKIP_ENV_VALIDATION=true
8+
# Install Prisma Client - remove if not using Prisma
159

10+
COPY prisma ./prisma
1611

17-
# Throw-away build stage to reduce size of final image
18-
FROM base as build
12+
ENV HUSKY 0
1913

20-
# Install packages needed to build node modules
21-
RUN apt-get update -qq && \
22-
apt-get install --no-install-recommends -y build-essential node-gyp openssl pkg-config python-is-python3
14+
# Install dependencies based on the preferred package manager
15+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
16+
RUN \
17+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
18+
elif [ -f package-lock.json ]; then npm ci; \
19+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
20+
else echo "Lockfile not found." && exit 1; \
21+
fi
2322

24-
# Install node modules
25-
COPY --link package-lock.json package.json ./
26-
RUN npm ci --include=dev
2723

28-
# Generate Prisma Client
29-
COPY --link prisma/enum-generator.cjs ./prisma/enum-generator.cjs
30-
COPY --link prisma ./
31-
RUN npx prisma generate
24+
##### BUILDER
3225

33-
# Copy application code
34-
# COPY --link prisma/enums.ts ./prisma/enums.ts
35-
COPY --link . .
26+
FROM base AS builder
27+
WORKDIR /app
28+
COPY --from=deps /app/node_modules ./node_modules
29+
COPY --from=deps /app/prisma ./prisma
30+
COPY . .
31+
32+
# Next.js collects completely anonymous telemetry data about general usage.
33+
# Learn more here: https://nextjs.org/telemetry
34+
# Uncomment the following line in case you want to disable telemetry during the build.
35+
ENV NEXT_TELEMETRY_DISABLED 1
36+
ENV DOCKER_OUTPUT 1
37+
ENV SKIP_ENV_VALIDATION 1
38+
39+
RUN \
40+
if [ -f yarn.lock ]; then yarn run build; \
41+
elif [ -f package-lock.json ]; then npm run build; \
42+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
43+
else echo "Lockfile not found." && exit 1; \
44+
fi
45+
46+
##### RUNNER
47+
48+
FROM base AS runner
49+
WORKDIR /app
3650

37-
# Build application
38-
RUN npm run build
51+
ENV NODE_ENV production
52+
# Uncomment the following line in case you want to disable telemetry during runtime.
53+
ENV NEXT_TELEMETRY_DISABLED 1
3954

40-
# Remove development dependencies
41-
RUN npm prune --omit=dev
55+
ENV DOCKER_OUTPUT 1
4256

57+
RUN addgroup --system --gid 1001 nodejs
58+
RUN adduser --system --uid 1001 nextjs
4359

44-
# Final stage for app image
45-
FROM base
60+
COPY --from=builder /app/public ./public
4661

47-
# Install packages needed for deployment
48-
RUN apt-get update -qq && \
49-
apt-get install --no-install-recommends -y openssl && \
50-
rm -rf /var/lib/apt/lists /var/cache/apt/archives
62+
# Set the correct permission for prerender cache
63+
RUN mkdir .next
64+
RUN chown nextjs:nodejs .next
5165

52-
# Copy built application
53-
COPY --from=build /app /app
66+
# Automatically leverage output traces to reduce image size
67+
# https://nextjs.org/docs/advanced-features/output-file-tracing
68+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
69+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
70+
71+
USER nextjs
5472

55-
# Start the server by default, this can be overwritten at runtime
5673
EXPOSE 3000
57-
CMD [ "npm", "run", "start" ]
74+
75+
ENV PORT 3000
76+
77+
# server.js is created by next build from the standalone output
78+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
79+
CMD HOSTNAME="0.0.0.0" node server.js

0 commit comments

Comments
 (0)