|
1 | 1 | # Node builder image |
2 | | -FROM uselagoon/node-20-builder:latest AS builder |
| 2 | +FROM uselagoon/node-20-builder:latest AS dev |
3 | 3 |
|
4 | | -COPY . /app/ |
| 4 | +# Copy only what we need into the image |
| 5 | +COPY ./src/ /app/src |
| 6 | +COPY server.js . |
| 7 | +COPY plugins.json . |
| 8 | +COPY package.json . |
| 9 | +COPY yarn.lock . |
| 10 | +COPY tour.json . |
| 11 | +COPY tourHash.js . |
5 | 12 |
|
6 | | -RUN yarn install --network-timeout 300000 |
| 13 | +# Upgrade the yarn version in /app to the most recent to take advantage of new features |
| 14 | +RUN yarn set version berry |
7 | 15 |
|
8 | | - |
9 | | -# Node service image |
10 | | -FROM uselagoon/node-20:latest |
| 16 | +# use a buildkit cache for yarn - this is reused in later steps |
| 17 | +RUN --mount=type=cache,target=/home/.yarn YARN_CACHE_FOLDER=/home/.yarn yarn install --network-timeout 300000 |
11 | 18 |
|
12 | 19 | ARG LAGOON_VERSION |
| 20 | +ARG GRAPHQL_API |
| 21 | +ARG KEYCLOAK_API |
13 | 22 | ENV LAGOON_VERSION=$LAGOON_VERSION |
| 23 | +ENV GRAPHQL_API=$GRAPHQL_API |
| 24 | +ENV KEYCLOAK_API=$KEYCLOAK_API |
14 | 25 |
|
15 | | -# Copy the node_modules from node builder |
16 | | -COPY --from=builder /app/node_modules /app/node_modules |
| 26 | +# Use an intermediate image to build and trim the production image |
| 27 | +FROM uselagoon/node-20:latest AS prod-builder |
17 | 28 |
|
18 | | -# Copying files from ui service |
19 | | -COPY . /app/ |
| 29 | +# Copy the whole /app folder from dev |
| 30 | +COPY --from=dev /app/ /app/ |
20 | 31 |
|
21 | | -ARG KEYCLOAK_API |
22 | | -ENV KEYCLOAK_API=$KEYCLOAK_API |
| 32 | +# Build app |
| 33 | +RUN --mount=type=cache,target=/home/.yarn YARN_CACHE_FOLDER=/home/.yarn yarn run build |
| 34 | +# Remove any node_modules in DevDependencies not needed for production |
| 35 | +RUN --mount=type=cache,target=/home/.yarn YARN_CACHE_FOLDER=/home/.yarn yarn workspaces focus -A --production |
23 | 36 |
|
24 | | -ARG GRAPHQL_API |
25 | | -ENV GRAPHQL_API=$GRAPHQL_API |
| 37 | +# Build the final production image |
| 38 | +FROM uselagoon/node-20:latest |
26 | 39 |
|
27 | | -# Build app |
28 | | -RUN yarn run build |
| 40 | +# Copy the whole /app folder from prod-builder |
| 41 | +COPY --from=prod-builder /app/ /app/ |
29 | 42 |
|
30 | 43 | EXPOSE 3000 |
31 | 44 | CMD ["yarn", "start"] |
0 commit comments