diff --git a/README.md b/README.md index 417e266..0ea22fd 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# dockercron +# Docker DockerCron Image +A docker-based cron image that includes the docker & docker compose CLI. + +## Usage: +``` +docker run -v $DOCKERSOCKET:/var/run/docker.sock -v $CRONTAB:/crontab/root -v $CRONJOBS:/jobs bryanpedini/dockercron:$VERSION-$DISTRO +``` + +## Example: +`crontab`: +``` +* * * * * /jobs/dockerps.sh +``` + +`jobs/dockerps.sh`: +``` +#!/usr/bin/env sh +docker ps -a +``` + +`docker` command: +``` +docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/crontab:/crontab/root -v $(pwd)/jobs:/jobs bryanpedini/dockercron: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..980ddb9 --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Copyright (c) 2023 · Bryan Joshua Pedini +# LICENSE = gpl3 +# see the LICENSE file for more details + +COMPOSEVERSION="v2.17.2" + +while read -r LINE; do + VERSION=$(echo "${LINE}" | sed 's/-.*//') + CRONVERSION=$(echo "${LINE}" | sed 's/.*-//;s/:.*//') + DISTRO=$(echo "${LINE}" | sed 's/.*://') + docker build \ + --build-arg CRONVERSION="${CRONVERSION}" \ + --build-arg DISTRO="${DISTRO}" \ + --build-arg VERSION="${VERSION}" \ + --build-arg COMPOSEVERSION="${COMPOSEVERSION}" \ + -t bryanpedini/dockercron:"${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..590d11f --- /dev/null +++ b/dockerfile @@ -0,0 +1,18 @@ +# Copyright (c) 2023 · Bryan Joshua Pedini +# LICENSE = gpl3 +# see the LICENSE file for more details + +ARG CRONVERSION +ARG DISTRO +FROM bryanpedini/cron:${CRONVERSION}-alpine${DISTRO} + +ARG VERSION +LABEL maintainer="Bryan Joshua Pedini " +LABEL version="1.0" + +ARG COMPOSEVERSION +RUN apk add docker && \ + mkdir -p /usr/local/lib/docker/cli-plugins && \ + wget -O /usr/local/lib/docker/cli-plugins/docker-compose \ + https://github.com/docker/compose/releases/download/${COMPOSEVERSION}/docker-compose-linux-x86_64 && \ + chmod +x /usr/local/lib/docker/cli-plugins/docker-compose diff --git a/versions b/versions new file mode 100644 index 0000000..56b27ab --- /dev/null +++ b/versions @@ -0,0 +1,2 @@ +1.0-1.0:3.15 +1.0-1.0:3.16