Skip to content

Commit

Permalink
Make build process work with pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Oct 30, 2024
1 parent 4aedf17 commit 947c5dd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"type": "module",
"main": "dist/main.js",
"scripts": {
"prebuild": "rimraf dist",
"prebuild": "rm -rf dist",
"build": "nest build",
"start": "nest start",
"start:dev": "pnpm clean && nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node --experimental-loader=extensionless dist/main",
"start:prod": "node dist/main",
"typeorm": "typeorm-ts-node-esm",
"migrate": "PICSUR_PRODUCTION=\"true\" pnpm typeorm migration:generate -d ./src/datasource.ts",
"format": "prettier --write \"src/**/*.ts\"",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "0.5.3",
"version": "0.5.4",
"scripts": {
"devdb:start": "docker-compose -f ./support/dev.docker-compose.yml up -d",
"devdb:stop": "docker-compose -f ./support/dev.docker-compose.yml down",
Expand Down
7 changes: 6 additions & 1 deletion support/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ VERSION=$(cat ../package.json | grep version | head -1 | awk -F: '{ print $2 }'
echo "Building version $VERSION"

# Allow host networking for buildx
docker buildx create --append --name picsur --driver-opt network=host
# First check if builder exists
if docker buildx ls | grep -q picsur; then
docker buildx create --name picsur --append --driver-opt network=host
else
docker buildx create --name picsur --driver-opt network=host
fi

docker build \
--push \
Expand Down
18 changes: 10 additions & 8 deletions support/picsur-stage1.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# This dockerfile only builds the javascript part of the project, so tsc and angular compilation

FROM node:20 AS BUILDER_STAGE1
FROM node:20 AS builder_stage1

RUN npm install -g pnpm

SHELL ["/bin/bash", "-c"]

ADD . /picsur
WORKDIR /picsur

RUN yarn workspaces focus -A
RUN pnpm install --frozen-lockfile

RUN yarn workspace picsur-shared build
RUN yarn workspace picsur-frontend build
RUN yarn workspace picsur-backend build
RUN pnpm --filter picsur-shared build
RUN pnpm --filter picsur-frontend build
RUN pnpm --filter picsur-backend build

RUN mkdir -p /trimmed

RUN cp -r --parents ./{package.json,yarn.lock,.yarnrc.yml,branding} /trimmed
RUN cp -r --parents ./{package.json,pnpm-lock.yaml,pnpm-workspace.yaml,branding} /trimmed
RUN cp -r --parents ./{frontend,backend,shared}/{dist,package.json} /trimmed

FROM scratch

WORKDIR /picsur
ADD .yarn .yarn
COPY --from=BUILDER_STAGE1 /trimmed ./

COPY --from=builder_stage1 /trimmed ./
17 changes: 11 additions & 6 deletions support/picsur-stage2.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# This dockerfile than builds the production dependencies and the final image

# Always fetch amd64 image
FROM ghcr.io/caramelfur/picsur-alpha-stage1:latest AS BUILDER_STAGE1
FROM ghcr.io/caramelfur/picsur-alpha-stage1:latest AS builder_stage1

FROM node:20-alpine AS BUILDER_STAGE2
FROM node:20-alpine AS builder_stage2

RUN npm install -g pnpm

RUN apk add python3 build-base

WORKDIR /picsur
COPY --from=BUILDER_STAGE1 /picsur ./
COPY --from=builder_stage1 /picsur ./

RUN yarn workspaces focus -A --production
RUN pnpm install --frozen-lockfile --prod

FROM node:20-alpine

RUN npm install -g pnpm

ENV PICSUR_PRODUCTION=true

WORKDIR /picsur
COPY --from=BUILDER_STAGE2 /picsur ./
COPY --from=builder_stage2 /picsur ./

CMD ["pnpm", "--filter", "picsur-backend", "start:prod"]

CMD yarn workspace picsur-backend start:prod

0 comments on commit 947c5dd

Please sign in to comment.