~Dockerfile
.dockerfile
Dockerfile
(text/x-dockerfile)
FROM node:alpine as builder

ENV NODE_ENV=production
ENV PORT=4100

WORKDIR /app/build

COPY ./patches        .
COPY ./package.json   .
COPY ./yarn.lock      .

RUN yarn # Install dependencies

COPY ./app      .
COPY ./db       .
COPY ./public   .
COPY ./types    .

COPY ./app.manifest.json   .
COPY ./paths.ts            .
COPY ./tsconfig.json       .

COPY ReadMe.md   .
COPY LICENSE     .

RUN yarn typecheck         # Validate TS types are valid first
RUN yarn clean             # Cleanup working dir
RUN yarn generate:prisma   # Generate Prisma Client from schema (db/schema.prisma)
RUN yarn build:ts          # Transpile TypeScript to JavaScript (node)
RUN yarn bundle:islands    # Bundle Islands (react-monolith) to ESM/CJS/UMD

# If everything went well, issue a git stamp file containing built commit hash.
RUN echo "$(git rev-parse HEAD)" >> .gitstamp

FROM node:slim as base

ENV NODE_ENV=production
ENV PORT=4100

WORKDIR /app

COPY --from=builder /app/build/.gitstamp      .
COPY --from=builder /app/build/dist           .
COPY --from=builder /app/build/node_modules   .
COPY --from=builder /app/build/yarn.lock      .
COPY --from=builder /app/build/ReadMe.md      .
COPY --from=builder /app/build/LICENSE        .

RUN echo "Running from Git commit: $(cat .gitstamp)"

CMD ['node', 'app/server.js']