From 934bc9a2857865b726dab0f63a9e7a2f6048ba50 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 30 May 2023 12:17:39 +0200 Subject: docker: rename scripts --- docker/Dockerfile | 8 ++++---- docker/cgitize.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ docker/in_cron.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ docker/run.sh | 44 ------------------------------------------- docker/run_cron.sh | 55 ------------------------------------------------------ 5 files changed, 103 insertions(+), 103 deletions(-) create mode 100755 docker/cgitize.sh create mode 100755 docker/in_cron.sh delete mode 100755 docker/run.sh delete mode 100755 docker/run_cron.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 15e4962..18bffde 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -20,13 +20,13 @@ ARG ssh_sock_dir=/ ARG ssh_sock_path="$ssh_sock_dir/ssh-agent.sock" ENV SSH_AUTH_SOCK "$ssh_sock_path" +COPY ["docker/cgitize.sh", "/"] COPY ["docker/get_output_dir.py", "/"] -COPY ["docker/run.sh", "/"] -COPY ["docker/run_cron.sh", "/"] +COPY ["docker/in_cron.sh", "/"] COPY ["cgitize/", "/usr/src/cgitize/"] ENV SCHEDULE_ON_START=1 -ENTRYPOINT ["/sbin/tini", "--", "/run_cron.sh"] +ENTRYPOINT ["/sbin/tini", "--", "/in_cron.sh"] WORKDIR /usr/src -CMD ["/run.sh"] +CMD ["/cgitize.sh"] diff --git a/docker/cgitize.sh b/docker/cgitize.sh new file mode 100755 index 0000000..92fe43c --- /dev/null +++ b/docker/cgitize.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Copyright (c) 2023 Egor Tensin +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize. +# Distributed under the MIT License. + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" +script_dir="$( cd -- "$script_dir" && pwd )" +readonly script_dir + +readonly src_dir=/usr/src +readonly cfg_path=/etc/cgitize/cgitize.toml + +secure_repo_dir() { + local dir + dir="$( "$script_dir/get_output_dir.py" -- "$cfg_path" )" + + chmod -- o-rwx "$dir" + + # This is required so that nginx can access the directory. + # nginx uses a fixed UID: + # https://github.com/nginxinc/docker-nginx/blob/4785a604aa40e0b0a69047a61e28781a2b0c2069/mainline/alpine-slim/Dockerfile#L16 + chown -- :101 "$dir" +} + +setup() { + secure_repo_dir +} + +run() { + cd -- "$src_dir" + exec python3 -m cgitize.main "$@" +} + +main() { + setup + run "$@" +} + +main "$@" diff --git a/docker/in_cron.sh b/docker/in_cron.sh new file mode 100755 index 0000000..d23ab70 --- /dev/null +++ b/docker/in_cron.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021 Egor Tensin +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize. +# Distributed under the MIT License. + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +schedule_to_cron() { + local schedule + for schedule; do + case "$schedule" in + minutely) echo '* * * * *' ;; + 15min) echo '*/15 * * * *' ;; + hourly) echo '0 * * * *' ;; + daily) echo '0 0 * * *' ;; + weekly) echo '0 0 * * 1' ;; + monthly) echo '0 0 1 * *' ;; + *) + echo "$schedule" + ;; + esac + done +} + +setup_cron_task() { + local schedule + schedule="${SCHEDULE:-once}" + + if [ "$schedule" = once ]; then + exec "$@" + fi + + schedule="$( schedule_to_cron "$schedule" )" + + if [ -n "${SCHEDULE_ON_START:+x}" ]; then + # Run the task once when the container is started. + "$@" + fi + + local crontab + crontab="$schedule" + crontab="$crontab$( printf ' %q' "$@" )" + + echo "$crontab" | crontab - + exec crond -f +} + +main() { + setup_cron_task "$@" +} + +main "$@" diff --git a/docker/run.sh b/docker/run.sh deleted file mode 100755 index 92fe43c..0000000 --- a/docker/run.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2023 Egor Tensin -# This file is part of the "cgitize" project. -# For details, see https://github.com/egor-tensin/cgitize. -# Distributed under the MIT License. - -set -o errexit -o nounset -o pipefail -shopt -s inherit_errexit lastpipe - -script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" -script_dir="$( cd -- "$script_dir" && pwd )" -readonly script_dir - -readonly src_dir=/usr/src -readonly cfg_path=/etc/cgitize/cgitize.toml - -secure_repo_dir() { - local dir - dir="$( "$script_dir/get_output_dir.py" -- "$cfg_path" )" - - chmod -- o-rwx "$dir" - - # This is required so that nginx can access the directory. - # nginx uses a fixed UID: - # https://github.com/nginxinc/docker-nginx/blob/4785a604aa40e0b0a69047a61e28781a2b0c2069/mainline/alpine-slim/Dockerfile#L16 - chown -- :101 "$dir" -} - -setup() { - secure_repo_dir -} - -run() { - cd -- "$src_dir" - exec python3 -m cgitize.main "$@" -} - -main() { - setup - run "$@" -} - -main "$@" diff --git a/docker/run_cron.sh b/docker/run_cron.sh deleted file mode 100755 index d23ab70..0000000 --- a/docker/run_cron.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2021 Egor Tensin -# This file is part of the "cgitize" project. -# For details, see https://github.com/egor-tensin/cgitize. -# Distributed under the MIT License. - -set -o errexit -o nounset -o pipefail -shopt -s inherit_errexit lastpipe - -schedule_to_cron() { - local schedule - for schedule; do - case "$schedule" in - minutely) echo '* * * * *' ;; - 15min) echo '*/15 * * * *' ;; - hourly) echo '0 * * * *' ;; - daily) echo '0 0 * * *' ;; - weekly) echo '0 0 * * 1' ;; - monthly) echo '0 0 1 * *' ;; - *) - echo "$schedule" - ;; - esac - done -} - -setup_cron_task() { - local schedule - schedule="${SCHEDULE:-once}" - - if [ "$schedule" = once ]; then - exec "$@" - fi - - schedule="$( schedule_to_cron "$schedule" )" - - if [ -n "${SCHEDULE_ON_START:+x}" ]; then - # Run the task once when the container is started. - "$@" - fi - - local crontab - crontab="$schedule" - crontab="$crontab$( printf ' %q' "$@" )" - - echo "$crontab" | crontab - - exec crond -f -} - -main() { - setup_cron_task "$@" -} - -main "$@" -- cgit v1.2.3