@@ -1,51 +1,74 @@
FROM node:alpine as builder
-ENV NODE_ENV=production
-ENV PORT=4100
+ENV NODE_ENV=development
+ARG PORT=4100
+ENV PORT=${PORT}
+ARG HOST="0.0.0.0"
+ENV HOST=${HOST}
+
+WORKDIR /usr/src/app
-WORKDIR /app/build # as .
+# [local tree] [builder tree]
-COPY ./patches .
-COPY ./package.json .
-COPY ./yarn.lock .
+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 dependencies
+# Install dependencies
+RUN yarn install
-COPY ./app .
-COPY ./db .
-COPY ./public .
-COPY ./types .
+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 ./app.manifest.json .
-COPY ./paths.ts .
-COPY ./tsconfig.json .
+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 .
-COPY LICENSE .
+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 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
+COPY ./public /usr/src/app/public
+COPY ./app.manifest.json /usr/src/app/app.manifest.json
+
# 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
+ARG PORT=4100
+ENV PORT=${PORT}
+ARG HOST="0.0.0.0"
+ENV HOST=${HOST}
-WORKDIR /app # as .
+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 .
+# [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/.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)"
-CMD ['node', 'app/server.js']
+EXPOSE ${PORT}
+
+CMD ["node", "app/server.js"]