From 8a902ac370fe158247ab48e249d0254f9404fd69 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Mon, 20 Sep 2021 10:55:55 +0300 Subject: [PATCH] Crond image. --- .gitlab-ci.yml | 16 ++++++++++++++++ crond/.dockerignore | 1 + crond/Dockerfile | 20 ++++++++++++++++++++ crond/README.md | 29 +++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 crond/.dockerignore create mode 100644 crond/Dockerfile create mode 100644 crond/README.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5cd2af2..70b29e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -123,3 +123,19 @@ push-sshd: needs: - job: build-sshd artifacts: true + +# crond image: + +build-crond: + extends: .build + variables: + CONTEXT: crond + +push-crond: + extends: .push + variables: + CONTEXT: crond + IMAGE: cron + needs: + - job: build-crond + artifacts: true diff --git a/crond/.dockerignore b/crond/.dockerignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/crond/.dockerignore @@ -0,0 +1 @@ +* diff --git a/crond/Dockerfile b/crond/Dockerfile new file mode 100644 index 0000000..0becbc9 --- /dev/null +++ b/crond/Dockerfile @@ -0,0 +1,20 @@ +FROM alpine:3.14 as downloader +ARG URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-amd64 +ARG SHA1SUM=048b95b48b708983effb2e5c935a1ef8483d9e3e +WORKDIR /tmp +RUN wget -q $URL && \ + echo "$SHA1SUM supercronic-linux-amd64" > sha1.sum && \ + sha1sum -c sha1.sum && \ + install -m 755 supercronic-linux-amd64 /usr/local/bin/supersonic && \ + touch /crontab + +FROM alpine:3.14 +COPY --from=downloader /usr/local/bin/supersonic /usr/local/bin/supersonic +COPY --from=downloader /crontab /crontab +WORKDIR /tmp +USER nobody +CMD [ "supersonic", "/crontab" ] +HEALTHCHECK CMD pgrep supersonic +RUN supersonic -test /crontab +ONBUILD COPY crontab /crontab +ONBUILD RUN supersonic -test /crontab diff --git a/crond/README.md b/crond/README.md new file mode 100644 index 0000000..67191b3 --- /dev/null +++ b/crond/README.md @@ -0,0 +1,29 @@ +# Cron docker + +A Docker image for running a Cron daemon, actually running +[Supersonic](https://github.com/aptible/supercronic). + +## Usage + +There are possible usage patterns for this image. The first is using it in a +multi-stage image build as the source of the `supersonic` binary to incorporate +in your own image like so: + +``` +FROM registry.shore.co.il/cron as supersonic + +FROM alpine:latest +COPY --from=supersonic /usr/local/bin/supersonic /usr/local/bin/ +``` + +The other pattern is building on top of this image to run some periodic tasks. +The `ONBUILD` commands will copy the crontab file and validate it. Just copy +whatever scripts and install whatever packages you need, like so: + +``` +FROM registry.shore.co.il/cron +COPY script /usr/local/bin/ +USER root +RUN apk add --update --no-cache aws-cli +USER nobody +``` -- GitLab