diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b80b36c..7d524eb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,37 +13,32 @@ jobs: multi: runs-on: ubuntu-latest steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx + + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - if: github.ref == 'refs/heads/main' - name: Conditional(Set tag as `latest`) - run: echo "tag=willfarrell/crontab:latest" >> $GITHUB_ENV +# - name: Login to DockerHub +# uses: docker/login-action@v1 +# with: +# username: ${{ secrets.DOCKER_USERNAME }} +# password: ${{ secrets.DOCKER_PASSWORD }} - - if: startsWith(github.ref, 'refs/tags/') - name: Conditional(Set tag as `{version}`) - run: echo "tag=willfarrell/crontab:${GITHUB_REF#refs/*/}" >> $GITHUB_ENV +# - if: github.ref == 'refs/heads/main' +# name: Conditional(Set tag as `latest`) +# run: echo "tag=willfarrell/crontab:latest" >> $GITHUB_ENV - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - push: true - tags: | - ${{ env.tag }} +# - if: startsWith(github.ref, 'refs/tags/') +# name: Conditional(Set tag as `{version}`) +# run: echo "tag=willfarrell/crontab:${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + +# - name: Build and push +# uses: docker/build-push-action@v2 +# with: +# context: . +# file: ./Dockerfile +# push: true +# tags: | +# ${{ env.tag }} diff --git a/Dockerfile b/Dockerfile index a5dfb47..d30258e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,36 @@ -FROM alpine:3.16 as rq-build +FROM alpine:latest as rq-build ENV RQ_VERSION=1.0.2 -WORKDIR /root/ +WORKDIR /usr/bin/rq/ -RUN apk --update add upx \ - && wget https://github.com/dflemstr/rq/releases/download/v${RQ_VERSION}/rq-v${RQ_VERSION}-x86_64-unknown-linux-musl.tar.gz \ - && tar -xvf rq-v1.0.2-x86_64-unknown-linux-musl.tar.gz \ - && upx --brute rq +RUN apk update && \ + apk upgrade && \ + apk add --no-cache \ + upx && \ + wget https://github.com/dflemstr/rq/releases/download/v${RQ_VERSION}/rq-v${RQ_VERSION}-x86_64-unknown-linux-musl.tar.gz && \ + tar -xvf rq-v${RQ_VERSION}-x86_64-unknown-linux-musl.tar.gz && \ + upx --brute rq -FROM library/docker:stable - -COPY --from=rq-build /root/rq /usr/local/bin +FROM docker:latest as release ENV HOME_DIR=/opt/crontab -RUN apk add --no-cache --virtual .run-deps gettext jq bash tini \ - && mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \ - && adduser -S docker -D -COPY docker-entrypoint / -ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint"] +RUN apk update && \ + apk upgrade && \ + apk add --no-cache \ + bash \ + curl \ + gettext \ + jq \ + tini \ + wget && \ + mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects && \ + adduser -S docker -D + +COPY --from=rq-build /usr/bin/rq/rq /usr/local/bin +COPY entrypoint.sh / + +ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"] HEALTHCHECK --interval=5s --timeout=3s \ CMD ps aux | grep '[c]rond' || exit 1 diff --git a/README.md b/README.md index 8fc98e0..0caf294 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,6 @@ # docker-crontab -A simple wrapper over `docker` to all complex cron job to be run in other containers. - -## Supported tags and Dockerfile links - -- [`latest` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/master/Dockerfile) -- [`1.0.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/1.0.0/Dockerfile) -- [`0.6.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/0.6.0/Dockerfile) - -![](https://img.shields.io/docker/pulls/willfarrell/crontab "Total docker pulls") [![](https://images.microbadger.com/badges/image/willfarrell/crontab.svg)](http://microbadger.com/images/willfarrell/crontab "Get your own image badge on microbadger.com") +A simple wrapper over `docker` to all complex cron job to be run in other containers. Note, this is a maintained fork of [willfarrell/docker-crontab](https://github.com/willfarrell/docker-crontab). ## Why? Yes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (>250MB when this was created), it was the main inspiration for this project. @@ -23,7 +15,6 @@ A great project, don't get me wrong. It was just missing certain key enterprise - Ability to trigger scripts in other containers on completion cron job using `trigger`. ## Config file - The config file can be specifed in any of `json`, `toml`, or `yaml`, and can be defined as either an array or mapping (top-level keys will be ignored; can be useful for organizing commands) - `name`: Human readable name that will be used as the job filename. Will be converted into a slug. Optional. @@ -61,7 +52,6 @@ See [`config-samples`](config-samples) for examples. ## How to use ### Command Line - ```bash docker build -t crontab . docker run -d \ @@ -73,7 +63,6 @@ docker run -d \ ``` ### Use with docker-compose - 1. Figure out which network name used for your docker-compose containers * use `docker network ls` to see existing networks * if your `docker-compose.yml` is in `my_dir` directory, you probably has network `my_dir_default` @@ -82,38 +71,3 @@ docker run -d \ * use `--network NETWORK_NAME` to connect new container into docker-compose network * use `--rm --name NAME` to use named container * e.g. `"dockerargs": "--network my_dir_default --rm --name my-best-cron-job"` - -### Dockerfile - -```Dockerfile -FROM willfarrell/crontab - -COPY config.json ${HOME_DIR}/ - -``` - -### Logrotate Dockerfile - -```Dockerfile -FROM willfarrell/crontab - -RUN apk add --no-cache logrotate -RUN echo "*/5 * * * * /usr/sbin/logrotate /etc/logrotate.conf" >> /etc/crontabs/logrotate -COPY logrotate.conf /etc/logrotate.conf - -CMD ["crond", "-f"] -``` - -### Logging - In Dev - -All `stdout` is captured, formatted, and saved to `/var/log/crontab/jobs.log`. Set `LOG_FILE` to `/dev/null` to disable logging. - -example: `e6ced859-1563-493b-b1b1-5a190b29e938 2017-06-18T01:27:10+0000 [info] Start Cronjob **map-a-vol** map a volume` - -grok: `CRONTABLOG %{DATA:request_id} %{TIMESTAMP_ISO8601:timestamp} \[%{LOGLEVEL:severity}\] %{GREEDYDATA:message}` - -## TODO -- [ ] Have ability to auto regenerate crontab on file change (signal HUP?) -- [ ] Run commands on host machine (w/ --privileged?) -- [ ] Write tests -- [ ] Setup TravisCI diff --git a/docker-entrypoint b/entrypoint.sh similarity index 96% rename from docker-entrypoint rename to entrypoint.sh index dd8ada5..c3e0aac 100755 --- a/docker-entrypoint +++ b/entrypoint.sh @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +#!/bin/bash + set -e DOCKER_SOCK=/var/run/docker.sock CRONTAB_FILE=/etc/crontabs/docker -# For local testing only. -#HOME_DIR=. - if [ -z "${HOME_DIR}" ]; then echo "HOME_DIR not set." exit 1 @@ -114,19 +112,11 @@ EOF fi } -#make_host_cmd() { -# HOST_BINARY=$(echo ${1} | jq -r .host) -# TMP_COMMAND=$(echo ${1} | jq -r .command) -# echo "${HOST_BINARY} ${TMP_COMMAND}" -#} - make_cmd() { if [ "$(echo "${1}" | jq -r .image)" != "null" ]; then make_image_cmd "${1}" elif [ "$(echo "${1}" | jq -r .container)" != "null" ]; then make_container_cmd "${1}" - #elif [ "$(echo ${1} | jq -r .host)" != "null" ]; then - # make_host_cmd "${1}" else echo "${1}" | jq -r .command fi @@ -257,7 +247,7 @@ start_app() { normalize_config export CONFIG=${HOME_DIR}/config.working.json if [ ! -f "${CONFIG}" ]; then - echo "generated ${CONFIG} missing." + echo "generated ${CONFIG} missing. exiting." exit 1 fi if [ "${1}" == "crond" ]; then @@ -268,4 +258,5 @@ start_app() { } ensure_docker_socket_accessible +printf "✨ starting crontab container ✨\n" start_app "${@}" diff --git a/test_logging b/test_logging deleted file mode 100755 index 97d5645..0000000 --- a/test_logging +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This file is for testing the logging of docker output #8 - -LOG_FILE=./jobs.log -touch ${LOG_FILE} -UUID="xxxxxxxxxxxxxxxxx" - -exec > >(read message; echo "${UUID} $(date) [info] $message" | tee -a ${LOG_FILE} ) -exec 2> >(read message; echo "${UUID} $(date) [error] $message" | tee -a ${LOG_FILE} >&2) - -echo "Start" - -docker run alpine sh -c 'while :; do echo "ping"; sleep 1; done' -# [error] write /dev/stdout: broken pipe -# --log-driver syslog <- errors -# --log-driver none <- errors - -echo "End"