-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
82 lines (63 loc) · 2.96 KB
/
Copy pathDockerfile
File metadata and controls
82 lines (63 loc) · 2.96 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
# NOTE: due to use of pnpm workspace, this dockerfile needs to be built
# from the repository root context.
ARG NODE_VERSION=18.14.0
ARG PNPM_VERSION=8.7.6
################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
# Set working directory for all build stages.
COPY . /app
WORKDIR /app
################################################################################
# Create a stage for building the application.
FROM base AS build
# Download additional development dependencies before building, as some projects require
# "devDependencies" to be installed to build. If you don't need this, remove this step.
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--filter "@docmaps/http-server" \
--frozen-lockfile
# Build the dependencies from this workspace
RUN pnpm --filter @docmaps/sdk --filter @docmaps/http-client run build
# Build the application
RUN pnpm --filter @docmaps/http-server run build
################################################################################
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.local/share/pnpm/store to speed up subsequent builds.
# Leverage bind mounts to package.json and pnpm-lock.yaml to avoid having to copy them
# into this layer.
FROM base AS prod
RUN npm i -g typescript@4.9.5
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--filter "@docmaps/http-server" \
--prod \
--frozen-lockfile
################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
# FIXME: build from Prod instead, once we have resolved the prepare script issue:
# https://github.com/Docmaps-Project/docmaps/issues/118
FROM prod AS runtime
# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=build /app/packages/http-server/dist /app/packages/http-server/dist
# Copy built sub-dependencies from this same package
COPY --from=build /app/packages/http-client/dist /app/packages/http-server/node_modules/@docmaps/http-client/dist
COPY --from=build /app/packages/sdk/dist /app/packages/http-server/node_modules/@docmaps/sdk/dist
WORKDIR /app/packages/http-server
# Use production node environment by default.
ENV NODE_ENV production
# Run the application as a non-root user.
USER node
# Expose the port that the application listens on.
EXPOSE 8000
# Run the application.
ENTRYPOINT [ "pnpm", "start" ]