1
- FROM golang:1.11.4-alpine3.8 AS build
1
+ FROM amd64/ golang:1.13 AS build
2
2
3
- # 新增 GLIBC
4
- ENV GLIBC_VERSION "2.28-r0"
3
+ ARG TAG=0.0.1
5
4
6
- # Download and install glibc
7
- RUN apk add --update && \
8
- apk add --no-cache --upgrade \
9
- ca-certificates \
10
- gcc \
11
- g++ \
12
- make \
13
- curl \
14
- git
15
-
16
- RUN curl -Lo /etc/apk/keys/sgerrand.rsa.pub "https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub" && \
17
- curl -Lo /var/glibc.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" && \
18
- curl -Lo /var/glibc-bin.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" && \
19
- apk add /var/glibc-bin.apk /var/glibc.apk && \
20
- /usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \
21
- echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf
22
-
23
- # 掛載 calibre 最新3.x
24
-
25
- ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/opt/calibre/lib
26
- ENV PATH $PATH:/opt/calibre/bin
27
-
28
- RUN curl -Lo /var/linux-installer.py https://download.calibre-ebook.com/linux-installer.py
29
-
30
- # RUN mkdir -p /go/src/github.com/lifei6671/ && cd /go/src/github.com/lifei6671/ && git clone https://github.com/mindoc-org/mindoc.git && cd mindoc
5
+ # 编译-环境变量
6
+ ENV GO111MODULE=on
7
+ ENV GOPROXY=https://goproxy.cn,direct
8
+ ENV CGO_ENABLED=1
9
+ ENV GOARCH=amd64
10
+ ENV GOOS=linux
31
11
12
+ # 工作目录
32
13
ADD . /go/src/github.com/mindoc-org/mindoc
33
-
34
14
WORKDIR /go/src/github.com/mindoc-org/mindoc
35
15
36
- RUN go get -u github.com/golang/dep/cmd/dep && dep ensure && \
37
- CGO_ENABLE=1 go build -v -a -o mindoc_linux_amd64 -ldflags="-w -s -X main.VERSION=$TAG -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'" && \
38
- rm -rf commands controllers models modules routers tasks vendor docs search data utils graphics .git Godeps uploads/* .gitignore .travis.yml Dockerfile gide.yaml LICENSE main.go README.md conf/enumerate.go conf/mail.go install.lock simsun.ttc
16
+ # 编译
17
+ RUN go env
18
+ RUN go mod tidy -v
19
+ RUN go build -o mindoc_linux_amd64 -ldflags "-w -s -X 'main.VERSION=$TAG' -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'"
20
+ RUN cp conf/app.conf.example conf/app.conf
21
+ # 清理不需要的文件
22
+ RUN rm appveyor.yml docker-compose.yml Dockerfile .travis.yml .gitattributes .gitignore go.mod go.sum main.go README.md simsun.ttc start.sh
23
+ RUN rm -rf cache commands controllers converter .git .github graphics mail models routers utils
39
24
40
- ADD start.sh /go/src/github.com/mindoc-org/mindoc
41
- ADD simsun.ttc /usr/share/fonts/win/
42
-
43
- FROM alpine:latest
44
-
45
- LABEL maintainer=
"[email protected] "
46
-
47
- RUN apk add --update && \
48
- apk add --no-cache --upgrade \
49
- tzdata \
50
- mesa-gl \
51
- python \
52
- qt5-qtbase-x11 \
53
- xdg-utils \
54
- libxrender \
55
- libxcomposite \
56
- xz \
57
- imagemagick \
58
- imagemagick-dev \
59
- msttcorefonts-installer \
60
- fontconfig && \
61
- update-ms-fonts && \
62
- fc-cache -f
63
-
64
- COPY --from=build /var/glibc.apk .
65
- COPY --from=build /var/glibc-bin.apk .
66
- COPY --from=build /etc/apk/keys/sgerrand.rsa.pub /etc/apk/keys/sgerrand.rsa.pub
67
- COPY --from=build /var/linux-installer.py .
68
- COPY --from=build /usr/share/fonts/win/simsun.ttc /usr/share/fonts/win/
69
- COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
70
- COPY --from=build /go/src/github.com/mindoc-org/mindoc /mindoc
25
+ # 测试编译的mindoc是否ok
26
+ RUN ./mindoc_linux_amd64 version
71
27
72
- RUN apk add glibc-bin.apk glibc.apk && \
73
- /usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \
74
- echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf && \
75
- rm -rf glibc.apk glibc-bin.apk /var/cache/apk/* && \
76
- chmod a+r /usr/share/fonts/win/simsun.ttc
77
-
78
-
79
- ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/opt/calibre/lib
80
- ENV PATH $PATH:/opt/calibre/bin
28
+ # 必要的文件复制
29
+ ADD simsun.ttc /usr/share/fonts/win/
30
+ ADD start.sh /go/src/github.com/mindoc-org/mindoc
81
31
82
- RUN cat linux-installer.py | python -c "import sys; main=lambda x,y:sys.stderr.write('Download failed\n '); exec(sys.stdin.read()); main(install_dir='/opt', isolated=True)" && \
83
- rm -rf /tmp/* linux-installer.py
84
32
85
- WORKDIR /mindoc
33
+ # Ubuntu 20.04
34
+ FROM ubuntu:focal
86
35
36
+ # 切换默认shell为bash
37
+ SHELL ["/bin/bash" , "-c" ]
87
38
88
- # 时区设置
39
+ # 时区设置(如果不设置, calibre依赖的tzdata在安装过程中会要求选择时区)
89
40
ENV TZ=Asia/Shanghai
90
41
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
91
42
43
+ COPY --from=build /usr/share/fonts/win/simsun.ttc /usr/share/fonts/win/
44
+ COPY --from=build /go/src/github.com/mindoc-org/mindoc /mindoc
45
+ WORKDIR /mindoc
46
+ RUN chmod a+r /usr/share/fonts/win/simsun.ttc
47
+
48
+ # 备份原有源
49
+ RUN mv /etc/apt/sources.list /etc/apt/sources.list-backup
50
+ # 最小化源,缩短apt update时间(ca-certificates必须先安装才支持换tsinghua源)
51
+ RUN echo 'deb http://archive.ubuntu.com/ubuntu/ focal main restricted' > /etc/apt/sources.list
52
+ RUN apt-get update
53
+ RUN apt install -y ca-certificates
54
+ # 更换tsinghua源(echo多行内容不能以#开头,会被docker误判为注释行,所以采用\n#开头)
55
+ RUN echo $'\
56
+ \n # from: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/\n \
57
+ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse\
58
+ \n # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse\n \
59
+ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse\
60
+ \n # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse\n \
61
+ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse\
62
+ \n # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse\n \
63
+ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse\
64
+ \n # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse\
65
+ \n # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse\
66
+ \n # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse' \
67
+ > /etc/apt/sources.list
68
+
69
+ # 更新软件包信息
70
+ RUN apt-get update
71
+ # 安装必要的系统工具
72
+ RUN apt install -y apt-transport-https ca-certificates curl wget xz-utils
73
+ # 安装 calibre 依赖的包
74
+ RUN apt install -y libgl-dev libnss3-dev libxcomposite-dev libxrandr-dev libxi-dev
75
+ # 安装文泉驿字体
76
+ RUN apt install -y fonts-wqy-microhei fonts-wqy-zenhei
77
+ # 安装中文语言包
78
+ RUN apt-get install -y locales language-pack-zh-hans language-pack-zh-hans-base
79
+ # 设置默认编码
80
+ RUN locale-gen "zh_CN.UTF-8"
81
+ RUN update-locale LANG=zh_CN.UTF-8
82
+ ENV LANG=zh_CN.UTF-8
83
+ ENV LANGUAGE=zh_CN:en
84
+ ENV LC_ALL=zh_CN.UTF-8
85
+ # 安装-calibre
86
+ # RUN apt-get install -y calibre # 此种方式安装省事,但会安装很多额外不需要的软件包,导致体积过大
87
+ RUN mkdir -p /tmp/calibre-cache
88
+ # 获取最新版本号
89
+ RUN curl -s http://code.calibre-ebook.com/latest>/tmp/calibre-cache/version
90
+ # 下载最新版本
91
+ RUN wget -O /tmp/calibre-cache/calibre-x86_64.txz -c https://download.calibre-ebook.com/`cat /tmp/calibre-cache/version`/calibre-`cat /tmp/calibre-cache/version`-x86_64.txz
92
+ # 注: 调试阶段,下载alibre-5.22.1-x86_64.txz到本地(使用 python -m http.server),加速构建
93
+ # RUN wget -O /tmp/calibre-cache/calibre-x86_64.txz -c http://10.96.8.252:8000/calibre-5.22.1-x86_64.txz
94
+ # 解压
95
+ RUN mkdir -p /opt/calibre
96
+ # RUN tar --extract --file=/tmp/calibre-cache/calibre-x86_64.txz --directory /opt/calibre
97
+ RUN tar xJof /tmp/calibre-cache/calibre-x86_64.txz -C /opt/calibre
98
+ ENV PATH=$PATH:/opt/calibre
99
+ # 设置calibre相关环境变量
100
+ ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
101
+ ENV QT_QPA_PLATFORM='offscreen'
102
+ # 测试 calibre 可正常使用
103
+ RUN ebook-convert --version
104
+ # 清理calibre缓存
105
+ RUN rm -rf /tmp/calibre-cache
106
+
107
+ # refer: https://docs.docker.com/engine/reference/builder/#volume
108
+ VOLUME /mindoc
109
+
110
+ # refer: https://docs.docker.com/engine/reference/builder/#expose
111
+ EXPOSE 8181/tcp
112
+
92
113
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
93
- RUN chmod +x start.sh
114
+ RUN chmod +x ./start.sh
115
+
116
+ CMD ["bash" , "./start.sh" ]
94
117
95
- CMD ["./start.sh" ]
118
+ # https://docs.docker.com/engine/reference/commandline/build/#options
119
+ # docker build --progress plain --rm --build-arg TAG=2.0.1 --tag gsw945/mindoc:2.0.1 .
120
+ # https://docs.docker.com/engine/reference/commandline/run/#options
121
+ # docker run --rm -it -p 8181:8181 -v "mindoc-docker":"/mindoc" --name mindoc -e MINDOC_ENABLE_EXPORT=true -d gsw945/mindoc:2.0.1
0 commit comments