Created
July 16, 2025 14:33
-
-
Save andrebrito16/1edc4ee1d070c1e352a654d9f5cc0da4 to your computer and use it in GitHub Desktop.
Dockerfile build Next Turbopack
This file contains hidden or 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
| # syntax=docker.io/docker/dockerfile:1 | |
| FROM node:22-alpine3.18 AS base | |
| 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 openssl openssl-dev libssl1.1 curl \ | |
| build-base \ | |
| cairo cairo-dev \ | |
| pango pango-dev \ | |
| libpng libpng-dev \ | |
| jpeg jpeg-dev \ | |
| giflib giflib-dev \ | |
| librsvg librsvg-dev \ | |
| pixman pixman-dev \ | |
| fontconfig \ | |
| ttf-freefont | |
| WORKDIR /app | |
| COPY prisma ./prisma | |
| ARG SITEMAP_ENV=dev | |
| ENV SITEMAP_ENV=$SITEMAP_ENV | |
| COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ | |
| RUN \ | |
| if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ | |
| elif [ -f package-lock.json ]; then npm ci; \ | |
| elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && corepack prepare [email protected] --activate && pnpm install --frozen-lockfile --ignore-scripts=false; \ | |
| else echo "Lockfile not found." && exit 1; \ | |
| fi | |
| # RUN npx next-ws-cli@latest patch | |
| # Sitemap | |
| RUN mkdir -p ./public | |
| RUN curl -f -o ./public/sitemap_index.xml https://cdn-prod.teachy.app/sitemap-indexes/sitemap_index.xml | |
| RUN curl -f -o ./public/sitemap_index_en_US.xml https://cdn-prod.teachy.app/sitemap-indexes/sitemap_index_en_US.xml | |
| RUN curl -f -o ./public/sitemap_index_ai.xml https://cdn-prod.teachy.app/sitemap-indexes/sitemap_index_ai.xml | |
| FROM base AS builder | |
| WORKDIR /app | |
| COPY --from=deps /app/node_modules ./node_modules | |
| COPY . . | |
| RUN apk add --no-cache build-base \ | |
| cairo cairo-dev \ | |
| pango pango-dev \ | |
| libpng libpng-dev \ | |
| jpeg jpeg-dev \ | |
| giflib giflib-dev \ | |
| librsvg librsvg-dev \ | |
| pixman pixman-dev \ | |
| fontconfig \ | |
| ttf-freefont | |
| ENV NEXT_TELEMETRY_DISABLED=1 | |
| ENV WATCHPACK_POLLING=true | |
| RUN corepack enable pnpm && corepack prepare [email protected] --activate && pnpm prisma generate | |
| ENV NODE_OPTIONS=--max_old_space_size=8288 | |
| # Generate ENV file from base64 encoded string | |
| ARG ENV_BASE64 | |
| ENV ENV_BASE64=$ENV_BASE64 | |
| RUN \ | |
| if [ -n "$ENV_BASE64" ]; then \ | |
| echo "$ENV_BASE64" | base64 -d > .env; \ | |
| fi | |
| # Replace REDIS_AVAILABLE to false to prevent build try to connect to Redisa | |
| RUN sed -i 's/REDIS_AVAILABLE=true/REDIS_AVAILABLE=false/' .env | |
| ARG GIT_HASH | |
| ENV GIT_HASH=$GIT_HASH | |
| RUN echo "[DEBUG] GIT_HASH is: $GIT_HASH" | |
| RUN \ | |
| if [ -f yarn.lock ]; then yarn run build:docker; \ | |
| elif [ -f package-lock.json ]; then npm run build:docker; \ | |
| elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build:docker; \ | |
| else echo "Lockfile not found." && exit 1; \ | |
| fi | |
| FROM base AS runner | |
| WORKDIR /app | |
| RUN apk add --no-cache build-base \ | |
| cairo cairo-dev \ | |
| pango pango-dev \ | |
| libpng libpng-dev \ | |
| jpeg jpeg-dev \ | |
| giflib giflib-dev \ | |
| librsvg librsvg-dev \ | |
| pixman pixman-dev \ | |
| fontconfig \ | |
| ttf-freefont | |
| ENV NEXT_TELEMETRY_DISABLED=1 | |
| RUN addgroup --system --gid 1001 nodejs | |
| RUN adduser --system --uid 1001 nextjs | |
| COPY --from=builder /app/public ./public | |
| COPY --from=deps /app/public/sitemap_index.xml ./public/sitemap_index.xml | |
| COPY --from=deps /app/public/sitemap_index_en_US.xml ./public/sitemap_index_en_US.xml | |
| COPY --from=deps /app/public/sitemap_index_ai.xml ./public/sitemap_index_ai.xml | |
| RUN chown -R nextjs:nodejs /app | |
| RUN ls -R /app/.next || echo "No .next directory found" | |
| COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | |
| COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | |
| COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma | |
| COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./next.config.js | |
| COPY --from=builder --chown=nextjs:nodejs /app/next-i18next.config.js ./i18next.config.js | |
| USER nextjs | |
| EXPOSE 3000 | |
| ENV PORT=3000 | |
| ENV HOSTNAME="0.0.0.0" | |
| CMD ["node", "--max_old_space_size=8192", "server.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment