From ebc91d95317418241a01cf580c423947559f593c Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Fri, 8 Mar 2024 03:06:38 +0800 Subject: [PATCH] chore: update docker file to multi stage builds --- Dockerfile | 37 +++++++++++++++++++++++++++++-------- package.json | 1 + 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index ffda760..8ca8477 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 apk add --update --no-cache python3 py3-pip g++ make + +# Tianji frontend ------------------------------ +FROM base AS docker-static +WORKDIR /app/tianji COPY . . -RUN apk add --update --no-cache python3 py3-pip g++ make - 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 -# remove unused source file RUN rm -rf ./src/client RUN rm -rf ./website RUN rm -rf ./reporter diff --git a/package.json b/package.json index 476fb69..68be13c 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "start:docker:db": "cd src/server && pnpm db:migrate:apply && pnpm db:migrate:script", "test": "vitest", "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:client": "cd src/client && pnpm build", "build:server": "cd src/server && pnpm build",