From 1592e333be61ed600379d9a59ed68329d269f5f5 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 30 Mar 2021 02:21:21 +0300 Subject: docker: enable scheduled runs via crond --- .ci/.gitattributes | 1 - .dockerignore | 1 + .gitattributes | 2 ++ Dockerfile | 4 +++- docker/entrypoint.sh | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) delete mode 100644 .ci/.gitattributes create mode 100755 docker/entrypoint.sh diff --git a/.ci/.gitattributes b/.ci/.gitattributes deleted file mode 100644 index dfdb8b7..0000000 --- a/.ci/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.sh text eol=lf diff --git a/.dockerignore b/.dockerignore index 272da1f..eabf2d8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ * !/cgitize/** +!/docker/** diff --git a/.gitattributes b/.gitattributes index 176a458..d76765e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ * text=auto + +*.sh text eol=lf diff --git a/Dockerfile b/Dockerfile index a99e1fe..98aab38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,15 @@ FROM alpine:3.10 -RUN apk add --no-cache git openssh-client python3 +RUN apk add --no-cache bash git openssh-client python3 tini ARG ssh_sock_dir=/var/run/cgitize ARG ssh_sock_path="$ssh_sock_dir/ssh-agent.sock" ENV SSH_AUTH_SOCK "$ssh_sock_path" +COPY ["docker/entrypoint.sh", "/"] COPY ["cgitize/", "/usr/src/cgitize/"] WORKDIR /usr/src +ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"] CMD ["python3", "-m", "cgitize.main"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..cf6eb77 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,33 @@ +#!/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 + +schedule="${SCHEDULE:-once}" + +case "$schedule" in + once) exec "$@" ;; + 15min) schedule='*/15 * * * *' ;; + hourly) schedule='0 * * * *' ;; + daily) schedule='0 0 * * *' ;; + weekly) schedule='0 0 * * 1' ;; + monthly) schedule='0 0 1 * *' ;; + *) ;; +esac + +script="#!/bin/bash +cd /usr/src &&$( printf -- ' %q' "$@" )" + +echo "$script" > /task.sh +chmod +x /task.sh + +crontab="$schedule /task.sh +# This is the new crontab." + +echo "$crontab" | crontab - + +crond -f -- cgit v1.2.3