|
| 1 | +# === 阶段 1: Node.js 构建阶段 === |
| 2 | +# 修正:阶段名改为小写 |
| 3 | +FROM node:21 AS node_build |
| 4 | +WORKDIR /go/src/github.com/siyuan-note/siyuan/ |
| 5 | + |
| 6 | +# 1. 先安装基础工具 jq |
| 7 | +RUN { \ |
| 8 | + echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib"; \ |
| 9 | + echo "deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib"; \ |
| 10 | + echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main"; \ |
| 11 | + echo "deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main"; \ |
| 12 | + echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib"; \ |
| 13 | + echo "deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib"; \ |
| 14 | +} > /etc/apt/sources.list && \ |
| 15 | + apt-get update && \ |
| 16 | + apt-get install -y jq |
| 17 | + |
| 18 | +# 2. 先复制依赖描述文件 |
| 19 | +COPY app/package.json app/pnpm-lock.yaml ./app/ |
| 20 | + |
| 21 | +# 3. 安装依赖 (利用缓存) |
| 22 | +RUN cd app && \ |
| 23 | + packageManager=$(jq -r '.packageManager' package.json) && \ |
| 24 | + if [ -n "$packageManager" ]; then \ |
| 25 | + npm install -g $packageManager --registry=https://registry.npmmirror.com; \ |
| 26 | + else \ |
| 27 | + npm install -g pnpm --registry=https://registry.npmmirror.com; \ |
| 28 | + fi && \ |
| 29 | + pnpm config set registry https://registry.npmmirror.com && \ |
| 30 | + pnpm install --frozen-lockfile |
| 31 | + |
| 32 | +# 4. 复制源代码 |
| 33 | +ADD . /go/src/github.com/siyuan-note/siyuan/ |
| 34 | + |
| 35 | +# 5. 执行构建 |
| 36 | +RUN cd app && pnpm run build |
| 37 | + |
| 38 | +# 清理临时文件 |
| 39 | +RUN apt-get purge -y jq && \ |
| 40 | + apt-get autoremove -y && \ |
| 41 | + rm -rf /var/lib/apt/lists/* |
| 42 | + |
| 43 | +# === 阶段 2: Golang 构建阶段 === |
| 44 | +# 修正:阶段名改为小写 |
| 45 | +FROM golang:1.26.0-alpine AS go_build |
| 46 | +WORKDIR /go/src/github.com/siyuan-note/siyuan/ |
| 47 | +COPY --from=node_build /go/src/github.com/siyuan-note/siyuan/ /go/src/github.com/siyuan-note/siyuan/ |
| 48 | + |
| 49 | +# 使用阿里云 Alpine 镜像并编译 |
| 50 | +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ |
| 51 | + apk add --no-cache gcc musl-dev && \ |
| 52 | + cd kernel && \ |
| 53 | + go env -w GOPROXY=https://goproxy.cn,direct && \ |
| 54 | + go build --tags fts5 -v -ldflags "-s -w" && \ |
| 55 | + mkdir /opt/siyuan/ && \ |
| 56 | + mv /go/src/github.com/siyuan-note/siyuan/app/appearance/ /opt/siyuan/ && \ |
| 57 | + mv /go/src/github.com/siyuan-note/siyuan/app/stage/ /opt/siyuan/ && \ |
| 58 | + mv /go/src/github.com/siyuan-note/siyuan/app/guide/ /opt/siyuan/ && \ |
| 59 | + mv /go/src/github.com/siyuan-note/siyuan/app/changelogs/ /opt/siyuan/ && \ |
| 60 | + mv /go/src/github.com/siyuan-note/siyuan/kernel/kernel /opt/siyuan/ && \ |
| 61 | + mv /go/src/github.com/siyuan-note/siyuan/kernel/entrypoint.sh /opt/siyuan/entrypoint.sh && \ |
| 62 | + find /opt/siyuan/ -name .git | xargs rm -rf |
| 63 | + |
| 64 | +# === 阶段 3: 最终运行阶段 === |
| 65 | +FROM alpine:latest |
| 66 | +LABEL maintainer="Liang Ding<845765@qq.com>" |
| 67 | +LABEL modifier="ulquiola<ulquiola@163.com>" |
| 68 | +WORKDIR /opt/siyuan/ |
| 69 | +COPY --from=go_build /opt/siyuan/ /opt/siyuan/ |
| 70 | + |
| 71 | +# 配置时区和语言环境 |
| 72 | +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ |
| 73 | + apk add --no-cache ca-certificates tzdata && \ |
| 74 | + chmod +x /opt/siyuan/entrypoint.sh && \ |
| 75 | + echo "Asia/Shanghai" > /etc/timezone && \ |
| 76 | + ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
| 77 | + |
| 78 | +ENV TZ=Asia/Shanghai |
| 79 | +ENV RUN_IN_CONTAINER=true |
| 80 | +ENV LANG=zh_CN.UTF-8 |
| 81 | +ENV LC_ALL=zh_CN.UTF-8 |
| 82 | +EXPOSE 6806 |
| 83 | +VOLUME /siyuan/workspace |
| 84 | +ENTRYPOINT ["/opt/siyuan/entrypoint.sh"] |
| 85 | +CMD ["--workspace=/siyuan/workspace", "--accessAuthCode=password"] |
0 commit comments