IsaacInsoll / PICR

Self Hosted Media Delivery Service for Photographers and Videographers
6 stars 1 forks source link

Build inside Docker #9

Open IsaacInsoll opened 2 weeks ago

IsaacInsoll commented 2 weeks ago

We should do the building inside docker. Mason suggested the following untested code.

The benefits include:

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" ]