|
1 | | -FROM node:12 |
| 1 | +FROM node:20 AS builder |
2 | 2 |
|
3 | | -WORKDIR /app/ |
4 | | -COPY package.json /app/ |
| 3 | +# The following build sequence is adapted from the Macrostrat web repository |
| 4 | +# Install rsync |
| 5 | +RUN apt-get update && apt-get install -y rsync |
5 | 6 |
|
6 | | -RUN npm install -g parcel-bundler && npm install |
| 7 | +ENV NODE_ENV=production |
7 | 8 |
|
8 | | -COPY ./ /app/ |
| 9 | +WORKDIR /usr/src/app |
| 10 | +COPY .yarn/releases .yarn/releases |
| 11 | +COPY .yarnrc.yml yarn.lock package.json ./ |
| 12 | + |
| 13 | +# Copy only the elements needed for a Yarn install to take advantage of |
| 14 | +# Docker's layer caching |
| 15 | +# This is complex because we are working with multiple workspaces. |
| 16 | + |
| 17 | +# Copy package JSON files with wildcards |
| 18 | +# This scoops up all package.json files in the directory and subdirectories |
| 19 | +# to deal with Yarn workspaces. However it requires BUILDKIT to be enabled, |
| 20 | +# which is done by setting DOCKER_BUILDKIT=1 in the environment |
| 21 | +RUN --mount=type=bind,target=/docker-context \ |
| 22 | + cd /docker-context/; \ |
| 23 | + find . -name "package.json" -mindepth 0 -maxdepth 5 -exec cp --parents "{}" /usr/src/app/ \; |
| 24 | + |
| 25 | +# Load the cache from the previous build |
| 26 | +RUN --mount=type=cache,target=/yarn-cache \ |
| 27 | + rsync -a /yarn-cache/ .yarn/cache/ \ |
| 28 | + && yarn install --immutable \ |
| 29 | + && rsync -a .yarn/cache/ /yarn-cache |
| 30 | + |
| 31 | +# # Remove rsync |
| 32 | +RUN apt-get remove -y rsync |
| 33 | + |
| 34 | +COPY . ./ |
| 35 | + |
| 36 | +ENV NODE_ENV=development |
| 37 | + |
| 38 | +RUN yarn run build:demo-app |
| 39 | + |
| 40 | +FROM caddy:2.10-alpine AS production |
| 41 | + |
| 42 | +COPY --from=builder /usr/src/app/packages/demo-app/dist /usr/share/caddy |
| 43 | + |
| 44 | +WORKDIR /usr/share/caddy |
| 45 | + |
| 46 | +COPY docker-command.sh /run/docker-command.sh |
| 47 | + |
| 48 | +EXPOSE 80 |
| 49 | + |
| 50 | +CMD ["/run/docker-command.sh"] |
9 | 51 |
|
10 | | -CMD parcel build -d /app/dist --public-url './' index.html |
|
0 commit comments