Skip to content

Commit a19f32e

Browse files
committed
修复Dockerfile-local 的bug
1 parent 8bfa298 commit a19f32e

1 file changed

Lines changed: 93 additions & 85 deletions

File tree

Dockerfile-local

Lines changed: 93 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,93 @@
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"]
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+
mkdir -p /artifacts && \
38+
mv appearance stage guide changelogs /artifacts/
39+
40+
# 清理临时文件
41+
RUN apt-get purge -y jq && \
42+
apt-get autoremove -y && \
43+
rm -rf /var/lib/apt/lists/*
44+
45+
# === 阶段 2: Golang 构建阶段 ===
46+
FROM golang:1.26.0-alpine AS go_build
47+
WORKDIR /kernel
48+
49+
# 复制 Go 依赖文件
50+
COPY kernel/go.* /kernel/
51+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
52+
apk add --no-cache gcc musl-dev && \
53+
go env -w GOPROXY=https://goproxy.cn,direct && \
54+
go mod download
55+
56+
# 复制 kernel 源代码
57+
COPY kernel/ /kernel/
58+
59+
# 转换 entrypoint.sh 的行结束符(从 CRLF 转为 LF)
60+
RUN sed -i 's/\r$//' /kernel/entrypoint.sh
61+
62+
# 编译 kernel
63+
RUN go build --tags fts5 -v -ldflags "-s -w"
64+
65+
# === 阶段 3: 最终运行阶段 ===
66+
FROM alpine:latest
67+
LABEL maintainer="Liang Ding<845765@qq.com>"
68+
LABEL modifier="ulquiola<ulquiola@163.com>"
69+
70+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
71+
apk add --no-cache ca-certificates tzdata
72+
73+
ENV TZ=Asia/Shanghai
74+
ENV RUN_IN_CONTAINER=true
75+
ENV LANG=zh_CN.UTF-8
76+
ENV LC_ALL=zh_CN.UTF-8
77+
EXPOSE 6806
78+
79+
WORKDIR /opt/siyuan/
80+
81+
# 从 Go 构建阶段复制二进制文件和入口脚本,并直接设置权限
82+
COPY --from=go_build --chmod=755 /kernel/kernel .
83+
COPY --from=go_build --chmod=755 /kernel/entrypoint.sh .
84+
85+
# 从 Node 构建阶段复制 UI 资源
86+
COPY --from=node_build /artifacts .
87+
88+
# 显式声明一个用于持久化数据的卷
89+
VOLUME /siyuan/workspace
90+
91+
# 设置容器的入口点为启动脚本
92+
ENTRYPOINT ["/opt/siyuan/entrypoint.sh"]
93+
CMD ["--workspace=/siyuan/workspace", "--accessAuthCode=password"]

0 commit comments

Comments
 (0)