This commit is contained in:
colben 2022-07-03 15:55:01 +08:00
parent 0b00d1a272
commit 17339d3259
9 changed files with 229 additions and 5 deletions

93
cloudreve/ADD/ccmd Executable file
View File

@ -0,0 +1,93 @@
#!/bin/bash
##################################################
# Mount dir #
# - LOG_DIR #
# - DATA_DIR #
##################################################
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
PIDS=
GOT_SIGTERM=
LOG_DIR='/var/log/cloudreve'
DATA_DIR='/var/lib/cloudreve'
function Print {
local file=/dev/null
[ '-f' = "$1" ] && file=$2 && shift && shift
date +"[%F %T] $*" | tee -a $file
}
function Quit {
Print killing cloudreve ...
while :; do
pkill -f cloudreve && Print killing cloudreve ... || break
sleep 1
done
Print Container stopped.
test -n "$GOT_SIGTERM"
}
function ModifyConf {
[ -e $DATA_DIR/cloudreve.ini ] && return 0
Print Generate cloudreve.ini ...
cat > $DATA_DIR/cloudreve.ini <<-EOF
[System]
Debug = false
Mode = master
Listen = :80
SessionSecret = $(date +%F | sha256sum | cut -c -64)
HashIDSalt = $(date +%T | sha256sum | cut -c -64)
#[UnixSocket]
#Listen = /socket/cloudreve
[Database]
DBFile = $DATA_DIR/cloudreve.db
#Type = mysql
#Port = 3306
#User = cloudreve
#Password = Cloudreve_1234
#Host = 127.0.0.1
#Name = cloudreve
#TablePrefix = cd_
#Charset = utf8mb4
#[Redis]
#Server = 127.0.0.1:6379
#Password = 123456
#DB = 9
#[CORS]
#AllowOrigins = *
#AllowMethods = OPTIONS,GET,POST
#AllowHeaders = *
#AllowCredentials = false
EOF
}
function StartProc {
Print Start cloudreve ...
rm -f /socket/cloudreve
/opt/cloudreve -c $DATA_DIR/cloudreve.ini &>> $LOG_DIR/cloudreve.out &
PIDS="$PIDS $!"
}
function Main {
local pid=
ModifyConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done
done
}
# Start here
Main

View File

@ -0,0 +1,15 @@
# 部署 cloudreve
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```

View File

@ -0,0 +1,21 @@
version: "3.7"
services:
rsync:
image: harbor.colben.cn/general/cloudreve
container_name: cloudreve
restart: "on-failure"
stop_grace_period: 1m
ports:
- 80:80
volumes:
- type: bind
source: ./etc/cloudreve.conf
target: /etc/cloudreve.conf
- type: bind
source: ./cloudreve/log
target: /var/log/cloudreve
- type: bind
source: ./cloudreve/data
target: /var/lib/cloudreve

7
cloudreve/Dockerfile Normal file
View File

@ -0,0 +1,7 @@
ARG ARCH
FROM harbor.colben.cn/general/photon$ARCH:4
MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/
RUN mkdir -p /var/{log,lib}/cloudreve
CMD ["/opt/ccmd"]

13
cloudreve/README.md Normal file
View File

@ -0,0 +1,13 @@
# 构建 cloudreve 镜像
## 定制
- 安装 cloudreve
## 外挂目录和文件
- /etc/cloudreve/conf.ini: cloudreve 配置文件
- /var/log/cloudreve: cloudreve 日志目录
- /var/lib/cloudreve: cloudreve 本地存储目录
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 部署 cloudreve

76
cloudreve/cloudreve.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash
#=========================================
# Author : colben
#=========================================
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)"
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest"
if [ -t 0 ]; then
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
else
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
fi
function Quit {
local exitCode=$?
[ 0 -ne $exitCode ] && Error Failed to build or push image!
[ -z "${END:-}" ] && echo && Error Interrupted manually!
Print Succeeded to build and push image.
}
function YesOrNo {
Warn $*
local sw=
while :; do
read -p '(Yes/No/Quit) ' -n1 sw
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
[ -n "$sw" ] && echo
done
}
function Update {
Warn Preparing cloudreve ...
cd $ROOT_DIR/ADD
if [ -z "$ARCH" ]; then
tar zxf $(ls /release/RUNTIME/cloudreve_*_linux_amd64.tar.gz|tail -1)
elif [ 'aarch64' == "$ARCH" ]; then
tar zxf $(ls /release/RUNTIME/cloudreve_*_linux_arm64.tar.gz|tail -1)
else
Error Not supported arch: $ARCH!
fi
chmod 0755 cloudreve
}
function Build {
local yn
cd $ROOT_DIR
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
&& Warn Removing image $IMAGE ... \
&& docker rmi $IMAGE
Warn Building image: $IMAGE ...
docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE .
YesOrNo Push image: $IMAGE? && docker push $IMAGE
}
function Main {
Update
Build
END=1
}
# Start here
Main

View File

@ -5,19 +5,19 @@ ARG ARCH
ADD --chown=root:root /ADD/ /opt/
RUN echo -e "[mysql-connectors-community]\n\
name=MySQL Connectors Community\n\
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el8$ARCH/\n\
baseurl=https://mirrors.nju.edu.cn/mysql/yum/mysql-connectors-community-el8$ARCH/\n\
enabled=1\n\
gpgcheck=0\n\
\n\
[mysql-tools-community]\n\
name=MySQL Tools Community\n\
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el8$ARCH/\n\
baseurl=https://mirrors.nju.edu.cn/mysql/yum/mysql-tools-community-el8$ARCH/\n\
enabled=1\n\
gpgcheck=0\n\
\n\
[mysql80-community]\n\
name=MySQL 8.0 Community Server\n\
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el8${ARCH:--x86_64}/\n\
baseurl=https://mirrors.nju.edu.cn/mysql/yum/mysql-8.0-community-el8${ARCH:--x86_64}/\n\
enabled=1\n\
gpgcheck=0\n\
" > /etc/yum.repos.d/mysql-8.0.repo \

View File

@ -3,7 +3,6 @@ FROM harbor.colben.cn/general/jdk$ARCH:8
MAINTAINER Colben colbenlee@gmail.com
RUN tdnf makecache \
&& tdnf -y install git openssh openssh-clients openssh-server sshpass jq ansible \
&& echo 'root:Ops_1234' | chpasswd \
&& mkdir -m 0700 /root/.ssh \
&& sed -i \
-e '/^Port /d' \

View File

@ -2,6 +2,6 @@ ARG ARCH
FROM harbor.colben.cn/general/rocky$ARCH:8
MAINTAINER Colben colbenlee@gmail.com
RUN dnf makecache \
&& dnf install gcc python39-devel mysql-devel -y \
&& dnf install gcc gcc-c++ make cmake python39-devel mysql-devel -y \
&& rm -rf /var/cache/dnf