-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (46 loc) · 1.76 KB
/
Dockerfile
File metadata and controls
63 lines (46 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 构建阶段
FROM golang:1.26.0-alpine3.23 AS builder
# 操作系统(linux/darwin/windows,默认linux)
ARG OS=linux
# 架构(amd64/arm64,默认amd64)
ARG ARCH=amd64
# 安装编译依赖
RUN apk add --no-cache gcc g++ unzip
# 设置工作目录
WORKDIR /app
# 设置国内代理
#RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
RUN go env -w GOPROXY=https://goproxy.cn,direct
# 复制项目代码
COPY . .
# 编译项目
RUN go build --tags "fts5" -ldflags "-w -s" -o gpress
# 初始化文件
RUN rm -rf /app/gpressdatadir/dict && \
unzip /app/gpressdatadir/dict.zip -d /app/gpressdatadir && \
rm -rf /app/gpressdatadir/dict.zip && \
mv /app/gpressdatadir/fts5 /app/gpressdatadir/fts && \
rm -rf /app/gpressdatadir/fts5 && \
mkdir -p /app/gpressdatadir/fts5 && \
if [ "${OS}" = "windows" ]; then mv /app/gpressdatadir/fts/libsimple.dll /app/gpressdatadir/fts5/libsimple.dll ; \
elif [ "${OS}" = "darwin" ]; then mv /app/gpressdatadir/fts/libsimple.dylib /app/gpressdatadir/fts5/libsimple.dylib ; \
elif [ "${ARCH}" = "arm64" ]; then mv /app/gpressdatadir/fts/libsimple.so-aarch64 /app/gpressdatadir/fts5/libsimple.so ; \
elif [ "${OS}" = "linux" ]; then mv /app/gpressdatadir/fts/libsimple.so /app/gpressdatadir/fts5/libsimple.so ; \
else echo "Unsupported OS: ${OS}" && exit 1; fi && \
rm -rf /app/gpressdatadir/fts
# 运行阶段
FROM alpine:3.23.3
# 安装运行时依赖
RUN apk add --no-cache libgcc libstdc++ sqlite-libs
# 设置工作目录
WORKDIR /app
RUN mkdir -p ./gpressdatadir
# 复制编译产物
COPY --from=builder /app/gpress .
COPY --from=builder /app/gpressdatadir ./gpressdatadir/
# 暴露端口
EXPOSE 660
# 设置数据卷
VOLUME ["/app/gpressdatadir"]
# 启动命令
CMD ["./gpress"]