Skip to content

Commit 8bfa298

Browse files
committed
Self-use adjustment 20260322
2 parents fe4523f + 5f3021f commit 8bfa298

17 files changed

Lines changed: 445 additions & 1827 deletions

File tree

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/node_modules
2+
.git
3+
.github
4+
.idea
5+
*.log
6+
dist
7+
build

.github/workflows/dockerimage.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Docker Image
1+
name: Release Docker Image By ulquiola
22

33
on:
44
workflow_dispatch:
@@ -9,12 +9,12 @@ on:
99
default: ''
1010
push:
1111
branches:
12-
- master
12+
- dev
1313

1414
# ref https://docs.github.com/zh/actions/learn-github-actions/variables
1515
env:
1616
package_json: "app/package.json"
17-
docker_hub_owner: "b3log"
17+
docker_hub_owner: "ulquiola"
1818
docker_hub_repo: "siyuan"
1919

2020
jobs:
@@ -70,8 +70,8 @@ jobs:
7070
- name: Build the Docker image use Workflow Dispatch inputs' version
7171
if: ${{ github.event_name == 'workflow_dispatch' && !github.event.inputs.image_tag == '' }}
7272
run: |
73-
docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v8 -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:latest -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:v${{ github.event.inputs.image_tag }} .
73+
docker buildx build --push --platform linux/amd64,linux/arm64 -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:latest -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:v${{ github.event.inputs.image_tag }} .
7474
- name: Build the Docker image use package_json version
7575
if: ${{ github.event_name == 'push' || github.event.inputs.image_tag == '' }}
7676
run: |
77-
docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v8 -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:latest -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:v${{ steps.version.outputs.value }} .
77+
docker buildx build --push --platform linux/amd64,linux/arm64 -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:latest -t ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:v${{ steps.version.outputs.value }} .

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,28 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/g
4141

4242
FROM alpine:latest
4343
LABEL maintainer="Liang Ding<845765@qq.com>"
44+
LABEL modifier="ulquiola<ulquiola@163.com>"
4445

4546
RUN apk add --no-cache ca-certificates tzdata su-exec
4647

4748
ENV TZ=Asia/Shanghai
4849
ENV HOME=/home/siyuan
4950
ENV RUN_IN_CONTAINER=true
51+
ENV LANG=zh_CN.UTF-8
52+
ENV LC_ALL=zh_CN.UTF-8
5053
EXPOSE 6806
5154

5255
WORKDIR /opt/siyuan/
56+
# 从 Go 构建阶段复制二进制文件和入口脚本,并直接设置权限
5357
COPY --from=go-build --chmod=755 /kernel/kernel /kernel/entrypoint.sh .
58+
# 从 Node 构建阶段复制 UI 资源
5459
COPY --from=node-build /artifacts .
5560

61+
# 显式声明一个用于持久化数据的卷
62+
VOLUME /siyuan/workspace
63+
64+
# 设置容器的入口点为启动脚本
5665
ENTRYPOINT ["/opt/siyuan/entrypoint.sh"]
57-
CMD ["/opt/siyuan/kernel"]
66+
# 设置默认传递给入口点的参数
67+
# 这些参数可以被 docker run 命令中的参数覆盖
68+
CMD ["--workspace=/siyuan/workspace", "--accessAuthCode=password"]

Dockerfile-local

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)