👷 Docker supports data persistence, root permissions (#73)

👷 Docker 支持数据持久化、Root 权限 (#73)
This commit is contained in:
nevinen 2021-05-07 23:18:06 +08:00 committed by GitHub
parent 7f3aa6d5c0
commit 60292725e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 57 deletions

View File

@ -7,7 +7,8 @@ ARG WORK_DIR=/pagermaid/workdir
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
SHELL=/bin/bash \
LANG=zh_CN.UTF-8 \
PS1="\u@\h:\w \$ "
PS1="\u@\h:\w \$ " \
RUN_AS_ROOT=true
SHELL ["/bin/bash", "-c"]
WORKDIR $WORK_DIR
RUN source ~/.bashrc \
@ -46,6 +47,7 @@ RUN source ~/.bashrc \
&& apt-get install --no-install-recommends -y \
## 这是跨平台交叉编译要用到的包,如果自行构建,有可能不需要
build-essential \
apt-utils \
python3-dev \
libxslt1-dev \
libxml2-dev \
@ -89,6 +91,7 @@ RUN source ~/.bashrc \
## 卸载编译依赖,清理安装缓存
&& sudo apt-get purge --auto-remove -y \
build-essential \
apt-utils \
python3-dev \
libxslt1-dev \
libxml2-dev \

View File

@ -27,7 +27,7 @@ Pagermaid 是一个用在 Telegram 的实用工具。
[一键脚本](https://t.me/PagerMaid_Modify/58)
[Docker 脚本](https://t.me/PagerMaid_Modify/60)
[Docker安装](utils/docker.md)
# 对存在使用本项目用户群组的提醒

View File

@ -4,11 +4,12 @@ services:
image: mrwangzhe/pagermaid_modify
restart: always
container_name: pagermaid
hostname: "pagermaid"
#ports:
hostname: pagermaid
#ports: # 是否开启网页控制面板
#- "3333:3333"
volumes:
- ./:/pagermaid/workdir
environment:
- PUID=917
- PGID=917
- RUN_AS_ROOT=true # 是否以root权限运行pagermaidtrue为是
- PUID=917 # 当 RUN_AS_ROOT=false 才生效即以普通用户权限运行pagermaid
- PGID=917 # 当 RUN_AS_ROOT=false 才生效即以普通用户权限运行pagermaid

View File

@ -1,7 +1,8 @@
#!/usr/bin/with-contenv bash
PUID=${PUID:-917}
PGID=${PGID:-917}
groupmod -o -g "$PGID" pagermaid
usermod -o -u "$PUID" pagermaid
if [[ $RUN_AS_ROOT != true ]]; then
PUID=${PUID:-917}
PGID=${PGID:-917}
groupmod -o -g "$PGID" pagermaid
usermod -o -u "$PUID" pagermaid
fi

View File

@ -1,3 +1,5 @@
#!/usr/bin/with-contenv bash
chown -R pagermaid:pagermaid /pagermaid
if [[ $RUN_AS_ROOT != true ]]; then
chown -R pagermaid:pagermaid /pagermaid
fi

View File

@ -1,3 +1,7 @@
#!/usr/bin/with-contenv bash
exec s6-setuidgid pagermaid redis-server --daemonize yes
if [[ $RUN_AS_ROOT != true ]]; then
exec s6-setuidgid pagermaid redis-server --daemonize yes
else
redis-server --daemonize yes
fi

View File

@ -1,5 +1,9 @@
#!/usr/bin/with-contenv bash
cd /pagermaid/workdir
exec s6-setuidgid pagermaid python -m pagermaid
if [[ $RUN_AS_ROOT != true ]]; then
exec s6-setuidgid pagermaid python -m pagermaid
else
python -m pagermaid
fi

28
utils/docker.md Normal file
View File

@ -0,0 +1,28 @@
## 一、一键脚本
```
wget https://raw.githubusercontent.com/Xtao-Labs/PagerMaid-Modify/master/utils/docker.sh
bash docker.sh
```
*注一键脚本安装的Docker将以root权限运行在使用pagermaid时最方便。*
## docker-compose 安装
1. 准备脚本
```
git clone https://github.com/Xtao-Labs/PagerMaid-Modify pagermaid
cd pagermaid
cp config.gen.yml config.yml
cp docker-compose.gen.yml docker-compose.yml
```
2. 编辑刚刚复制的`docker-compose.yml`为你自己的信息,如不想解决权限问题,建议`RUN_AS_ROOT=true`。
3. 如果会配置,就自己编辑刚刚复制的`config.yml`。如果不会就直接下一步。
4. 启动容器`docker-compose up -d`。
5. 如第3步未配置`config.yml`,则运行`docker exec -it <容器名> bash utils/docker-config.sh`进行配置。

View File

@ -7,7 +7,7 @@ then
exit 1
fi
welcome() {
welcome () {
echo
echo "安装即将开始"
echo "如果您想取消安装,"
@ -29,7 +29,7 @@ docker_check () {
fi
}
access_check() {
access_check () {
echo "测试 Docker 环境 . . ."
if [ -w /var/run/docker.sock ]
then
@ -40,101 +40,159 @@ access_check() {
fi
}
build_docker() {
build_docker () {
printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1
printf "请输入你想以哪个用户运行pagermaid该用户的PUID值如不懂请直接回车"
read -r puid <&1
PUID=${puid-:917}
printf "请输入你想以哪个用户运行pagermaid该用户的PGID值如不懂请直接回车"
read -r pgid <&1
PGID=${pgid-:917}
echo "正在拉取 Docker 镜像 . . ."
docker rm -f "$container_name" > /dev/null 2>&1
docker pull mrwangzhe/pagermaid_modify
}
start_docker() {
start_docker () {
echo "正在启动 Docker 容器 . . ."
docker run -dit -e PUID=$PUID -e PGID=$PGID --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1
docker run -dit --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1
echo
echo "开始配置参数 . . ."
echo "在登录后,请按 Ctrl + C 使容器在后台模式下重新启动。"
sleep 3
docker exec -it -u pagermaid $container_name bash utils/docker-config.sh
docker exec -it $container_name bash utils/docker-config.sh
echo
echo "Docker 创建完毕。"
echo
shon_online
}
start_installation() {
data_persistence () {
echo "数据持久化可以在升级或重新部署容器时保留配置文件和插件。"
printf "请确认是否进行数据持久化操作 [Y/n] "
read -r persistence <&1
case $persistence in
[yY][eE][sS] | [yY])
printf "请输入将数据保留在宿主机哪个路径(绝对路径),同时请确保该路径下没有名为 workdir 的文件夹 "
read -r data_path <&1
if [ -d $data_path ]; then
if [[ -z $container_name ]]; then
printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1
fi
if docker inspect $container_name &>/dev/null; then
docker cp $container_name:/pagermaid/workdir $data_path
docker stop $container_name &>/dev/null
docker rm $container_name &>/dev/null
docker run -dit -e PUID=$PUID -e PGID=$PGID -v $data_path/workdir:/pagermaid/workdir --restart=always --name="$container_name" --hostname="$container_name" mrwangzhe/pagermaid_modify <&1
echo
echo "数据持久化操作完成。"
echo
shon_online
else
echo "不存在名为 $container_name 的容器,退出。"
exit 1
fi
else
echo "路径 $data_path 不存在,退出。"
exit 1
fi
;;
[nN][oO] | [nN])
echo "结束。"
;;
*)
echo "输入错误 . . ."
exit 1
;;
esac
}
start_installation () {
welcome
docker_check
access_check
build_docker
start_docker
data_persistence
}
cleanup(){
cleanup () {
printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1
echo "正在删除 Docker 镜像 . . ."
docker rm -f "$container_name" > /dev/null 2>&1
echo ""
shon_online
echo "开始删除 Docker 镜像 . . ."
if docker inspect $container_name &>/dev/null; then
docker rm -f "$container_name" &>/dev/null
echo
shon_online
else
echo "不存在名为 $container_name 的容器,退出。"
exit 1
fi
}
stop_pager(){
stop_pager () {
printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1
echo "正在关闭 Docker 镜像 . . ."
docker stop "$container_name" > /dev/null 2>&1
echo ""
shon_online
if docker inspect $container_name &>/dev/null; then
docker stop "$container_name" &>/dev/null
echo
shon_online
else
echo "不存在名为 $container_name 的容器,退出。"
exit 1
fi
}
start_pager(){
start_pager () {
printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1
echo "正在启动 Docker 容器 . . ."
docker start $container_name > /dev/null 2>&1
echo ""
echo "Docker 启动完毕。"
echo ""
shon_online
if docker inspect $container_name &>/dev/null; then
docker start $container_name &>/dev/null
echo
echo "Docker 启动完毕。"
echo
shon_online
else
echo "不存在名为 $container_name 的容器,退出。"
exit 1
fi
}
restart_pager(){
restart_pager () {
printf "请输入 PagerMaid 容器的名称:"
read -r container_name <&1
echo "正在重新启动 Docker 容器 . . ."
docker restart $container_name > /dev/null 2>&1
echo ""
echo "Docker 重新启动完毕。"
echo ""
shon_online
if docker inspect $container_name &>/dev/null; then
docker restart $container_name &>/dev/null
echo
echo "Docker 重新启动完毕。"
echo
shon_online
else
echo "不存在名为 $container_name 的容器,退出。"
exit 1
fi
}
reinstall_pager(){
reinstall_pager () {
cleanup
build_docker
start_docker
data_persistence
}
shon_online(){
shon_online () {
echo
echo "欢迎使用 PagerMaid-Modify Docker 一键安装脚本。"
echo
echo "请选择您需要进行的操作:"
echo " 1) Docker 安装 PagerMaid"
echo " 2) Docker 卸载 PagerMaid"
echo " 3) 关闭 PagerMaid"
echo " 4) 启动 PagerMaid"
echo " 5) 重新启动 PagerMaid"
echo " 6) 重新安装 PagerMaid"
echo " 7) 退出脚本"
echo " 3) Docker 关闭 PagerMaid"
echo " 4) Docker 启动 PagerMaid"
echo " 5) Docker 重启 PagerMaid"
echo " 6) Docker 重装 PagerMaid"
echo " 7) 将 PagerMaid 数据持久化"
echo " 8) 退出脚本"
echo
echo " Version0.3.0"
echo " Version0.3.1"
echo
echo -n "请输入编号: "
read N
@ -158,6 +216,9 @@ shon_online(){
reinstall_pager
;;
7)
data_persistence
;;
8)
exit 0
;;
*)