We should do the building inside docker. Mason suggested the following untested code.
The benefits include:
More "dockery" way to do it
Binaries will match the architecture of the container (EG: x86 vs arm)
Easier for CI / releases as we don't need client side building by a dev
Benefits from dockers caching for builds when source hasn't changed)
FROM node:20-alpine AS picr-backend-build
USER node
# TODO: exclude existing dist/public folders as we are building them
COPY package.json
RUN npm install
COPY --chown=node:node . .
RUN npm run build
RUN cd frontend && vite build && cd ..
FROM node:20-alpine
MAINTAINER Isaac Insoll '<isaac@snibi.com>'
LABEL org.opencontainers.image.source=https://github.com/isaacinsoll/picr
USER node
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY --chown=node:node package*.json ./
# NOTE THE --from=build
COPY --from=picr-backend-build --chown=node:node ./node_moules ./node_modules
COPY --from=picr-backend-build --chown=node:node ./dist ./dist
COPY --from=picr-backend-build --chown=node:node ./public ./public
EXPOSE 6900
CMD [ "node", "dist/backend/app.js" ]
We should do the building inside docker. Mason suggested the following untested code.
The benefits include: