2021-04-24 21:19:18 +08:00
|
|
|
|
FROM amd64/golang:1.13 AS build
|
2017-04-30 22:13:12 +08:00
|
|
|
|
|
2021-06-29 14:24:52 +08:00
|
|
|
|
ARG TAG=0.0.1
|
|
|
|
|
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# 编译-环境变量
|
|
|
|
|
ENV GO111MODULE=on
|
|
|
|
|
ENV GOPROXY=https://goproxy.cn,direct
|
|
|
|
|
ENV CGO_ENABLED=1
|
|
|
|
|
ENV GOARCH=amd64
|
|
|
|
|
ENV GOOS=linux
|
2018-07-18 17:56:33 +08:00
|
|
|
|
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# 工作目录
|
2021-03-23 15:09:17 +08:00
|
|
|
|
ADD . /go/src/github.com/mindoc-org/mindoc
|
|
|
|
|
WORKDIR /go/src/github.com/mindoc-org/mindoc
|
2017-04-30 22:13:12 +08:00
|
|
|
|
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# 编译
|
|
|
|
|
RUN go env
|
|
|
|
|
RUN go mod tidy -v
|
2021-06-29 14:24:52 +08:00
|
|
|
|
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`'"
|
2021-04-24 21:19:18 +08:00
|
|
|
|
RUN cp conf/app.conf.example conf/app.conf
|
|
|
|
|
# 清理不需要的文件
|
2021-06-30 14:41:47 +08:00
|
|
|
|
RUN rm appveyor.yml docker-compose.yml Dockerfile .travis.yml .gitattributes .gitignore go.mod go.sum main.go README.md simsun.ttc start.sh conf/*.go
|
2021-04-24 21:19:18 +08:00
|
|
|
|
RUN rm -rf cache commands controllers converter .git .github graphics mail models routers utils
|
2018-07-12 18:38:29 +08:00
|
|
|
|
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# 测试编译的mindoc是否ok
|
2021-06-29 14:24:52 +08:00
|
|
|
|
RUN ./mindoc_linux_amd64 version
|
2021-04-24 21:19:18 +08:00
|
|
|
|
|
|
|
|
|
# 必要的文件复制
|
2018-07-26 17:50:52 +08:00
|
|
|
|
ADD simsun.ttc /usr/share/fonts/win/
|
2021-04-24 21:19:18 +08:00
|
|
|
|
ADD start.sh /go/src/github.com/mindoc-org/mindoc
|
2018-02-03 17:22:50 +08:00
|
|
|
|
|
2018-07-12 18:38:29 +08:00
|
|
|
|
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# Ubuntu 20.04
|
|
|
|
|
FROM ubuntu:focal
|
2018-07-12 18:38:29 +08:00
|
|
|
|
|
2021-06-29 14:24:52 +08:00
|
|
|
|
# 切换默认shell为bash
|
|
|
|
|
SHELL ["/bin/bash", "-c"]
|
|
|
|
|
|
2018-09-17 17:07:58 +08:00
|
|
|
|
COPY --from=build /usr/share/fonts/win/simsun.ttc /usr/share/fonts/win/
|
2021-03-23 15:09:17 +08:00
|
|
|
|
COPY --from=build /go/src/github.com/mindoc-org/mindoc /mindoc
|
2018-06-06 11:43:25 +08:00
|
|
|
|
WORKDIR /mindoc
|
2021-04-24 21:19:18 +08:00
|
|
|
|
RUN chmod a+r /usr/share/fonts/win/simsun.ttc
|
|
|
|
|
|
2021-10-11 18:15:50 +08:00
|
|
|
|
# # 备份原有源
|
|
|
|
|
# RUN mv /etc/apt/sources.list /etc/apt/sources.list-backup
|
|
|
|
|
# # 最小化源,缩短apt update时间(ca-certificates必须先安装才支持换tsinghua源)
|
|
|
|
|
# RUN echo 'deb http://archive.ubuntu.com/ubuntu/ focal main restricted' > /etc/apt/sources.list
|
|
|
|
|
# RUN apt-get update
|
|
|
|
|
# RUN apt install -y ca-certificates
|
|
|
|
|
# # 更换tsinghua源(echo多行内容不能以#开头,会被docker误判为注释行,所以采用\n#开头)
|
|
|
|
|
# RUN echo $'\
|
|
|
|
|
# \n# from: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/\n\
|
|
|
|
|
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse\
|
|
|
|
|
# \n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse\n\
|
|
|
|
|
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse\
|
|
|
|
|
# \n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse\n\
|
|
|
|
|
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse\
|
|
|
|
|
# \n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse\n\
|
|
|
|
|
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse\
|
|
|
|
|
# \n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse\
|
|
|
|
|
# \n# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse\
|
|
|
|
|
# \n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse'\
|
|
|
|
|
# > /etc/apt/sources.list
|
2021-06-29 14:24:52 +08:00
|
|
|
|
|
2021-06-27 13:43:11 +08:00
|
|
|
|
# 更新软件包信息
|
2021-04-24 21:19:18 +08:00
|
|
|
|
RUN apt-get update
|
2021-06-27 13:43:11 +08:00
|
|
|
|
# 安装必要的系统工具
|
|
|
|
|
RUN apt install -y apt-transport-https ca-certificates curl wget xz-utils
|
2021-07-06 15:19:55 +08:00
|
|
|
|
|
|
|
|
|
# 时区设置(如果不设置, calibre依赖的tzdata在安装过程中会要求选择时区)
|
|
|
|
|
ENV TZ=Asia/Shanghai
|
|
|
|
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
|
|
|
|
# tzdata的前端类型默认为readline(Shell情况下)或dialog(支持GUI的情况下)
|
|
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
# 安装时区信息
|
|
|
|
|
RUN apt install -y --no-install-recommends tzdata
|
|
|
|
|
# 重新配置tzdata软件包,使得时区设置生效
|
|
|
|
|
RUN dpkg-reconfigure --frontend noninteractive tzdata
|
|
|
|
|
|
2021-06-29 14:24:52 +08:00
|
|
|
|
# 安装 calibre 依赖的包
|
|
|
|
|
RUN apt install -y libgl-dev libnss3-dev libxcomposite-dev libxrandr-dev libxi-dev
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# 安装文泉驿字体
|
|
|
|
|
RUN apt install -y fonts-wqy-microhei fonts-wqy-zenhei
|
2021-06-27 13:43:11 +08:00
|
|
|
|
# 安装中文语言包
|
2021-06-29 14:24:52 +08:00
|
|
|
|
RUN apt-get install -y locales language-pack-zh-hans language-pack-zh-hans-base
|
2021-06-27 13:43:11 +08:00
|
|
|
|
# 设置默认编码
|
2021-06-29 14:24:52 +08:00
|
|
|
|
RUN locale-gen "zh_CN.UTF-8"
|
|
|
|
|
RUN update-locale LANG=zh_CN.UTF-8
|
|
|
|
|
ENV LANG=zh_CN.UTF-8
|
|
|
|
|
ENV LANGUAGE=zh_CN:en
|
|
|
|
|
ENV LC_ALL=zh_CN.UTF-8
|
2021-04-24 21:19:18 +08:00
|
|
|
|
# 安装-calibre
|
2021-06-29 14:24:52 +08:00
|
|
|
|
# RUN apt-get install -y calibre # 此种方式安装省事,但会安装很多额外不需要的软件包,导致体积过大
|
2021-06-27 13:43:11 +08:00
|
|
|
|
RUN mkdir -p /tmp/calibre-cache
|
|
|
|
|
# 获取最新版本号
|
|
|
|
|
RUN curl -s http://code.calibre-ebook.com/latest>/tmp/calibre-cache/version
|
|
|
|
|
# 下载最新版本
|
2021-06-30 14:41:47 +08:00
|
|
|
|
# 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
|
2021-07-06 15:23:40 +08:00
|
|
|
|
RUN wget -O /tmp/calibre-cache/calibre-x86_64.txz -c https://github.com/kovidgoyal/calibre/releases/download/v`cat /tmp/calibre-cache/version`/calibre-`cat /tmp/calibre-cache/version`-x86_64.txz
|
2021-06-29 14:24:52 +08:00
|
|
|
|
# 注: 调试阶段,下载alibre-5.22.1-x86_64.txz到本地(使用 python -m http.server),加速构建
|
2021-07-06 15:23:40 +08:00
|
|
|
|
# RUN wget -O /tmp/calibre-cache/calibre-x86_64.txz -c http://10.96.8.252:8000/calibre-5.22.1-x86_64.txz
|
2021-06-27 13:43:11 +08:00
|
|
|
|
# 解压
|
|
|
|
|
RUN mkdir -p /opt/calibre
|
|
|
|
|
# RUN tar --extract --file=/tmp/calibre-cache/calibre-x86_64.txz --directory /opt/calibre
|
|
|
|
|
RUN tar xJof /tmp/calibre-cache/calibre-x86_64.txz -C /opt/calibre
|
2021-06-29 14:24:52 +08:00
|
|
|
|
ENV PATH=$PATH:/opt/calibre
|
|
|
|
|
# 设置calibre相关环境变量
|
|
|
|
|
ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
|
|
|
|
|
ENV QT_QPA_PLATFORM='offscreen'
|
2021-06-27 13:43:11 +08:00
|
|
|
|
# 测试 calibre 可正常使用
|
2021-04-24 21:19:18 +08:00
|
|
|
|
RUN ebook-convert --version
|
2021-06-29 14:24:52 +08:00
|
|
|
|
# 清理calibre缓存
|
|
|
|
|
RUN rm -rf /tmp/calibre-cache
|
|
|
|
|
|
|
|
|
|
# refer: https://docs.docker.com/engine/reference/builder/#volume
|
2021-07-07 18:44:35 +08:00
|
|
|
|
# 数据同步目录
|
|
|
|
|
VOLUME /mindoc-sync-host
|
2021-06-29 14:24:52 +08:00
|
|
|
|
|
|
|
|
|
# refer: https://docs.docker.com/engine/reference/builder/#expose
|
|
|
|
|
EXPOSE 8181/tcp
|
|
|
|
|
|
2021-07-07 18:44:35 +08:00
|
|
|
|
# 如果配置文件不存在就复制
|
|
|
|
|
RUN cp --no-clobber /mindoc/conf/app.conf.example /mindoc/conf/app.conf
|
|
|
|
|
|
2018-06-27 15:10:01 +08:00
|
|
|
|
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
|
2021-07-01 15:52:00 +08:00
|
|
|
|
RUN chmod +x /mindoc/start.sh
|
2021-06-29 14:24:52 +08:00
|
|
|
|
|
2021-07-06 15:19:55 +08:00
|
|
|
|
ENTRYPOINT ["/bin/bash", "/mindoc/start.sh"]
|
2018-02-03 17:22:50 +08:00
|
|
|
|
|
2021-06-29 14:24:52 +08:00
|
|
|
|
# https://docs.docker.com/engine/reference/commandline/build/#options
|
|
|
|
|
# docker build --progress plain --rm --build-arg TAG=2.0.1 --tag gsw945/mindoc:2.0.1 .
|
|
|
|
|
# https://docs.docker.com/engine/reference/commandline/run/#options
|
2021-07-07 18:44:35 +08:00
|
|
|
|
# set MINDOC=//d/mindoc # windows
|
|
|
|
|
# export MINDOC=/home/ubuntu/mindoc-docker # linux
|
|
|
|
|
# docker run --rm -it -p 8181:8181 -v "%MINDOC%":"/mindoc-sync-host" --name mindoc -e MINDOC_ENABLE_EXPORT=true -d gsw945/mindoc:2.0.1
|