A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)

:technologist: Optimize Dockerfile to maximize cache utilization and parallelism (#16052)

* Optimize Dockerfile to maximize cache utilization and parallelism, and add ARG to control mirrors

* Add missing ".npmrc" before create pnpm dependencies

* Fix Dockerfile to correctly add ".npmrc" from the app directory

authored by San Dockerfile and committed by GitHub 986a2208 fae33231

Changed files
+45 -37
+45 -37
Dockerfile
··· 1 - FROM node:21 AS NODE_BUILD 1 + FROM --platform=$BUILDPLATFORM node:21 AS node-build 2 + 3 + ARG NPM_REGISTRY= 4 + 5 + WORKDIR /app 6 + ADD app/package.json app/pnpm* app/.npmrc . 7 + 8 + RUN <<EORUN 9 + #!/bin/bash -e 10 + corepack enable 11 + corepack install --global $(node -e 'console.log(require("./package.json").packageManager)') 12 + npm config set registry ${NPM_REGISTRY} 13 + pnpm install --silent 14 + EORUN 2 15 3 - WORKDIR /go/src/github.com/siyuan-note/siyuan/ 4 - ADD . /go/src/github.com/siyuan-note/siyuan/ 5 - RUN apt-get update && \ 6 - apt-get install -y jq 7 - RUN cd app && \ 8 - packageManager=$(jq -r '.packageManager' package.json) && \ 9 - if [ -n "$packageManager" ]; then \ 10 - npm install -g $packageManager; \ 11 - else \ 12 - echo "No packageManager field found in package.json"; \ 13 - npm install -g pnpm; \ 14 - fi && \ 15 - pnpm install --registry=http://registry.npmjs.org/ --silent && \ 16 + ADD app/ . 17 + RUN <<EORUN 18 + #!/bin/bash -e 16 19 pnpm run build 17 - RUN apt-get purge -y jq 18 - RUN apt-get autoremove -y 19 - RUN rm -rf /var/lib/apt/lists/* 20 + mkdir /artifacts 21 + mv appearance stage guide changelogs /artifacts/ 22 + EORUN 20 23 21 - FROM golang:1.24-alpine AS GO_BUILD 22 - WORKDIR /go/src/github.com/siyuan-note/siyuan/ 23 - COPY --from=NODE_BUILD /go/src/github.com/siyuan-note/siyuan/ /go/src/github.com/siyuan-note/siyuan/ 24 - ENV GO111MODULE=on 25 - ENV CGO_ENABLED=1 26 - RUN apk add --no-cache gcc musl-dev && \ 27 - cd kernel && go build --tags fts5 -v -ldflags "-s -w" && \ 28 - mkdir /opt/siyuan/ && \ 29 - mv /go/src/github.com/siyuan-note/siyuan/app/appearance/ /opt/siyuan/ && \ 30 - mv /go/src/github.com/siyuan-note/siyuan/app/stage/ /opt/siyuan/ && \ 31 - mv /go/src/github.com/siyuan-note/siyuan/app/guide/ /opt/siyuan/ && \ 32 - mv /go/src/github.com/siyuan-note/siyuan/app/changelogs/ /opt/siyuan/ && \ 33 - mv /go/src/github.com/siyuan-note/siyuan/kernel/kernel /opt/siyuan/ && \ 34 - mv /go/src/github.com/siyuan-note/siyuan/kernel/entrypoint.sh /opt/siyuan/entrypoint.sh && \ 35 - find /opt/siyuan/ -name .git | xargs rm -rf 24 + FROM golang:1.24-alpine AS go-build 25 + 26 + ARG GOPROXY= 27 + 28 + RUN <<EORUN 29 + #!/bin/sh -e 30 + apk add --no-cache gcc musl-dev 31 + go env -w GO111MODULE=on 32 + go env -w GOPROXY=${GOPROXY} 33 + go env -w CGO_ENABLED=1 34 + EORUN 35 + 36 + WORKDIR /kernel 37 + ADD kernel/go.* . 38 + RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg \ 39 + go mod download 40 + 41 + ADD kernel/ . 42 + RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg \ 43 + go build --tags fts5 -v -ldflags "-s -w" 36 44 37 45 FROM alpine:latest 38 46 LABEL maintainer="Liang Ding<845765@qq.com>" 39 47 40 - WORKDIR /opt/siyuan/ 41 - COPY --from=GO_BUILD /opt/siyuan/ /opt/siyuan/ 42 - 43 - RUN apk add --no-cache ca-certificates tzdata su-exec && \ 44 - chmod +x /opt/siyuan/entrypoint.sh 48 + RUN apk add --no-cache ca-certificates tzdata su-exec 45 49 46 50 ENV TZ=Asia/Shanghai 47 51 ENV HOME=/home/siyuan 48 52 ENV RUN_IN_CONTAINER=true 49 53 EXPOSE 6806 54 + 55 + WORKDIR /opt/siyuan/ 56 + COPY --from=go-build --chmod=755 /kernel/kernel /kernel/entrypoint.sh . 57 + COPY --from=node-build /artifacts . 50 58 51 59 ENTRYPOINT ["/opt/siyuan/entrypoint.sh"] 52 60 CMD ["/opt/siyuan/kernel"]