7506cc5 (parent dcaf526)12/10/2023, 12:16:03 AM
~Dockerfile
.dockerfile
Dockerfile
(text/x-dockerfile)
FROM node:alpine as builder

ENV NODE_ENV=development
ENV NODE_OPTIONS=--openssl-legacy-provider

ARG PORT=4100
ENV PORT=${PORT}
ARG HOST="0.0.0.0"
ENV HOST=${HOST}

WORKDIR /usr/src/app

#    [local tree]          [builder tree]

COPY ./patches             /usr/src/app/patches
COPY ./package.json        /usr/src/app/package.json
COPY ./tsconfig.json       /usr/src/app/tsconfig.json
COPY ./yarn.lock           /usr/src/app/yarn.lock

# Install dependencies
RUN apk upgrade --no-cache openssl
RUN yarn install

#    [local tree]          [builder tree]

COPY ./.git                /usr/src/app/.git
COPY ./app                 /usr/src/app/app
COPY ./db                  /usr/src/app/db
COPY ./public              /usr/src/app/public
COPY ./types               /usr/src/app/types

COPY ./.env                /usr/src/app/.env
COPY ./app.manifest.json   /usr/src/app/app.manifest.json
COPY ./paths.ts            /usr/src/app/paths.ts

COPY ./ReadMe.md           /usr/src/app/ReadMe.md
COPY ./LICENSE             /usr/src/app/LICENSE

ENV NODE_ENV=production
ENV NODE_OPTIONS=--openssl-legacy-provider

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

#    [local tree]          [builder tree]

COPY ./public              /usr/src/app/public
COPY ./app.manifest.json   /usr/src/app/app.manifest.json

FROM node:slim as base

ENV NODE_ENV=production
ENV NODE_OPTIONS=--openssl-legacy-provider

ARG PORT=4100
ENV PORT=${PORT}
ARG HOST="0.0.0.0"
ENV HOST=${HOST}

RUN apt-get update && \
    apt-get install -y --no-install-recommends git openssl && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

#                   [builder tree]              [base tree]

COPY --from=builder /usr/src/app/dist           /app
COPY --from=builder /usr/src/app/db             /app/db
COPY --from=builder /usr/src/app/node_modules   /app/node_modules
COPY --from=builder /usr/src/app/public         /app/public
COPY --from=builder /usr/src/app/.env           /app/.env
COPY --from=builder /usr/src/app/ReadMe.md      /app/ReadMe.md
COPY --from=builder /usr/src/app/LICENSE        /app/LICENSE
COPY --from=builder /usr/src/app/package.json   /app/package.json
COPY --from=builder /usr/src/app/yarn.lock      /app/yarn.lock

# Generate git stamp file
COPY --from=builder /usr/src/app/.git           /app/.git
RUN git rev-parse HEAD > .gitstamp
COPY ./.gitstamp    /app/.gitstamp
RUN rm -rf /app/.git

EXPOSE ${PORT}

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