From c5d869390204dab5309e0740f34e65f2b8b76ef0 Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Fri, 7 Apr 2023 13:31:17 +0200 Subject: [PATCH] added docker cron image build environment --- README.md | 28 +++++++++++++++++++++++++++- build.sh | 14 ++++++++++++++ crontab | 8 ++++++++ docker-entrypoint.sh | 8 ++++++++ dockerfile | 15 +++++++++++++++ versions | 2 ++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 build.sh create mode 100644 crontab create mode 100755 docker-entrypoint.sh create mode 100644 dockerfile create mode 100644 versions diff --git a/README.md b/README.md index 39632da..d25b0ab 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# cron +# Docker Cron Image +A docker-based cron image to handle periodic jobs with ease, everything included + +## Usage: +``` +docker run -v $CRONTAB:/crontab/root -v $CRONJOBS:/jobs bryanpedini/cron:$VERSION-$DISTRO +``` + +## Example: +`crontab`: +``` +* * * * * /jobs/echo.sh +``` + +`jobs/echo.sh`: +``` +#!/usr/bin/env sh +echo "this is a custom cron job" +``` + +`docker` command: +``` +docker run -it --rm -v $(pwd)/crontab:/crontab/root -v $(pwd)/jobs:/jobs bryanpedini/cron:1.0-alpine3.16 +``` + +## WARNING: +Pay attention to the `crontab` file permissions, ownership needs to be `0:0` for user `root`. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..8c11415 --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Copyright (c) 2023 · Bryan Joshua Pedini +# LICENSE = gpl3 +# see the LICENSE file for more details + +while read -r LINE; do + VERSION=$(echo "${LINE}" | sed 's/-.*//') + DISTRO=$(echo "${LINE}" | sed 's/.*-//') + docker build \ + --build-arg DISTRO="${DISTRO}" \ + --build-arg VERSION="${VERSION}" \ + -t bryanpedini/cron:"${VERSION}"-alpine"${DISTRO}" . +done < versions diff --git a/crontab b/crontab new file mode 100644 index 0000000..e179d57 --- /dev/null +++ b/crontab @@ -0,0 +1,8 @@ +# do daily/weekly/monthly maintenance +# min hour day month weekday command + +# Copyright (c) 2023 · Bryan Joshua Pedini +# LICENSE = gpl3 +# see the LICENSE file for more details + +* * * * * echo "No cron job set, please set cron jobs, refer to the documentation" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..202e34d --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# Copyright (c) 2023 · Bryan Joshua Pedini +# LICENSE = gpl3 +# see the LICENSE file for more details + +echo "Starting cron..." +crond -f -l 9 -c /crontab diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..811f700 --- /dev/null +++ b/dockerfile @@ -0,0 +1,15 @@ +# Copyright (c) 2023 · Bryan Joshua Pedini +# LICENSE = gpl3 +# see the LICENSE file for more details + +ARG DISTRO +FROM alpine:${DISTRO} + +ARG VERSION +LABEL maintainer="Bryan Joshua Pedini " +LABEL version="${VERSION}" + +COPY crontab /crontab/root +COPY docker-entrypoint.sh /docker-entrypoint.sh + +ENTRYPOINT [ "/docker-entrypoint.sh" ] diff --git a/versions b/versions new file mode 100644 index 0000000..495c4cc --- /dev/null +++ b/versions @@ -0,0 +1,2 @@ +1.0-3.15 +1.0-3.16