From 6a2470ba30895dce004ca18eee5fb4bc23a23712 Mon Sep 17 00:00:00 2001 From: kannibalox Date: Thu, 22 Jun 2023 17:53:33 -0400 Subject: [PATCH 1/4] Add Dockerfile --- Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6b093c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.11 + +RUN python3 -m venv /app/autotorrent + +ENV PATH=/app/autotorrent/bin/:$PATH +ENV HOME=/app/autotorrent +WORKDIR /app/autotorrent +ENTRYPOINT ["/app/autotorrent/bin/at2"] + +COPY . /tmp/autotorrent/ +RUN pip install --no-cache-dir /tmp/autotorrent/ && rm -r /tmp/autotorrent/ + +## Uncomment to install from pypi +# RUN /app/autotorrent/bin/pip install autotorrent2 From 709dbf49b3c87e7aaf61a294c0056e47a56ef17c Mon Sep 17 00:00:00 2001 From: kannibalox Date: Thu, 22 Jun 2023 22:27:33 -0400 Subject: [PATCH 2/4] Allow switching UID when running --- Dockerfile | 3 ++- docker-entrypoint.sh | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 6b093c8..4f6e4fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,9 @@ RUN python3 -m venv /app/autotorrent ENV PATH=/app/autotorrent/bin/:$PATH ENV HOME=/app/autotorrent WORKDIR /app/autotorrent -ENTRYPOINT ["/app/autotorrent/bin/at2"] +COPY ./docker-entrypoint.sh /opt/docker-entrypoint.sh +ENTRYPOINT ["/opt/docker-entrypoint.sh"] COPY . /tmp/autotorrent/ RUN pip install --no-cache-dir /tmp/autotorrent/ && rm -r /tmp/autotorrent/ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..3542958 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +if [[ -n "$PUID" && -n "$PGID" ]]; then + groupadd -g "$PGID" autotorrent + useradd -u "$PUID" -g "$PGID" -M -d /app/autotorrent autotorrent + echo at2 "$@" | su autotorrent +else + at2 "$@" +fi From 6e05fbec4ba9a3c0417f6a6c85521de48284b6b4 Mon Sep 17 00:00:00 2001 From: kannibalox Date: Fri, 23 Jun 2023 17:54:34 -0400 Subject: [PATCH 3/4] Add tinycron --- Dockerfile | 2 ++ docker-entrypoint.sh | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f6e4fc..f3706d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ ENV PATH=/app/autotorrent/bin/:$PATH ENV HOME=/app/autotorrent WORKDIR /app/autotorrent +RUN curl -sSL https://github.com/bcicen/tinycron/releases/download/v0.4/tinycron-0.4-linux-amd64 > /usr/local/bin/tinycron && chmod +x /usr/local/bin/tinycron + COPY ./docker-entrypoint.sh /opt/docker-entrypoint.sh ENTRYPOINT ["/opt/docker-entrypoint.sh"] COPY . /tmp/autotorrent/ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 3542958..5b66b5a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,7 +2,19 @@ if [[ -n "$PUID" && -n "$PGID" ]]; then groupadd -g "$PGID" autotorrent useradd -u "$PUID" -g "$PGID" -M -d /app/autotorrent autotorrent - echo at2 "$@" | su autotorrent + if [[ "$1" == "cron" ]]; then + SCHEDULE="$2" + shift 2 + echo /usr/local/bin/tinycron "$SCHEDULE" at2 "$@" | su autotorrent + else + echo at2 "$@" | su autotorrent + fi else - at2 "$@" + if [[ "$1" == "cron" ]]; then + SCHEDULE="$2" + shift 2 + /usr/local/bin/tinycron "$SCHEDULE" at2 "$@" + else + at2 "$@" + fi fi From f833e850a3be6d8e4813e36ed028d31e3dbf5526 Mon Sep 17 00:00:00 2001 From: kannibalox Date: Fri, 23 Jun 2023 19:25:48 -0400 Subject: [PATCH 4/4] Allow expanding globs at runtime --- docker-entrypoint.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5b66b5a..cefdac3 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,7 +5,9 @@ if [[ -n "$PUID" && -n "$PGID" ]]; then if [[ "$1" == "cron" ]]; then SCHEDULE="$2" shift 2 - echo /usr/local/bin/tinycron "$SCHEDULE" at2 "$@" | su autotorrent + echo -e '#!/bin/bash\nat2 '"$*" > /var/tmp/cron.sh + chmod +x /var/tmp/cron.sh + echo /usr/local/bin/tinycron "$SCHEDULE" /var/tmp/cron.sh | su autotorrent else echo at2 "$@" | su autotorrent fi @@ -13,7 +15,9 @@ else if [[ "$1" == "cron" ]]; then SCHEDULE="$2" shift 2 - /usr/local/bin/tinycron "$SCHEDULE" at2 "$@" + echo -e '#!/bin/bash\nat2 '"$*" > /var/tmp/cron.sh + chmod +x /var/tmp/cron.sh + /usr/local/bin/tinycron "$SCHEDULE" /var/tmp/cron.sh else at2 "$@" fi