-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (46 loc) · 1.99 KB
/
Dockerfile
File metadata and controls
63 lines (46 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# syntax=docker/dockerfile:1
# https://docs.docker.com/go/dockerfile-reference/
ARG NODE_VERSION=24
FROM node:${NODE_VERSION}-alpine AS builder
# Enable the corepack, which supports the Yarn 2+ package manager.
RUN corepack enable
# Create a directory for the application code.
WORKDIR /usr/src/app
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.yarn to speed up subsequent builds.
# Leverage a bind mounts to package.json and yarn.lock to avoid having to copy them into
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=bind,source=.yarnrc.yml,target=.yarnrc.yml \
--mount=type=cache,target=/root/.yarn \
yarn install --immutable
# Copy the rest of source files
COPY . .
# Build the application
RUN yarn build
FROM node:${NODE_VERSION}-alpine AS runner
# Use production node environment by default.
ENV NODE_ENV=production
# Enable the corepack, which supports the Yarn 2+ package manager.
RUN corepack enable
# Run the application as a non-root user.
USER node
# Create a directory for the application code.
WORKDIR /usr/src/app
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.yarn to speed up subsequent builds.
# Leverage a bind mounts to package.json and yarn.lock to avoid having to copy them into
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=bind,source=.yarnrc.yml,target=.yarnrc.yml \
--mount=type=cache,target=/root/.yarn \
yarn install --immutable
# Copy the package.json and yarn.lock files to the container.
COPY package.json yarn.lock .yarnrc.yml ./
# Copy the built application from the builder stage.
COPY --from=builder /usr/src/app/dist dist
# Expose the port that the application listens on.
EXPOSE 3000
CMD ["yarn", "start"]