|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +# Comments are provided throughout this file to help you get started. |
| 4 | +# If you need more help, visit the Dockerfile reference guide at |
| 5 | +# https://docs.docker.com/go/dockerfile-reference/ |
| 6 | + |
| 7 | +ARG NODE_VERSION=22.9.0 |
| 8 | + |
| 9 | +FROM node:${NODE_VERSION}-alpine AS build |
| 10 | + |
| 11 | +WORKDIR /usr/src/app |
| 12 | + |
| 13 | +# Download dependencies as a separate step to take advantage of Docker's caching. |
| 14 | +# Leverage a cache mount to /root/.npm to speed up subsequent builds. |
| 15 | +# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into |
| 16 | +# into this layer. |
| 17 | +RUN --mount=type=bind,source=package.json,target=package.json \ |
| 18 | + --mount=type=bind,source=.npmrc,target=.npmrc \ |
| 19 | + --mount=type=bind,source=packages/interface/package.json,target=packages/interface/package.json \ |
| 20 | + --mount=type=bind,source=packages/backend/package.json,target=packages/backend/package.json \ |
| 21 | + --mount=type=bind,source=packages/frontend/package.json,target=packages/frontend/package.json \ |
| 22 | + --mount=type=bind,source=package-lock.json,target=package-lock.json \ |
| 23 | + --mount=type=cache,target=/root/.npm \ |
| 24 | + npm ci -ws --include-workspace-root |
| 25 | + |
| 26 | + |
| 27 | +# Copy the rest of the source files into the image. |
| 28 | +COPY --link . . |
| 29 | + |
| 30 | +RUN npm run build --ws |
| 31 | + |
| 32 | +FROM node:${NODE_VERSION}-alpine AS production-base |
| 33 | + |
| 34 | +WORKDIR /usr/src/app |
| 35 | + |
| 36 | +# Use production node environment by default. |
| 37 | +ENV NODE_ENV=production |
| 38 | + |
| 39 | +COPY --link package.json package.json |
| 40 | + |
| 41 | +# Copy shared interface package on all production images. |
| 42 | +COPY --link ./packages/interface ./packages/interface |
| 43 | +COPY --link --from=build /usr/src/app/packages/interface/dist ./packages/interface/dist |
| 44 | + |
| 45 | +FROM production-base AS backend |
| 46 | + |
| 47 | +RUN --mount=type=bind,source=packages/backend/package.json,target=packages/backend/package.json \ |
| 48 | + --mount=type=bind,source=package-lock.json,target=package-lock.json \ |
| 49 | + --mount=type=cache,target=/root/.npm \ |
| 50 | + npm ci -w=backend --omit=dev |
| 51 | + |
| 52 | +# Run the application as a non-root user. |
| 53 | +USER node |
| 54 | + |
| 55 | +COPY --link ./packages/backend ./packages/backend |
| 56 | +COPY --link --from=build /usr/src/app/packages/backend/dist ./packages/backend/dist |
| 57 | + |
| 58 | + |
| 59 | +ENV PORT=3000 |
| 60 | +EXPOSE 3000 |
| 61 | + |
| 62 | +# Run the application. |
| 63 | +CMD ["node", "./packages/backend", "serve"] |
| 64 | + |
| 65 | +FROM nginx:stable-alpine AS frontend |
| 66 | +# This is temporary, you would just export the distribution and send it to a CDN as static assets |
| 67 | +COPY --link --from=build /usr/src/app/packages/frontend/dist /usr/share/nginx/html |
| 68 | +COPY --link ./packages/frontend/nginx/default.conf /etc/nginx/templates/default.conf.template |
| 69 | + |
| 70 | +ENV PORT=8080 |
| 71 | +EXPOSE 8080 |
0 commit comments