mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🧑💻 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
This commit is contained in:
parent
fae3323182
commit
986a2208c6
1 changed files with 45 additions and 37 deletions
82
Dockerfile
82
Dockerfile
|
|
@ -1,52 +1,60 @@
|
||||||
FROM node:21 AS NODE_BUILD
|
FROM --platform=$BUILDPLATFORM node:21 AS node-build
|
||||||
|
|
||||||
WORKDIR /go/src/github.com/siyuan-note/siyuan/
|
ARG NPM_REGISTRY=
|
||||||
ADD . /go/src/github.com/siyuan-note/siyuan/
|
|
||||||
RUN apt-get update && \
|
WORKDIR /app
|
||||||
apt-get install -y jq
|
ADD app/package.json app/pnpm* app/.npmrc .
|
||||||
RUN cd app && \
|
|
||||||
packageManager=$(jq -r '.packageManager' package.json) && \
|
RUN <<EORUN
|
||||||
if [ -n "$packageManager" ]; then \
|
#!/bin/bash -e
|
||||||
npm install -g $packageManager; \
|
corepack enable
|
||||||
else \
|
corepack install --global $(node -e 'console.log(require("./package.json").packageManager)')
|
||||||
echo "No packageManager field found in package.json"; \
|
npm config set registry ${NPM_REGISTRY}
|
||||||
npm install -g pnpm; \
|
pnpm install --silent
|
||||||
fi && \
|
EORUN
|
||||||
pnpm install --registry=http://registry.npmjs.org/ --silent && \
|
|
||||||
|
ADD app/ .
|
||||||
|
RUN <<EORUN
|
||||||
|
#!/bin/bash -e
|
||||||
pnpm run build
|
pnpm run build
|
||||||
RUN apt-get purge -y jq
|
mkdir /artifacts
|
||||||
RUN apt-get autoremove -y
|
mv appearance stage guide changelogs /artifacts/
|
||||||
RUN rm -rf /var/lib/apt/lists/*
|
EORUN
|
||||||
|
|
||||||
FROM golang:1.24-alpine AS GO_BUILD
|
FROM golang:1.24-alpine AS go-build
|
||||||
WORKDIR /go/src/github.com/siyuan-note/siyuan/
|
|
||||||
COPY --from=NODE_BUILD /go/src/github.com/siyuan-note/siyuan/ /go/src/github.com/siyuan-note/siyuan/
|
ARG GOPROXY=
|
||||||
ENV GO111MODULE=on
|
|
||||||
ENV CGO_ENABLED=1
|
RUN <<EORUN
|
||||||
RUN apk add --no-cache gcc musl-dev && \
|
#!/bin/sh -e
|
||||||
cd kernel && go build --tags fts5 -v -ldflags "-s -w" && \
|
apk add --no-cache gcc musl-dev
|
||||||
mkdir /opt/siyuan/ && \
|
go env -w GO111MODULE=on
|
||||||
mv /go/src/github.com/siyuan-note/siyuan/app/appearance/ /opt/siyuan/ && \
|
go env -w GOPROXY=${GOPROXY}
|
||||||
mv /go/src/github.com/siyuan-note/siyuan/app/stage/ /opt/siyuan/ && \
|
go env -w CGO_ENABLED=1
|
||||||
mv /go/src/github.com/siyuan-note/siyuan/app/guide/ /opt/siyuan/ && \
|
EORUN
|
||||||
mv /go/src/github.com/siyuan-note/siyuan/app/changelogs/ /opt/siyuan/ && \
|
|
||||||
mv /go/src/github.com/siyuan-note/siyuan/kernel/kernel /opt/siyuan/ && \
|
WORKDIR /kernel
|
||||||
mv /go/src/github.com/siyuan-note/siyuan/kernel/entrypoint.sh /opt/siyuan/entrypoint.sh && \
|
ADD kernel/go.* .
|
||||||
find /opt/siyuan/ -name .git | xargs rm -rf
|
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg \
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
ADD kernel/ .
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg \
|
||||||
|
go build --tags fts5 -v -ldflags "-s -w"
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
LABEL maintainer="Liang Ding<845765@qq.com>"
|
LABEL maintainer="Liang Ding<845765@qq.com>"
|
||||||
|
|
||||||
WORKDIR /opt/siyuan/
|
RUN apk add --no-cache ca-certificates tzdata su-exec
|
||||||
COPY --from=GO_BUILD /opt/siyuan/ /opt/siyuan/
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates tzdata su-exec && \
|
|
||||||
chmod +x /opt/siyuan/entrypoint.sh
|
|
||||||
|
|
||||||
ENV TZ=Asia/Shanghai
|
ENV TZ=Asia/Shanghai
|
||||||
ENV HOME=/home/siyuan
|
ENV HOME=/home/siyuan
|
||||||
ENV RUN_IN_CONTAINER=true
|
ENV RUN_IN_CONTAINER=true
|
||||||
EXPOSE 6806
|
EXPOSE 6806
|
||||||
|
|
||||||
|
WORKDIR /opt/siyuan/
|
||||||
|
COPY --from=go-build --chmod=755 /kernel/kernel /kernel/entrypoint.sh .
|
||||||
|
COPY --from=node-build /artifacts .
|
||||||
|
|
||||||
ENTRYPOINT ["/opt/siyuan/entrypoint.sh"]
|
ENTRYPOINT ["/opt/siyuan/entrypoint.sh"]
|
||||||
CMD ["/opt/siyuan/kernel"]
|
CMD ["/opt/siyuan/kernel"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue