Dockerfile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. FROM golang:bookworm AS build
  2. ARG TAG=0.0.1
  3. # 编译-环境变量
  4. ENV GO111MODULE=on
  5. ENV GOPROXY=https://goproxy.cn,direct
  6. ENV CGO_ENABLED=1
  7. ENV GOARCH=amd64
  8. ENV GOOS=linux
  9. # 工作目录
  10. ADD . /go/src/github.com/mindoc-org/mindoc
  11. WORKDIR /go/src/github.com/mindoc-org/mindoc
  12. # 编译
  13. RUN go env
  14. RUN go mod tidy -v
  15. RUN go build -v -o mindoc_linux_amd64 -ldflags "-w -s -X 'main.VERSION=$TAG' -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'"
  16. RUN cp conf/app.conf.example conf/app.conf
  17. # 清理不需要的文件
  18. 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
  19. RUN rm -rf cache commands controllers converter .git .github graphics mail models routers utils
  20. # 测试编译的mindoc是否ok
  21. RUN ./mindoc_linux_amd64 version
  22. # 必要的文件复制
  23. ADD simsun.ttc /usr/share/fonts/win/
  24. ADD start.sh /go/src/github.com/mindoc-org/mindoc
  25. # upgrade to the latest
  26. FROM ubuntu:latest
  27. # 切换默认shell为bash
  28. SHELL ["/bin/bash", "-c"]
  29. WORKDIR /mindoc
  30. # 文件复制
  31. COPY --from=build /usr/share/fonts/win/simsun.ttc /usr/share/fonts/win/
  32. COPY --from=build /go/src/github.com/mindoc-org/mindoc/mindoc_linux_amd64 /mindoc/
  33. COPY --from=build /go/src/github.com/mindoc-org/mindoc/start.sh /mindoc/
  34. COPY --from=build /go/src/github.com/mindoc-org/mindoc/LICENSE.md /mindoc/
  35. # 文件夹复制
  36. COPY --from=build /go/src/github.com/mindoc-org/mindoc/lib /mindoc/lib
  37. COPY --from=build /go/src/github.com/mindoc-org/mindoc/conf /mindoc/__default_assets__/conf
  38. COPY --from=build /go/src/github.com/mindoc-org/mindoc/static /mindoc/__default_assets__/static
  39. COPY --from=build /go/src/github.com/mindoc-org/mindoc/views /mindoc/__default_assets__/views
  40. COPY --from=build /go/src/github.com/mindoc-org/mindoc/uploads /mindoc/__default_assets__/uploads
  41. RUN chmod a+r /usr/share/fonts/win/simsun.ttc
  42. RUN sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list /etc/apt/sources.list.d/*
  43. # 更新软件包信息
  44. RUN apt-get update
  45. # 时区设置(如果不设置, calibre依赖的tzdata在安装过程中会要求选择时区)
  46. ENV TZ=Asia/Shanghai
  47. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  48. # tzdata的前端类型默认为readline(Shell情况下)或dialog(支持GUI的情况下)
  49. ARG DEBIAN_FRONTEND=noninteractive
  50. # 安装时区信息
  51. RUN apt install -y --no-install-recommends tzdata
  52. # 重新配置tzdata软件包,使得时区设置生效
  53. RUN dpkg-reconfigure --frontend noninteractive tzdata
  54. # 安装文泉驿字体
  55. # 安装中文语言包
  56. RUN apt install -y fonts-wqy-microhei fonts-wqy-zenhei locales language-pack-zh-hans-base
  57. # 设置默认编码
  58. RUN locale-gen "zh_CN.UTF-8"
  59. RUN update-locale LANG=zh_CN.UTF-8
  60. ENV LANG=zh_CN.UTF-8
  61. ENV LANGUAGE=zh_CN:en
  62. ENV LC_ALL=zh_CN.UTF-8
  63. # 安装必要依赖、下载、解压 calibre 并清理缓存
  64. RUN apt-get install -y --no-install-recommends \
  65. libglx0 libegl1 libnss3 libxcomposite1 libxkbcommon0 libxdamage1 libxrandr-dev libopengl0 libxtst6 libasound2t64 libxkbfile1\
  66. wget xz-utils && \
  67. mkdir -p /tmp/calibre-cache /opt/calibre && \
  68. wget -O /tmp/calibre-cache/calibre-x86_64.txz -c https://download.calibre-ebook.com/7.26.0/calibre-7.26.0-x86_64.txz --no-check-certificate && \
  69. tar xJof /tmp/calibre-cache/calibre-x86_64.txz -C /opt/calibre && \
  70. rm -rf /tmp/calibre-cache && \
  71. apt-get clean && rm -rf /var/lib/apt/lists/*
  72. # 设置环境变量
  73. ENV PATH="/opt/calibre:$PATH" \
  74. QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox" \
  75. QT_QPA_PLATFORM="offscreen"
  76. # 测试 calibre 是否可正常使用
  77. RUN ebook-convert --version
  78. # refer: https://docs.docker.com/engine/reference/builder/#volume
  79. VOLUME ["/mindoc/conf","/mindoc/static","/mindoc/views","/mindoc/uploads","/mindoc/runtime","/mindoc/database"]
  80. # refer: https://docs.docker.com/engine/reference/builder/#expose
  81. EXPOSE 8181/tcp
  82. ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
  83. RUN chmod +x /mindoc/start.sh
  84. ENTRYPOINT ["/bin/bash", "/mindoc/start.sh"]
  85. # https://docs.docker.com/engine/reference/commandline/build/#options
  86. # docker build --progress plain --rm --build-arg TAG=2.1 --tag gsw945/mindoc:2.1 .
  87. # https://docs.docker.com/engine/reference/commandline/run/#options
  88. # set MINDOC=//d/mindoc # windows
  89. # export MINDOC=/home/ubuntu/mindoc-docker # linux
  90. # docker run -d --name=mindoc --restart=always -v /www/mindoc/uploads:/mindoc/uploads -v /www/mindoc/database:/mindoc/database -v /www/mindoc/conf:/mindoc/conf -e MINDOC_DB_ADAPTER=sqlite3 -e MINDOC_DB_DATABASE=./database/mindoc.db -e MINDOC_CACHE=true -e MINDOC_CACHE_PROVIDER=file -p 8181:8181 mindoc-org/mindoc:v2.1