Skip to content

Commit

Permalink
Heroku rclone conf (#176)
Browse files Browse the repository at this point in the history
* Add RCLONE_CONFIG_BASE64 to config rclone on heroku

* Update heroku docker run app.json
  • Loading branch information
wahyd4 committed Oct 11, 2021
1 parent 9e3f772 commit 9a58c2a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 33 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ENV CADDYPATH=/app
ENV RCLONE_CONFIG=/app/conf/rclone.conf
ENV XDG_DATA_HOME=/app/.caddy/data
ENV XDG_CONFIG_HOME=/app/.caddy/config
ENV RCLONE_CONFIG_BASE64=""

ADD install.sh aria2c.sh caddy.sh Procfile init.sh start.sh rclone.sh /app/
ADD conf /app/conf
Expand Down
20 changes: 10 additions & 10 deletions README.CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ services:

### 支持的 Docker 环境变量

* ENABLE_AUTH 启用 Basic auth(网页简单认证) 用户认证
* ENABLE_RCLONE 是否启用 RCLONE,由于Rclone 的初次运行需要从Github 下载文件,由于你懂的原因,可能文件下载失败,进而导致整个程序崩溃,这时你需要设置为`false`
* ARIA2_USER Basic Auth 用户认证用户名,Rclone也使用该参数
* ARIA2_PWD Basic Auth 密码,Rclone也使用该参数
* ARIA2_EXTERNAL_PORT 从外部可以访问到的 Aria2 端口,默认为 HTTP 的`80`
* PUID 需要绑定主机的Linux用户ID,可以通过`cat /etc/passwd` 查看用户列表, 默认UID 是`1000`
* PGID 需要绑定的主机的Linux 用户组ID,默认GID 是`1000`
* RPC_SECRET Aria2 RPC 加密 token
* DOMAIN 绑定的域名, 当绑定的域名为`HTTPS`时,即为启用`HTTPS`, 例: `DOMAIN=https://toozhao.com`

* `ENABLE_AUTH` 启用 Basic auth(网页简单认证) 用户认证
* `ENABLE_RCLONE` 是否启用 RCLONE,由于Rclone 的初次运行需要从Github 下载文件,由于你懂的原因,可能文件下载失败,进而导致整个程序崩溃,这时你需要设置为`false`
* `ARIA2_USER` Basic Auth 用户认证用户名,Rclone也使用该参数
* `ARIA2_PWD` Basic Auth 密码,Rclone也使用该参数
* `ARIA2_EXTERNAL_PORT` 从外部可以访问到的 Aria2 端口,默认为 HTTP 的`80`
* `PUID` 需要绑定主机的Linux用户ID,可以通过`cat /etc/passwd` 查看用户列表, 默认UID 是`1000`
* `PGID` 需要绑定的主机的Linux 用户组ID,默认GID 是`1000`
* `RPC_SECRET` Aria2 RPC 加密 token
* `DOMAIN` 绑定的域名, 当绑定的域名为`HTTPS`时,即为启用`HTTPS`, 例: `DOMAIN=https://toozhao.com`
* `RCLONE_CONFIG_BASE64` 通过`base64` 字符串的形式配置rclone.conf。主要给在Heroku平台上运行时使用,请使用命令行 `cat /app/conf/rclone.conf | base64` 或者其他任何在线base64在线工具 [比如这个](https://www.base64encode.org/)来把`rclone.conf`的内容生成`base64`字符串。在使用本环境变量的同时,请确保`ENABLE_RCLONE`设置为`true`。

### 支持的 Docker volume 属性
* `/data` 用来放置所有下载的文件的目录
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ Then simply run `docker-compose up -d`, that's it!

### Supported Environment Variables

* ENABLE_AUTH whether to enable Basic auth
* ENABLE_RCLONE whether to disable Rclone, if you running this container offline or do not have stable connection to Github, please set to `false`
* ARIA2_USER Basic Auth username, Rclone GUI uses it as well.
* ARIA2_PWD Basic Auth password, Rclone GUI uses it as well.
* ARIA2_EXTERNAL_PORT The Aria2 port which exposed to public to access to
* PUID Bind Linux UID into container which means you can use non `root` user to manage downloaded files, default UID is `1000`
* PGID Bind Linux GID into container, default GID is 1000
* RPC_SECRET The Aria2 RPC secret token
* DOMAIN The domain you'd like to bind, when domain is a `https://` thing, then auto TLS feature will be enabled
* `ENABLE_AUTH` whether to enable Basic auth
* `ENABLE_RCLONE` whether to disable Rclone, if you running this container offline or do not have stable connection to Github, please set to `false`
* `ARIA2_USER` Basic Auth username, Rclone GUI uses it as well.
* `ARIA2_PWD` Basic Auth password, Rclone GUI uses it as well.
* `ARIA2_EXTERNAL_PORT` The Aria2 port which exposed to public to access to
* `PUID` Bind Linux UID into container which means you can use non `root` user to manage downloaded files, default UID is `1000`
* `PGID` Bind Linux GID into container, default GID is 1000
* `RPC_SECRET` The Aria2 RPC secret token
* `DOMAIN` The domain you'd like to bind, when domain is a `https://` thing, then auto TLS feature will be enabled
* `RCLONE_CONFIG_BASE64` Inject and config Rclone through `base64` string, which is the only way to use Rclone on Heroku. Please use `cat /app/conf/rclone.conf | base64` or any base64 online tools such as [this](https://www.base64encode.org/) to encode your `rclone.conf` as bse64 string. Note, you need to set `ENABLE_RCLONE` to true as well.


### Supported Volumes
Expand Down
5 changes: 5 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"value": "heroku",
"required": false
},
"RCLONE_CONFIG_BASE64": {
"description": "This value is the base64 string of your preconfigured /app/conf/rclone.conf content",
"value": "",
"required": false
},
"ARIA2_USER": {
"description": "Username to login to AriaNg",
"value": "user",
Expand Down
4 changes: 2 additions & 2 deletions aria2c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RPC_SECRET_BASE64=$(echo -n ${RPC_SECRET}|base64)
sed -i 's/secret:\"\"/secret:\"'"${RPC_SECRET_BASE64}"'\"/g' /usr/local/www/aria2/js/aria-ng*.js

if [ "$ARIA2_SSL" = "true" ]; then
echo "Start aria2 with secure config"
echo "[INFO] Start aria2 with secure config"

/usr/bin/aria2c --conf-path="/app/conf/aria2.conf" \
--enable-rpc --rpc-listen-all \
Expand All @@ -15,7 +15,7 @@ echo "Start aria2 with secure config"

else

echo "Start aria2 with standard mode"
echo "[INFO] Start aria2 with standard mode"
/usr/bin/aria2c --conf-path="/app/conf/aria2.conf" --enable-rpc --rpc-listen-all

fi
10 changes: 5 additions & 5 deletions caddy.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#! /bin/bash -eu

echo "Run aria2c and ariaNG"
echo "[INFO] Run aria2c and ariaNG"

echo "**** Generate basic auth password for caddy ****"
echo "[INFO] Generate basic auth password for caddy"
ARIA2_PWD_ENCRYPT=$(caddy hash-password -plaintext ${ARIA2_PWD})

case $ENABLE_AUTH in
true)
echo "Using Basic Auth config file "
echo "[INFO] Use Basic Auth config file "
export CADDY_FILE=/usr/local/caddy/SecureCaddyfile
sed -i 's/ARIA2_USER/'"${ARIA2_USER}"'/g' ${CADDY_FILE}
sed -i 's/ARIA2_PWD_ENCRYPT/'"${ARIA2_PWD_ENCRYPT}"'/g' ${CADDY_FILE}
;;

heroku)
echo "Running in Heroku mode"
echo "[INFO] Run Caddy with Heroku mode"
export CADDY_FILE=/usr/local/caddy/HerokuCaddyfile
sed -i 's/ARIA2_USER/'"${ARIA2_USER}"'/g' ${CADDY_FILE}
sed -i 's/ARIA2_PWD_ENCRYPT/'"${ARIA2_PWD_ENCRYPT}"'/g' ${CADDY_FILE}
Expand All @@ -23,7 +23,7 @@ heroku)

