Merge pull request #4 from bluezealot/master

追加了Docker编译相关的代码
dev
进击的皇虫 1 year ago committed by GitHub
commit 2d8618d6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,18 @@
name: Docker Image CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build --file docker/dockerfile --tag bluezealot/moredoc:Linux_ce_v1.0.0 "docker"

@ -0,0 +1,58 @@
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
schedule:
- cron: '24 4 * * *'
push:
branches: [ "master" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "master" ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: docker
file: docker/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/moredoc:Linux_ce_v1.1.0

@ -0,0 +1,19 @@
# 关于Docker
## 端口
docker 的-p参数目前向外暴露了8880端口。
## 文件
docker 的-v参数目前向外暴露了三个路径
- /home/moredoc/workspace/cache
- /home/moredoc/workspace/documents
- /home/moredoc/workspace/uploads
## 数据库链接地址
提供环境变量 MYSQL_CONNECTION 来设置
## docker run 命令启动例子
```
sudo docker run -it -p 18880:8880 -v /home/bluezealot/work/morebook/cache:/home/moredoc/workspace/cache -v /home/bluezealot/work/morebook/document:/home/moredoc/workspace/documents -v /home/bluezealot/work/morebook/uploads:/home/moredoc/workspace/uploads -e MYSQL_CONNECTION="root:password@tcp(10.50.30.59:32306)/moredoc_test?charset=utf8mb4&loc=Local&parseTime=true" bluezealot/moredoc:Linux_ce_v1.0.0
```

@ -0,0 +1,59 @@
FROM ubuntu:jammy-20230126
ARG uid=1001
ARG gid=1001
ARG basedir=workspace
ARG DEBIAN_FRONTEND=noninteractive
EXPOSE 8880
# install wget
# install libreoffice
# install mupdf
# install supervisor
# install all needed tools
RUN apt-get update \
&& apt-get install -y wget \
&& apt-get install -y python3 \
&& apt-get install -y libreoffice \
&& apt-get install -y mupdf mupdf-tools \
&& apt-get install -y supervisor \
&& apt-get install -y libopengl0 \
&& apt-get install -y xz-utils \
&& apt-get install -y unzip \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update \
&& apt-get install -y language-pack-zh-hans \
&& apt-get install -y language-pack-ja \
&& apt-get install -y chinese* \
&& apt-get install -y libreoffice-l10n-zh-cn libreoffice-help-zh-cn \
&& apt-get install -y libreoffice-help-ja \
&& rm -rf /var/lib/apt/lists/*
# install calibre
RUN wget -nv -O- https://download.calibre-ebook.com/linux-installer.py | python3 -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"
# Add non root user
RUN addgroup --gid $gid --system moredoc\
&& adduser --uid $uid --disabled-password --system --gid $gid moredoc
# change to moredoc user
USER moredoc
WORKDIR /home/moredoc
ENV VERSION ce_v1.1.0
# Get and Unpack Tomcat
RUN wget https://github.com/mnt-ltd/moredoc/releases/download/v1.1.0/moredoc_${VERSION}_linux_amd64.zip -O ~/moredoc_${VERSION}_linux_amd64.zip
RUN cd ~/ && \
mkdir $basedir && \
unzip -n ~/moredoc_${VERSION}_linux_amd64.zip -d $basedir/
COPY entrypoint.sh entrypoint.sh
USER root
RUN chmod 777 entrypoint.sh
RUN chmod -R 777 /home/moredoc
USER moredoc
RUN mkdir $basedir/cache
RUN mkdir $basedir/documents
RUN mkdir $basedir/uploads
VOLUME $basedir/cache
VOLUME $basedir/documents
VOLUME $basedir/uploads
ENTRYPOINT ["./entrypoint.sh"]
ENV MYSQL_CONNECTION=dummy
CMD $MYSQL_CONNECTION

@ -0,0 +1,36 @@
#!/bin/bash
log() {
local type="$1"; shift
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
}
moredoc_note() {
log Note "$@"
}
_main() {
cd ~
moredoc_note "Current path is:"
pwd
moredoc_note "Current folder contains:"
ls
if [ -f app.toml ]
then
moredoc_note "Start server"
exec ./workspace/moredoc serve
else
moredoc_note "Init server"
ESCAPED_ORIGIN=$(printf '%s\n' "root:root@tcp(localhost:3306)/moredoc?charset=utf8mb4&loc=Local&parseTime=true" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE=$(printf '%s\n' "${MYSQL_CONNECTION}" | sed -e 's/[\/&]/\\&/g')
sed "s/$ESCAPED_ORIGIN/$ESCAPED_REPLACE/g" ./workspace/app.example.toml > ./workspace/app.toml
ls ./workspace
moredoc_note "Init DB"
cd workspace/
./moredoc syncdb
moredoc_note "Start server"
exec ./moredoc serve
fi
}
_main "$@"
Loading…
Cancel
Save