Skip to content

Commit

Permalink
chore: Define base image for multi-stage Docker build (vercel#4743)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihmpavel authored and NicholasLYang committed May 9, 2023
1 parent cbb7b87 commit 426a2a4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/pages/blog/turbo-0-4-0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ COPY --from=pruner /app/out/yarn.lock ./yarn.lock
RUN yarn install
# Copy source code of pruned subworkspace and build
FROM base as builder
FROM base AS builder
WORKDIR /app
COPY --from=pruner /app/.git ./.git
COPY --from=pruner /app/out/full/ .
Expand Down
8 changes: 5 additions & 3 deletions docs/pages/repo/docs/handbook/deploying-with-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ Splitting up **dependencies** and **source files** in this way lets us **only ru
Our detailed [`with-docker` example](https://github.com/vercel/turbo/tree/main/examples/with-docker) goes into depth on how to utilise `prune` to its full potential. Here's the Dockerfile, copied over for convenience.

```docker
FROM node:alpine AS builder
FROM node:18-alpine AS base
FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
Expand All @@ -124,7 +126,7 @@ COPY . .
RUN turbo prune --scope=web --docker
# Add lockfile and package.json's of isolated subworkspace
FROM node:alpine AS installer
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
Expand All @@ -139,7 +141,7 @@ RUN yarn install
COPY --from=builder /app/out/full/ .
RUN yarn turbo run build --filter=web...
FROM node:alpine AS runner
FROM base AS runner
WORKDIR /app
# Don't run production as root
Expand Down
8 changes: 5 additions & 3 deletions examples/with-docker/apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM node:18-alpine AS base

# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs.

FROM node:alpine AS builder
FROM base AS builder
# 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
RUN apk update
Expand All @@ -12,7 +14,7 @@ COPY . .
RUN turbo prune --scope=api --docker

# Add lockfile and package.json's of isolated subworkspace
FROM node:alpine AS installer
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
Expand All @@ -36,7 +38,7 @@ COPY turbo.json turbo.json

RUN yarn turbo run build --filter=api...

FROM node:alpine AS runner
FROM base AS runner
WORKDIR /app

# Don't run production as root
Expand Down
8 changes: 5 additions & 3 deletions examples/with-docker/apps/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM node:18-alpine AS base

# This Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
# Make sure you update both files!

FROM node:alpine AS builder
FROM base AS builder
# 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
RUN apk update
Expand All @@ -12,7 +14,7 @@ COPY . .
RUN turbo prune --scope=web --docker

# Add lockfile and package.json's of isolated subworkspace
FROM node:alpine AS installer
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
Expand All @@ -36,7 +38,7 @@ COPY turbo.json turbo.json

RUN yarn turbo run build --filter=web...

FROM node:alpine AS runner
FROM base AS runner
WORKDIR /app

# Don't run production as root
Expand Down

0 comments on commit 426a2a4

Please sign in to comment.