chore: update docker file to multi stage builds

This commit is contained in:
moonrailgun 2024-03-08 03:06:38 +08:00
parent 1872a5d437
commit ebc91d9531
2 changed files with 30 additions and 8 deletions

View File

@ -1,22 +1,43 @@
FROM node:20-alpine # tianji reporter
FROM golang:1.21.1-bookworm AS reporter
WORKDIR /app/reporter
WORKDIR /app/tianji COPY ./reporter/ ./reporter/
RUN apt update
RUN cd reporter && go build .
# # Base ------------------------------
FROM node:20-alpine AS base
RUN npm install -g pnpm@8.3.1 RUN npm install -g pnpm@8.3.1
RUN apk add --update --no-cache python3 py3-pip g++ make
# Tianji frontend ------------------------------
FROM base AS docker-static
WORKDIR /app/tianji
COPY . . COPY . .
RUN apk add --update --no-cache python3 py3-pip g++ make
RUN pnpm install --frozen-lockfile RUN pnpm install --frozen-lockfile
RUN pnpm build RUN pnpm build:static
# Tianji server ------------------------------
FROM base AS docker-server
WORKDIR /app/tianji
COPY . .
RUN pnpm install --filter @tianji/server... --config.dedupe-peer-dependents=false
RUN mkdir -p ./src/server/public
RUN COPY --from=docker-static /app/tianji/src/server/public /app/tianji/src/server/public
RUN pnpm build:server
# make sure run after pnpm build completed to avoid break system packages
# Push client(only support pure text message)
RUN pip install apprise --break-system-packages RUN pip install apprise --break-system-packages
# remove unused source file
RUN rm -rf ./src/client RUN rm -rf ./src/client
RUN rm -rf ./website RUN rm -rf ./website
RUN rm -rf ./reporter RUN rm -rf ./reporter

View File

@ -11,6 +11,7 @@
"start:docker:db": "cd src/server && pnpm db:migrate:apply && pnpm db:migrate:script", "start:docker:db": "cd src/server && pnpm db:migrate:apply && pnpm db:migrate:script",
"test": "vitest", "test": "vitest",
"build": "pnpm build:tracker && pnpm build:app && pnpm build:geo", "build": "pnpm build:tracker && pnpm build:app && pnpm build:geo",
"build:static": "pnpm build:tracker && pnpm build:client && pnpm build:geo",
"build:app": "pnpm build:server && pnpm build:client", "build:app": "pnpm build:server && pnpm build:client",
"build:client": "cd src/client && pnpm build", "build:client": "cd src/client && pnpm build",
"build:server": "cd src/server && pnpm build", "build:server": "cd src/server && pnpm build",