;;
*)
echo "Using caddy without Basic Auth"
echo "[INFO] Use caddy without Basic Auth"
export CADDY_FILE=/usr/local/caddy/Caddyfile
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/bash -eu

echo "**** update uid and gid to ${PUID}:${PGID} ****"
echo "[INFO] Update uid and gid to ${PUID}:${PGID}"
groupmod -o -g "$PGID" junv
usermod -o -u "$PUID" junv

Expand All @@ -19,7 +19,7 @@ chmod +x /app/caddy.sh \
/app/rclone.sh \
/app/aria2c.sh

echo "**** give caddy permissions to use low ports ****"
echo "[INFO] Give caddy permissions to use low ports"
setcap cap_net_bind_service=+ep /usr/local/bin/caddy

"${@-sh}"
8 changes: 5 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh -eux

echo "Set variables for $(arch)"
echo "[INFO] Set variables for $(arch)"

caddy_version=2.4.5
filebrowser_version=v2.17.2
Expand Down Expand Up @@ -30,7 +30,7 @@ case "$(arch)" in
;;

*)
echo "unsupported arch $(arch), exit now"
echo "[ERROR] unsupported arch $(arch), exit now"
exit 1
;;
esac
Expand All @@ -40,7 +40,7 @@ ariang_file=AriaNg-${ariang_version}.zip

adduser -D -u 1000 junv \
&& apk update \
&& apk add runit shadow wget bash curl openrc gnupg aria2 tar mailcap --no-cache \
&& apk add runit shadow wget bash curl openrc gnupg aria2 tar mailcap fuse vim --no-cache \
&& wget -N https://github.com/caddyserver/caddy/releases/download/v${caddy_version}/${caddy_file} \
&& tar -zxf ${caddy_file} \
&& mv caddy /usr/local/bin/ \
Expand Down Expand Up @@ -71,3 +71,5 @@ adduser -D -u 1000 junv \
&& unzip ${ariang_file} \
&& rm -rf ${ariang_file} \
&& chmod -R 755 /usr/local/www/aria2 \
&& mkdir -p /data/cloud \
&& chown junv:junv /data/cloud
10 changes: 8 additions & 2 deletions rclone.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#! /bin/bash -eu

if [ "$RCLONE_CONFIG_BASE64" != "" ]; then
echo "[INFO] Config Rclone from RCLONE_CONFIG_BASE64 env"
echo $RCLONE_CONFIG_BASE64 | base64 -d > /app/conf/rclone.conf
echo "[INFO] Config Rclone from RCLONE_CONFIG_BASE64 completed"
fi

if [ "$ENABLE_RCLONE" = "true" ]; then
echo "Start Rclone, please make sure you can connect to Github website. if not, please set docker env ENABLE_RCLONE=false"
echo "[INFO] Start Rclone, please make sure you can connect to Github website. if not, please set docker env ENABLE_RCLONE=false"
rclone rcd --rc-web-gui \
--rc-web-gui-no-open-browser \
--rc-addr :5572 \
--rc-user $ARIA2_USER \
--rc-pass $ARIA2_PWD \
--cache-dir /app/.cache
else
echo "Skip starting Rclone as it's been disabled"
echo "[INFO] Skip starting Rclone as it has been disabled"
sleep 3650d
fi

0 comments on commit 9a58c2a

Please sign in to comment.