added docker cron image build environment

This commit is contained in:
Bryan Joshua Pedini 2023-04-07 13:31:17 +02:00
parent 969368d68d
commit c5d8693902
6 changed files with 74 additions and 1 deletions

View File

@ -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`.

14
build.sh Executable file
View File

@ -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

8
crontab Normal file
View File

@ -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"

8
docker-entrypoint.sh Executable file
View File

@ -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

15
dockerfile Normal file
View File

@ -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 <b.pedini@bjphoster.com>"
LABEL version="${VERSION}"
COPY crontab /crontab/root
COPY docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]

2
versions Normal file
View File

@ -0,0 +1,2 @@
1.0-3.15
1.0-3.16