nas-tools older version 2.9.1

This commit is contained in:
RookieTerry 2023-03-28 21:42:38 +08:00 committed by GitHub
parent 6eb79120ee
commit 79b88d8c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 342 additions and 0 deletions

41
nas-tools/Dockerfile Normal file
View File

@ -0,0 +1,41 @@
FROM alpine
RUN apk add --no-cache libffi-dev \
&& apk add --no-cache $(echo $(wget --no-check-certificate -qO- https://raw.githubusercontent.com/jxxghp/nas-tools/master/package_list.txt)) \
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& curl https://rclone.org/install.sh | bash \
&& if [ "$(uname -m)" = "x86_64" ]; then ARCH=amd64; elif [ "$(uname -m)" = "aarch64" ]; then ARCH=arm64; fi \
&& curl https://dl.min.io/client/mc/release/linux-${ARCH}/mc --create-dirs -o /usr/bin/mc \
&& chmod +x /usr/bin/mc \
&& pip install --upgrade pip setuptools wheel \
&& pip install cython \
&& pip install -r https://raw.githubusercontent.com/jxxghp/nas-tools/master/requirements.txt \
&& apk del libffi-dev \
&& npm install pm2 -g \
&& rm -rf /tmp/* /root/.cache /var/cache/apk/*
ENV LANG="C.UTF-8" \
TZ="Asia/Shanghai" \
NASTOOL_CONFIG="/config/config.yaml" \
NASTOOL_AUTO_UPDATE=true \
NASTOOL_CN_UPDATE=true \
NASTOOL_VERSION=master \
PS1="\u@\h:\w \$ " \
REPO_URL="https://github.com/jxxghp/nas-tools.git" \
PYPI_MIRROR="https://pypi.tuna.tsinghua.edu.cn/simple" \
ALPINE_MIRROR="mirrors.ustc.edu.cn" \
PUID=0 \
PGID=0 \
UMASK=000 \
WORKDIR="/nas-tools"
WORKDIR ${WORKDIR}
RUN python_ver=$(python3 -V | awk '{print $2}') \
&& echo "${WORKDIR}/" > /usr/lib/python${python_ver%.*}/site-packages/nas-tools.pth \
&& echo 'fs.inotify.max_user_watches=524288' >> /etc/sysctl.conf \
&& echo 'fs.inotify.max_user_instances=524288' >> /etc/sysctl.conf \
&& git config --global pull.ff only \
&& git clone -b master ${REPO_URL} ${WORKDIR} --depth=1 --recurse-submodule \
&& git config --global --add safe.directory ${WORKDIR}
EXPOSE 3000
VOLUME ["/config"]
ENTRYPOINT ["/nas-tools/docker/entrypoint.sh"]

41
nas-tools/Dockerfile.beta Normal file
View File

@ -0,0 +1,41 @@
FROM alpine
RUN apk add --no-cache libffi-dev \
&& apk add --no-cache $(echo $(wget --no-check-certificate -qO- https://raw.githubusercontent.com/jxxghp/nas-tools/dev/package_list.txt)) \
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& curl https://rclone.org/install.sh | bash \
&& if [ "$(uname -m)" = "x86_64" ]; then ARCH=amd64; elif [ "$(uname -m)" = "aarch64" ]; then ARCH=arm64; fi \
&& curl https://dl.min.io/client/mc/release/linux-${ARCH}/mc --create-dirs -o /usr/bin/mc \
&& chmod +x /usr/bin/mc \
&& pip install --upgrade pip setuptools wheel \
&& pip install cython \
&& pip install -r https://raw.githubusercontent.com/jxxghp/nas-tools/dev/requirements.txt \
&& apk del libffi-dev \
&& npm install pm2 -g \
&& rm -rf /tmp/* /root/.cache /var/cache/apk/*
ENV LANG="C.UTF-8" \
TZ="Asia/Shanghai" \
NASTOOL_CONFIG="/config/config.yaml" \
NASTOOL_AUTO_UPDATE=true \
NASTOOL_CN_UPDATE=true \
NASTOOL_VERSION=dev \
PS1="\u@\h:\w \$ " \
REPO_URL="https://github.com/jxxghp/nas-tools.git" \
PYPI_MIRROR="https://pypi.tuna.tsinghua.edu.cn/simple" \
ALPINE_MIRROR="mirrors.ustc.edu.cn" \
PUID=0 \
PGID=0 \
UMASK=000 \
WORKDIR="/nas-tools"
WORKDIR ${WORKDIR}
RUN python_ver=$(python3 -V | awk '{print $2}') \
&& echo "${WORKDIR}/" > /usr/lib/python${python_ver%.*}/site-packages/nas-tools.pth \
&& echo 'fs.inotify.max_user_watches=524288' >> /etc/sysctl.conf \
&& echo 'fs.inotify.max_user_instances=524288' >> /etc/sysctl.conf \
&& git config --global pull.ff only \
&& git clone -b dev ${REPO_URL} ${WORKDIR} --depth=1 --recurse-submodule \
&& git config --global --add safe.directory ${WORKDIR}
EXPOSE 3000
VOLUME ["/config"]
ENTRYPOINT ["/nas-tools/docker/entrypoint.sh"]

48
nas-tools/Dockerfile.lite Normal file
View File

@ -0,0 +1,48 @@
FROM alpine
RUN apk add --no-cache libffi-dev \
git \
gcc \
musl-dev \
python3-dev \
py3-pip \
libxml2-dev \
libxslt-dev \
tzdata \
su-exec \
dumb-init \
npm \
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& pip install --upgrade pip setuptools wheel \
&& pip install cython \
&& pip install -r https://raw.githubusercontent.com/jxxghp/nas-tools/master/requirements.txt \
&& npm install pm2 -g \
&& apk del --purge libffi-dev gcc musl-dev libxml2-dev libxslt-dev \
&& pip uninstall -y cython \
&& rm -rf /tmp/* /root/.cache /var/cache/apk/*
ENV LANG="C.UTF-8" \
TZ="Asia/Shanghai" \
NASTOOL_CONFIG="/config/config.yaml" \
NASTOOL_AUTO_UPDATE=false \
NASTOOL_CN_UPDATE=true \
NASTOOL_VERSION=lite \
PS1="\u@\h:\w \$ " \
REPO_URL="https://github.com/jxxghp/nas-tools.git" \
PYPI_MIRROR="https://pypi.tuna.tsinghua.edu.cn/simple" \
ALPINE_MIRROR="mirrors.ustc.edu.cn" \
PUID=0 \
PGID=0 \
UMASK=000 \
WORKDIR="/nas-tools"
WORKDIR ${WORKDIR}
RUN python_ver=$(python3 -V | awk '{print $2}') \
&& echo "${WORKDIR}/" > /usr/lib/python${python_ver%.*}/site-packages/nas-tools.pth \
&& echo 'fs.inotify.max_user_watches=524288' >> /etc/sysctl.conf \
&& echo 'fs.inotify.max_user_instances=524288' >> /etc/sysctl.conf \
&& git config --global pull.ff only \
&& git clone -b master ${REPO_URL} ${WORKDIR} --depth=1 --recurse-submodule \
&& git config --global --add safe.directory ${WORKDIR}
EXPOSE 3000
VOLUME ["/config"]
ENTRYPOINT ["/nas-tools/docker/entrypoint.sh"]

19
nas-tools/compose.yml Normal file
View File

@ -0,0 +1,19 @@
version: "3"
services:
nas-tools:
image: jxxghp/nas-tools:latest
ports:
- 3000:3000 # 默认的webui控制端口
volumes:
- ./config:/config # 冒号左边请修改为你想保存配置的路径
- /你的媒体目录:/你想设置的容器内能见到的目录 # 媒体目录,多个目录需要分别映射进来,需要满足配置文件说明中的要求
environment:
- PUID=0 # 想切换为哪个用户来运行程序该用户的uid
- PGID=0 # 想切换为哪个用户来运行程序该用户的gid
- UMASK=000 # 掩码权限默认000可以考虑设置为022
- NASTOOL_AUTO_UPDATE=false # 如需在启动容器时自动升级程程序请设置为true
#- REPO_URL=https://ghproxy.com/https://github.com/jxxghp/nas-tools.git # 当你访问github网络很差时可以考虑解释本行注释
restart: always
network_mode: bridge
hostname: nas-tools
container_name: nas-tools

100
nas-tools/entrypoint.sh Normal file
View File

@ -0,0 +1,100 @@
#!/bin/sh
cd ${WORKDIR}
if [ "${NASTOOL_AUTO_UPDATE}" = "true" ]; then
if [ ! -s /tmp/requirements.txt.sha256sum ]; then
sha256sum requirements.txt > /tmp/requirements.txt.sha256sum
fi
if [ ! -s /tmp/third_party.txt.sha256sum ]; then
sha256sum third_party.txt > /tmp/third_party.txt.sha256sum
fi
if [ "${NASTOOL_VERSION}" != "lite" ]; then
if [ ! -s /tmp/package_list.txt.sha256sum ]; then
sha256sum package_list.txt > /tmp/package_list.txt.sha256sum
fi
fi
echo "更新程序..."
git remote set-url origin "${REPO_URL}" &> /dev/null
echo "windows/" > .gitignore
if [ "${NASTOOL_VERSION}" == "dev" ]; then
branch="dev"
else
branch="master"
fi
git clean -dffx
git fetch --depth 1 origin ${branch}
git reset --hard origin/${branch}
if [ $? -eq 0 ]; then
echo "更新成功..."
# Python依赖包更新
hash_old=$(cat /tmp/requirements.txt.sha256sum)
hash_new=$(sha256sum requirements.txt)
if [ "${hash_old}" != "${hash_new}" ]; then
echo "检测到requirements.txt有变化重新安装依赖..."
if [ "${NASTOOL_CN_UPDATE}" = "true" ]; then
pip install --upgrade pip setuptools wheel -i "${PYPI_MIRROR}"
pip install -r requirements.txt -i "${PYPI_MIRROR}"
else
pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
fi
if [ $? -ne 0 ]; then
echo "无法安装依赖,请更新镜像..."
else
echo "依赖安装成功..."
sha256sum requirements.txt > /tmp/requirements.txt.sha256sum
hash_old=$(cat /tmp/third_party.txt.sha256sum)
hash_new=$(sha256sum third_party.txt)
if [ "${hash_old}" != "${hash_new}" ]; then
echo "检测到third_party.txt有变化更新第三方组件..."
git submodule update --init --recursive
if [ $? -ne 0 ]; then
echo "无法更新第三方组件,请更新镜像..."
else
echo "第三方组件安装成功..."
sha256sum third_party.txt > /tmp/third_party.txt.sha256sum
fi
fi
fi
fi
# 系统软件包更新
if [ "${NASTOOL_VERSION}" != "lite" ]; then
hash_old=$(cat /tmp/package_list.txt.sha256sum)
hash_new=$(sha256sum package_list.txt)
if [ "${hash_old}" != "${hash_new}" ]; then
echo "检测到package_list.txt有变化更新软件包..."
if [ "${NASTOOL_CN_UPDATE}" = "true" ]; then
sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_MIRROR}/g" /etc/apk/repositories
apk update -f
fi
apk add --no-cache libffi-dev
apk add --no-cache $(echo $(cat package_list.txt))
if [ $? -ne 0 ]; then
echo "无法更新软件包,请更新镜像..."
else
apk del libffi-dev
echo "软件包安装成功..."
sha256sum package_list.txt > /tmp/package_list.txt.sha256sum
fi
fi
fi
else
echo "更新失败,继续使用旧的程序来启动..."
fi
else
echo "程序自动升级已关闭如需自动升级请在创建容器时设置环境变量NASTOOL_AUTO_UPDATE=true"
fi
echo "以PUID=${PUID}PGID=${PGID}的身份启动程序..."
if [ "${NASTOOL_VERSION}" = "lite" ]; then
mkdir -p /.pm2
chown -R "${PUID}":"${PGID}" "${WORKDIR}" /config /.pm2
else
mkdir -p /.local
mkdir -p /.pm2
chown -R "${PUID}":"${PGID}" "${WORKDIR}" /config /usr/lib/chromium /.local /.pm2
export PATH=${PATH}:/usr/lib/chromium
fi
umask "${UMASK}"
exec su-exec "${PUID}":"${PGID}" "$(which dumb-init)" "$(which pm2-runtime)" start run.py -n NAStool --interpreter python3

93
nas-tools/readme.md Normal file
View File

@ -0,0 +1,93 @@
## 特点
- 基于alpine实现镜像体积小
- 镜像层数少;
- 支持 amd64/arm64 架构;
- 重启即可更新程序,如果依赖有变化,会自动尝试重新安装依赖,若依赖自动安装不成功,会提示更新镜像;
- 可以以非root用户执行任务降低程序权限和潜在风险
- 可以设置文件掩码权限umask。
- lite 版本不包含浏览器内核及xvfb不支持浏览器仿真不支持Rclone/Minio转移方式不支持复杂依赖变更时的自动安装升级但是体积更小。
## 创建
**注意**
- 媒体目录的设置必须符合 [配置说明](https://github.com/jxxghp/nas-tools#%E9%85%8D%E7%BD%AE) 的要求。
- umask含义详见http://www.01happy.com/linux-umask-analyze 。
- 创建后请根据 [配置说明](https://github.com/jxxghp/nas-tools#%E9%85%8D%E7%BD%AE) 及该文件本身的注释,修改`config/config.yaml`,修改好后再重启容器,最后访问`http://<ip>:<web_port>`。
**docker cli**
```
docker run -d \
--name nas-tools \
--hostname nas-tools \
-p 3000:3000 `# 默认的webui控制端口` \
-v $(pwd)/config:/config `# 冒号左边请修改为你想在主机上保存配置文件的路径` \
-v /你的媒体目录:/你想设置的容器内能见到的目录 `# 媒体目录,多个目录需要分别映射进来` \
-e PUID=0 `# 想切换为哪个用户来运行程序该用户的uid详见下方说明` \
-e PGID=0 `# 想切换为哪个用户来运行程序该用户的gid详见下方说明` \
-e UMASK=000 `# 掩码权限默认000可以考虑设置为022` \
-e NASTOOL_AUTO_UPDATE=false `# 如需在启动容器时自动升级程程序请设置为true` \
-e NASTOOL_CN_UPDATE=false `# 如果开启了容器启动自动升级程序并且网络不太友好时可以设置为true会使用国内源进行软件更新` \
jxxghp/nas-tools
```
如果你访问github的网络不太好可以考虑在创建容器时增加设置一个环境变量`-e REPO_URL="https://ghproxy.com/https://github.com/jxxghp/nas-tools.git" \`。
**docker-compose**
新建`docker-compose.yaml`文件如下,并以命令`docker-compose up -d`启动。
```
version: "3"
services:
nas-tools:
image: jxxghp/nas-tools:latest
ports:
- 3000:3000 # 默认的webui控制端口
volumes:
- ./config:/config # 冒号左边请修改为你想保存配置的路径
- /你的媒体目录:/你想设置的容器内能见到的目录 # 媒体目录,多个目录需要分别映射进来,需要满足配置文件说明中的要求
environment:
- PUID=0 # 想切换为哪个用户来运行程序该用户的uid
- PGID=0 # 想切换为哪个用户来运行程序该用户的gid
- UMASK=000 # 掩码权限默认000可以考虑设置为022
- NASTOOL_AUTO_UPDATE=false # 如需在启动容器时自动升级程程序请设置为true
- NASTOOL_CN_UPDATE=false # 如果开启了容器启动自动升级程序并且网络不太友好时可以设置为true会使用国内源进行软件更新
#- REPO_URL=https://ghproxy.com/https://github.com/jxxghp/nas-tools.git # 当你访问github网络很差时可以考虑解释本行注释
restart: always
network_mode: bridge
hostname: nas-tools
container_name: nas-tools
```
## 后续如何更新
- 正常情况下,如果设置了`NASTOOL_AUTO_UPDATE=true`重启容器即可自动更新nas-tools程序。
- 设置了`NASTOOL_AUTO_UPDATE=true`时,如果启动时的日志提醒你 "更新失败,继续使用旧的程序来启动...",请再重启一次,如果一直都报此错误,请改善你的网络。
- 设置了`NASTOOL_AUTO_UPDATE=true`时,如果启动时的日志提醒你 "无法安装依赖,请更新镜像..."则需要删除旧容器删除旧镜像重新pull镜像再重新创建容器。
## 关于PUID/PGID的说明
- 如在使用诸如emby、jellyfin、plex、qbittorrent、transmission、deluge、jackett、sonarr、radarr等等的docker镜像请保证创建本容器时的PUID/PGID和它们一样。
- 在docker宿主上登陆媒体文件所有者的这个用户然后分别输入`id -u`和`id -g`可获取到uid和gid分别设置为PUID和PGID即可。
- `PUID=0` `PGID=0`指root用户它拥有最高权限若你的媒体文件的所有者不是root不建议设置为`PUID=0` `PGID=0`
## 如果要硬连接如何映射
参考下图由imogel@telegram制作。
![如何映射](volume.png)

BIN
nas-tools/volume.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB