saleor-dockerize-all-apps/apps.Dockerfile

79 lines
2.6 KiB
Docker
Raw Normal View History

2024-05-14 13:05:11 +00:00
FROM node:18-alpine AS base
FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
WORKDIR /app
RUN npm i -g turbo pnpm
COPY . .
2024-05-14 19:00:06 +00:00
ARG APP_DIR
ARG APP_NAME
2024-05-14 13:05:11 +00:00
# Generate a partial monorepo with a pruned lockfile for a target workspace.
2024-05-14 19:00:06 +00:00
RUN turbo prune "$APP_NAME" --docker
2024-05-14 13:05:11 +00:00
# Assuming "TARGET_APP" is the name entered in the project's package.json: { name: "TARGET_APP" }
# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
2024-05-14 19:00:06 +00:00
ARG APP_DIR
ARG APP_NAME
2024-05-14 13:05:11 +00:00
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
RUN npm i -g turbo pnpm
RUN pnpm i
# Build the project
COPY --from=builder /app/out/full/ .
2024-05-15 13:31:44 +00:00
RUN HOSTNAME="0.0.0.0" turbo run build --filter="$APP_NAME"...
2024-05-14 13:05:11 +00:00
FROM base AS runner
2024-05-14 19:00:06 +00:00
ARG APP_DIR
ARG APP_NAME
2024-05-14 13:05:11 +00:00
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
2024-05-14 19:00:06 +00:00
COPY --from=installer /app/apps/$APP_DIR/next.config.js .
COPY --from=installer /app/apps/$APP_DIR/package.json .
2024-05-14 13:05:11 +00:00
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
2024-05-14 19:00:06 +00:00
COPY --from=installer --chown=nextjs:nodejs /app/apps/$APP_DIR/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/$APP_DIR/.next/static ./apps/$APP_DIR/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/$APP_DIR/public ./apps/$APP_DIR/public
2024-05-14 13:05:11 +00:00
COPY --from=installer --chown=nextjs:nodejs /app/node_modules ./node_modules
# COPY --from=installer --chown=nextjs:nodejs /app/node_modules/next/dist/server/future/route-modules ./node_modules/next/dist/server/future/route-modules
# COPY --from=installer --chown=nextjs:nodejs /app/node_modules/next/dist/compiled/next-server ./node_modules/next/dist/compiled/next-server
# COPY --from=installer --chown=nextjs:nodejs /app/node_modules/next/dist/compiled/next-server ./node_modules/next/dist/compiled/next-server
# COPY --from=installer --chown=nextjs:nodejs /app/node_modules/react/jsx-runtime ./node_modules/react/jsx-runtime
2024-05-14 19:00:06 +00:00
WORKDIR /app/apps/$APP_DIR
2024-05-15 13:31:44 +00:00
CMD HOSTNAME="0.0.0.0" node server.js
2024-05-14 14:48:08 +00:00
ARG SERVICE
ARG TITLE
ARG DESC
ARG URL
ARG SOURCE
ARG AUTHORS
ARG LICENSES
LABEL service="$SERVICE"\
org.opencontainers.image.title="$TITLE"\
org.opencontainers.image.description="$DESC" \
org.opencontainers.image.url="$URL"\
org.opencontainers.image.source="$SOURCE"\
org.opencontainers.image.authors="$AUTHORS"\
org.opencontainers.image.licenses="$LICENSES"