-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
227f616
commit 696b6c7
Showing
1 changed file
with
40 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,65 @@ | ||
FROM node:18-alpine AS base | ||
|
||
# Install dependencies only when needed | ||
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 | ||
|
||
# Install dependencies based on the preferred package manager | ||
COPY package.json pnpm-lock.yaml* ./ | ||
|
||
RUN apk add --no-cache python3 make g++ | ||
# Etapa 1: Prepare image for building | ||
FROM node:18-slim AS base | ||
|
||
# Install dependencies | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN \ | ||
if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ | ||
else echo "Lockfile not found." && exit 1; \ | ||
fi | ||
RUN corepack enable && apt-get update && apt-get install -y python3 make g++ git && rm -rf /var/lib/apt/lists/* | ||
|
||
|
||
# Rebuild the source code only when needed | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
|
||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
# Copy package.json and pnpm-lock.yaml | ||
COPY package.json pnpm-lock.yaml ./ | ||
|
||
RUN \ | ||
if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ | ||
else echo "Lockfile not found." && exit 1; \ | ||
fi | ||
# Install dependencies only for building | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
# Production image, copy all the files and run next | ||
FROM base AS runner | ||
WORKDIR /app | ||
# Copy the rest of the source code | ||
COPY . . | ||
|
||
ENV NODE_ENV production | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
# Build the application | ||
RUN pnpm run build | ||
|
||
# Stage 2: Prepare image for production | ||
FROM node:18-slim AS production | ||
|
||
RUN apk add git curl bash tar openssh | ||
# Install dependencies only for production | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN corepack enable && apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
|
||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
# COPY THE node modules | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/.next ./.next | ||
COPY --from=builder /app/dist ./dist | ||
COPY --from=builder /app/next.config.mjs ./next.config.mjs | ||
COPY --from=builder /app/public ./public | ||
COPY --from=builder /app/package.json ./package.json | ||
COPY --from=builder /app/drizzle ./drizzle | ||
COPY --from=builder /app/.env.production ./.env | ||
COPY --from=builder /app/components.json ./components.json | ||
# Copy the rest of the source code | ||
COPY --from=base /app/.next ./.next | ||
COPY --from=base /app/dist ./dist | ||
COPY --from=base /app/next.config.mjs ./next.config.mjs | ||
COPY --from=base /app/public ./public | ||
COPY --from=base /app/package.json ./package.json | ||
COPY --from=base /app/drizzle ./drizzle | ||
COPY --from=base /app/.env.production ./.env | ||
COPY --from=base /app/components.json ./components.json | ||
|
||
# Install dependencies only for production | ||
COPY package.json pnpm-lock.yaml ./ | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile | ||
|
||
RUN npm install --global pnpm | ||
# Install docker | ||
RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && rm get-docker.sh | ||
|
||
RUN apk update && apk add --no-cache docker-cli docker-cli-buildx | ||
|
||
# Install Nixpacks and tsx | ||
# | VERBOSE=1 VERSION=1.21.0 bash | ||
RUN curl -sSL https://nixpacks.com/install.sh -o install.sh \ | ||
&& chmod +x install.sh \ | ||
&& ./install.sh | ||
&& ./install.sh \ | ||
&& pnpm install -g tsx | ||
|
||
# Install buildpacks | ||
RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.32.1/pack-v0.32.1-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack | ||
|
||
# Install buildpacks | ||
RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.32.1/pack-v0.32.1-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack | ||
|
||
# Expose port | ||
EXPOSE 3000 | ||
|
||
# server.js is created by next build from the standalone output | ||
# https://nextjs.org/docs/pages/api-reference/next-config-js/output | ||
CMD ["pnpm", "start"] |