chores(examples): Define base image for multi-stage build (#45862)

Just define base docker image for multi-stage build

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
This commit is contained in:
Duc Tran 2023-02-14 01:14:26 +07:00 committed by GitHub
parent e573b20756
commit a8b3e7809a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 12 deletions

View file

@ -1,5 +1,7 @@
FROM node:18-alpine AS base
# Step 1. Rebuild the source code only when needed
FROM node:18-alpine AS builder
FROM base AS builder
WORKDIR /app
@ -41,7 +43,7 @@ RUN \
# Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here
# Step 2. Production image, copy all the files and run next
FROM node:18-alpine AS runner
FROM base AS runner
WORKDIR /app
@ -68,4 +70,4 @@ ENV NEXT_PUBLIC_ENV_VARIABLE=${NEXT_PUBLIC_ENV_VARIABLE}
# Note: Don't expose ports here, Compose will handle that for us
CMD node server.js
CMD ["node", "server.js"]

View file

@ -1,5 +1,7 @@
FROM node:18-alpine AS base
# 1. Install dependencies only when needed
FROM node:16-alpine AS deps
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
@ -15,7 +17,7 @@ RUN \
fi
# 2. Rebuild the source code only when needed
FROM node:16-alpine AS builder
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
@ -24,7 +26,7 @@ COPY .env.development.sample .env.production
RUN yarn build
# 3. Production image, copy all the files and run next
FROM node:16-alpine AS runner
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production

View file

@ -1,5 +1,7 @@
FROM node:18-alpine AS base
# 1. Install dependencies only when needed
FROM node:16-alpine AS deps
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
@ -16,7 +18,7 @@ RUN \
# 2. Rebuild the source code only when needed
FROM node:16-alpine AS builder
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
@ -25,7 +27,7 @@ COPY .env.production.sample .env.production
RUN yarn build
# 3. Production image, copy all the files and run next
FROM node:16-alpine AS runner
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production

View file

@ -1,5 +1,7 @@
FROM node:18-alpine AS base
# 1. Install dependencies only when needed
FROM node:16-alpine AS deps
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
@ -16,7 +18,7 @@ RUN \
# 2. Rebuild the source code only when needed
FROM node:16-alpine AS builder
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
@ -25,7 +27,7 @@ COPY .env.staging.sample .env.production
RUN yarn build
# 3. Production image, copy all the files and run next
FROM node:16-alpine AS runner
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production