Dockerfile更新 v2.1

pull/814/head
gsw945 2022-07-25 11:56:55 +08:00
parent b00536f927
commit 4d9fe06436
3 changed files with 59 additions and 99 deletions

View File

@ -36,30 +36,41 @@ FROM ubuntu:focal
# 切换默认shell为bash
SHELL ["/bin/bash", "-c"]
COPY --from=build /usr/share/fonts/win/simsun.ttc /usr/share/fonts/win/
COPY --from=build /go/src/github.com/mindoc-org/mindoc /mindoc
WORKDIR /mindoc
# 文件复制
COPY --from=build /usr/share/fonts/win/simsun.ttc /usr/share/fonts/win/
COPY --from=build /go/src/github.com/mindoc-org/mindoc/mindoc_linux_amd64 /mindoc/
COPY --from=build /go/src/github.com/mindoc-org/mindoc/start.sh /mindoc/
COPY --from=build /go/src/github.com/mindoc-org/mindoc/LICENSE.md /mindoc/
# 文件夹复制
COPY --from=build /go/src/github.com/mindoc-org/mindoc/lib /mindoc/lib
COPY --from=build /go/src/github.com/mindoc-org/mindoc/conf /mindoc/__default_assets__/conf
COPY --from=build /go/src/github.com/mindoc-org/mindoc/static /mindoc/__default_assets__/static
COPY --from=build /go/src/github.com/mindoc-org/mindoc/views /mindoc/__default_assets__/views
COPY --from=build /go/src/github.com/mindoc-org/mindoc/uploads /mindoc/__default_assets__/uploads
RUN chmod a+r /usr/share/fonts/win/simsun.ttc
# 备份原有源
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
# 更换aliyun源(echo多行内容不能以#开头会被docker误判为注释行所以采用\n#开头)
RUN echo $'\
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse'\
> /etc/apt/sources.list
# RUN mv /etc/apt/sources.list /etc/apt/sources.list-backup
# 最小化源缩短apt update时间(ca-certificates必须先安装才支持换aliyun源)
# 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
# # 更换aliyun源(echo多行内容不能以#开头会被docker误判为注释行所以采用\n#开头)
# RUN echo $'\
# deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\
# \n# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\
# deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\
# \n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\n\
# deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\
# \n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\n\
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\
# \n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\n\
# deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse\
# \n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse'\
# > /etc/apt/sources.list
# 更新软件包信息
RUN apt-get update
@ -88,6 +99,7 @@ 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
# 安装-calibre
# RUN apt-get install -y calibre # 此种方式安装省事,但会安装很多额外不需要的软件包,导致体积过大
RUN mkdir -p /tmp/calibre-cache
@ -114,23 +126,19 @@ RUN ebook-convert --version
RUN rm -rf /tmp/calibre-cache
# refer: https://docs.docker.com/engine/reference/builder/#volume
# 数据同步目录
VOLUME /mindoc-sync-host
VOLUME ["/mindoc/conf","/mindoc/static","/mindoc/views","/mindoc/uploads","/mindoc/runtime","/mindoc/database"]
# refer: https://docs.docker.com/engine/reference/builder/#expose
EXPOSE 8181/tcp
# 如果配置文件不存在就复制
RUN cp --no-clobber /mindoc/conf/app.conf.example /mindoc/conf/app.conf
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
RUN chmod +x /mindoc/start.sh
ENTRYPOINT ["/bin/bash", "/mindoc/start.sh"]
# 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 .
# docker build --progress plain --rm --build-arg TAG=2.1 --tag gsw945/mindoc:2.1 .
# https://docs.docker.com/engine/reference/commandline/run/#options
# 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
# docker run --rm -it -p 8181:8181 -v "%MINDOC%":"/mindoc-sync-host" --name mindoc -e MINDOC_ENABLE_EXPORT=true -d gsw945/mindoc:2.1

View File

