FROM node:alpine as builder
ENV NODE_ENV=development
ARG PORT=4100
ENV PORT=${PORT}
ARG HOST="0.0.0.0"
ENV HOST=${HOST}
WORKDIR /usr/src/app
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
RUN yarn install
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
RUN yarn generate:prisma # Generate Prisma Client from schema (db/schema.prisma)
RUN yarn typecheck # Validate TS types are valid first
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
COPY ./public /usr/src/app/public
COPY ./app.manifest.json /usr/src/app/app.manifest.json
RUN echo "$(git rev-parse HEAD)" >> .gitstamp
FROM node:slim as base
ENV NODE_ENV=production
ARG PORT=4100
ENV PORT=${PORT}
ARG HOST="0.0.0.0"
ENV HOST=${HOST}
WORKDIR /app
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/.gitstamp /app/.gitstamp
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/yarn.lock /app/yarn.lock
RUN echo "Running from Git commit: $(cat .gitstamp)"
EXPOSE ${PORT}
CMD ["node", "app/server.js"]