|
1 | | -FROM graphile/postgraphile:4 |
| 1 | +# Global args, set before the first FROM, shared by all stages |
| 2 | +ARG NODE_ENV="production" |
2 | 3 |
|
3 | | -# Install additional plugins |
4 | | -RUN yarn global add \ |
5 | | - postgraphile-plugin-connection-filter-relations \ |
6 | | - @graphile-contrib/pg-simplify-inflector |
| 4 | +################################################################################ |
| 5 | +# Build stage 1 - `yarn build` |
| 6 | + |
| 7 | +FROM node:22-alpine as builder |
| 8 | +# Import our shared args |
| 9 | +ARG NODE_ENV |
| 10 | + |
| 11 | +# Cache node_modules for as long as possible |
| 12 | +COPY package.json yarn.lock /app/ |
| 13 | +WORKDIR /app/ |
| 14 | +RUN yarn install --frozen-lockfile --production=false --no-progress |
| 15 | + |
| 16 | +# Copy over the server source code |
| 17 | +COPY server/ /app/server/ |
| 18 | + |
| 19 | +# Finally run the build script |
| 20 | +RUN yarn run build |
| 21 | + |
| 22 | +################################################################################ |
| 23 | +# Build stage 2 - COPY the relevant things (multiple steps) |
| 24 | + |
| 25 | +FROM node:22-alpine as clean |
| 26 | +# Import our shared args |
| 27 | +ARG NODE_ENV |
| 28 | + |
| 29 | +# Copy over selectively just the things we need, try and avoid the rest |
| 30 | +COPY --from=builder /app/package.json /app/yarn.lock /app/ |
| 31 | +COPY --from=builder /app/server/dist/ /app/server/dist/ |
| 32 | + |
| 33 | +################################################################################ |
| 34 | +# Build stage FINAL - COPY everything, once, and then do a clean `yarn install` |
| 35 | + |
| 36 | +FROM node:22-alpine |
| 37 | +# Import our shared args |
| 38 | +ARG NODE_ENV |
| 39 | + |
| 40 | +EXPOSE 5000 |
| 41 | +WORKDIR /app/ |
| 42 | +# Copy everything from stage 2, it's already been filtered |
| 43 | +COPY --from=clean /app/ /app/ |
| 44 | + |
| 45 | +# Install yarn ASAP because it's the slowest |
| 46 | +RUN yarn install --frozen-lockfile --production=true --no-progress |
| 47 | + |
| 48 | +LABEL description="My PostGraphile-powered server" |
| 49 | + |
| 50 | +# You might want to disable GRAPHILE_TURBO if you have issues |
| 51 | +ENV GRAPHILE_TURBO=1 |
| 52 | +ENV NODE_ENV=$NODE_ENV |
| 53 | +ENTRYPOINT yarn start |
0 commit comments