@ -1,36 +1,31 @@
#!/bin/bash
set -eux
# 默认资源
if [ ! -d "/mindoc/conf" ]; then mkdir -p "/mindoc/conf" ; fi
if [[ -z "$(ls -A -- "/mindoc/conf")" ]] ; then cp -r "/mindoc/__default_assets__/conf" "/mindoc/" ; fi
if [ ! -d "/mindoc/static" ]; then mkdir -p "/mindoc/static" ; fi
if [[ -z "$(ls -A -- "/mindoc/static")" ]] ; then cp -r "/mindoc/__default_assets__/static" "/mindoc/" ; fi
if [ ! -d "/mindoc/views" ]; then mkdir -p "/mindoc/views" ; fi
if [[ -z "$(ls -A -- "/mindoc/views")" ]] ; then cp -r "/mindoc/__default_assets__/views" "/mindoc/" ; fi
if [ ! -d "/mindoc/uploads" ]; then mkdir -p "/mindoc/uploads" ; fi
if [[ -z "$(ls -A -- "/mindoc/uploads")" ]] ; then cp -r "/mindoc/__default_assets__/uploads" "/mindoc/" ; fi
# 如果配置文件不存在就复制
cp --no-clobber /mindoc/conf/app.conf.example /mindoc/conf/app.conf
# 数据库等初始化
/mindoc/mindoc_linux_amd64 install
# 导出同步检查
mkdir -p /mindoc-sync-host
if ! [ -f "/mindoc-sync-host/sync.sh" ]; then
# 同步方向: docker->HOST 或 HOST -> docker
# echo "export MINDOC_SYNC=" >> /mindoc-sync-host/sync.sh # 不同步
echo "export MINDOC_SYNC=docker2host" >> /mindoc-sync-host/sync.sh # 默认 docker->HOST
# 同步内容
# conf: 配置
# database: sqlite方式数据库
# runtime: 运行时数据(日志等)
# static: 静态文件
# uploads: 上传文件
# views: 页面视图
# echo "export SYNC_LIST='conf;database;runtime;static;uploads;views'" >> /mindoc-sync-host/sync.sh # 同步所有内容
# echo "export SYNC_LIST=" >> /mindoc-sync-host/sync.sh # 不同步任何内容
echo "export SYNC_LIST='conf;database;uploads'" >> /mindoc-sync-host/sync.sh # 同步conf、database、uploads
# 同步操作(sync/copy/sync --dry-run 等具体参考rclone文档host2docker务必谨慎操作)
# echo "export SYNC_ACTION=sync --dry-run" >> /mindoc-sync-host/sync.sh # 无操作且仅显示同步文件信息(--dry-run)
echo "export SYNC_ACTION=sync" >> /mindoc-sync-host/sync.sh # 默认同步
# 同步脚本
echo "source /mindoc/sync_host.sh" >> /mindoc-sync-host/sync.sh
fi
# 同步操作
source /mindoc-sync-host/sync.sh
# 运行
/mindoc/mindoc_linux_amd64
# # Debug Dockerfile
# while [ 1 ]
# do
# echo "log ..."
# sleep 5s
# done

View File

@ -1,43 +0,0 @@
#!/bin/bash
set -eux
if ! [ -x "$(command -v rclone)" ]; then
apt install rclone -y
else
whereis rclone
fi
export MINDOC_SYNC="${MINDOC_SYNC:=}"
export SYNC_LIST="${SYNC_LIST:=}"
export SYNC_ACTION="${SYNC_ACTION:=sync --dry-run}"
export HOST_DIR=/mindoc-sync-host
export DOCKER_DIR=/mindoc
function doSyncCopy() {
if [ -d "${1}" ]
then
rclone $SYNC_ACTION --progress --exclude .git* --exclude .git/** "${1}" "${2}"
fi
}
function doSync() {
case $MINDOC_SYNC in
"docker2host")
doSyncCopy "${DOCKER_DIR}/${1}" "${HOST_DIR}/${1}"
;;
"host2docker")
doSyncCopy "${HOST_DIR}/${1}" "${DOCKER_DIR}/${1}"
;;
*)
printenv | grep MINDOC_SYNC
;;
esac
}
export IFS=";"
if ! [ -z "${SYNC_LIST}" ]; then
for item in $SYNC_LIST; do
doSync "${item}"
done
fi