mirror of
https://github.com/willfarrell/docker-crontab.git
synced 2025-04-19 12:49:48 +02:00
chore: merge from private git repo.
This commit is contained in:
parent
c530324db3
commit
76b524fd17
51
.github/workflows/build.yml
vendored
51
.github/workflows/build.yml
vendored
@ -13,37 +13,32 @@ jobs:
|
|||||||
multi:
|
multi:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
- name: Checkout
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
-
|
|
||||||
name: Set up QEMU
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
-
|
|
||||||
name: Set up Docker Buildx
|
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
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: Login to DockerHub
|
||||||
name: Conditional(Set tag as `latest`)
|
# uses: docker/login-action@v1
|
||||||
run: echo "tag=willfarrell/crontab:latest" >> $GITHUB_ENV
|
# with:
|
||||||
|
# username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
# password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- if: startsWith(github.ref, 'refs/tags/')
|
# - if: github.ref == 'refs/heads/main'
|
||||||
name: Conditional(Set tag as `{version}`)
|
# name: Conditional(Set tag as `latest`)
|
||||||
run: echo "tag=willfarrell/crontab:${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
# run: echo "tag=willfarrell/crontab:latest" >> $GITHUB_ENV
|
||||||
|
|
||||||
-
|
# - if: startsWith(github.ref, 'refs/tags/')
|
||||||
name: Build and push
|
# name: Conditional(Set tag as `{version}`)
|
||||||
uses: docker/build-push-action@v2
|
# run: echo "tag=willfarrell/crontab:${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
with:
|
|
||||||
context: .
|
# - name: Build and push
|
||||||
file: ./Dockerfile
|
# uses: docker/build-push-action@v2
|
||||||
push: true
|
# with:
|
||||||
tags: |
|
# context: .
|
||||||
${{ env.tag }}
|
# file: ./Dockerfile
|
||||||
|
# push: true
|
||||||
|
# tags: |
|
||||||
|
# ${{ env.tag }}
|
||||||
|
40
Dockerfile
40
Dockerfile
@ -1,24 +1,36 @@
|
|||||||
FROM alpine:3.16 as rq-build
|
FROM alpine:latest as rq-build
|
||||||
|
|
||||||
ENV RQ_VERSION=1.0.2
|
ENV RQ_VERSION=1.0.2
|
||||||
WORKDIR /root/
|
WORKDIR /usr/bin/rq/
|
||||||
|
|
||||||
RUN apk --update add upx \
|
RUN apk update && \
|
||||||
&& wget https://github.com/dflemstr/rq/releases/download/v${RQ_VERSION}/rq-v${RQ_VERSION}-x86_64-unknown-linux-musl.tar.gz \
|
apk upgrade && \
|
||||||
&& tar -xvf rq-v1.0.2-x86_64-unknown-linux-musl.tar.gz \
|
apk add --no-cache \
|
||||||
&& upx --brute rq
|
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
|
FROM docker:latest as release
|
||||||
|
|
||||||
COPY --from=rq-build /root/rq /usr/local/bin
|
|
||||||
|
|
||||||
ENV HOME_DIR=/opt/crontab
|
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 /
|
RUN apk update && \
|
||||||
ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint"]
|
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 \
|
HEALTHCHECK --interval=5s --timeout=3s \
|
||||||
CMD ps aux | grep '[c]rond' || exit 1
|
CMD ps aux | grep '[c]rond' || exit 1
|
||||||
|
48
README.md
48
README.md
@ -1,14 +1,6 @@
|
|||||||
# docker-crontab
|
# docker-crontab
|
||||||
|
|
||||||
A simple wrapper over `docker` to all complex cron job to be run in other containers.
|
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).
|
||||||
|
|
||||||
## 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)
|
|
||||||
|
|
||||||
 [](http://microbadger.com/images/willfarrell/crontab "Get your own image badge on microbadger.com")
|
|
||||||
|
|
||||||
## Why?
|
## 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.
|
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`.
|
- Ability to trigger scripts in other containers on completion cron job using `trigger`.
|
||||||
|
|
||||||
## Config file
|
## 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)
|
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.
|
- `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
|
## How to use
|
||||||
|
|
||||||
### Command Line
|
### Command Line
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t crontab .
|
docker build -t crontab .
|
||||||
docker run -d \
|
docker run -d \
|
||||||
@ -73,7 +63,6 @@ docker run -d \
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Use with docker-compose
|
### Use with docker-compose
|
||||||
|
|
||||||
1. Figure out which network name used for your docker-compose containers
|
1. Figure out which network name used for your docker-compose containers
|
||||||
* use `docker network ls` to see existing networks
|
* 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`
|
* 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 `--network NETWORK_NAME` to connect new container into docker-compose network
|
||||||
* use `--rm --name NAME` to use named container
|
* use `--rm --name NAME` to use named container
|
||||||
* e.g. `"dockerargs": "--network my_dir_default --rm --name my-best-cron-job"`
|
* 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
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
DOCKER_SOCK=/var/run/docker.sock
|
DOCKER_SOCK=/var/run/docker.sock
|
||||||
CRONTAB_FILE=/etc/crontabs/docker
|
CRONTAB_FILE=/etc/crontabs/docker
|
||||||
|
|
||||||
# For local testing only.
|
|
||||||
#HOME_DIR=.
|
|
||||||
|
|
||||||
if [ -z "${HOME_DIR}" ]; then
|
if [ -z "${HOME_DIR}" ]; then
|
||||||
echo "HOME_DIR not set."
|
echo "HOME_DIR not set."
|
||||||
exit 1
|
exit 1
|
||||||
@ -114,19 +112,11 @@ EOF
|
|||||||
fi
|
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() {
|
make_cmd() {
|
||||||
if [ "$(echo "${1}" | jq -r .image)" != "null" ]; then
|
if [ "$(echo "${1}" | jq -r .image)" != "null" ]; then
|
||||||
make_image_cmd "${1}"
|
make_image_cmd "${1}"
|
||||||
elif [ "$(echo "${1}" | jq -r .container)" != "null" ]; then
|
elif [ "$(echo "${1}" | jq -r .container)" != "null" ]; then
|
||||||
make_container_cmd "${1}"
|
make_container_cmd "${1}"
|
||||||
#elif [ "$(echo ${1} | jq -r .host)" != "null" ]; then
|
|
||||||
# make_host_cmd "${1}"
|
|
||||||
else
|
else
|
||||||
echo "${1}" | jq -r .command
|
echo "${1}" | jq -r .command
|
||||||
fi
|
fi
|
||||||
@ -257,7 +247,7 @@ start_app() {
|
|||||||
normalize_config
|
normalize_config
|
||||||
export CONFIG=${HOME_DIR}/config.working.json
|
export CONFIG=${HOME_DIR}/config.working.json
|
||||||
if [ ! -f "${CONFIG}" ]; then
|
if [ ! -f "${CONFIG}" ]; then
|
||||||
echo "generated ${CONFIG} missing."
|
echo "generated ${CONFIG} missing. exiting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ "${1}" == "crond" ]; then
|
if [ "${1}" == "crond" ]; then
|
||||||
@ -268,4 +258,5 @@ start_app() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_docker_socket_accessible
|
ensure_docker_socket_accessible
|
||||||
|
printf "✨ starting crontab container ✨\n"
|
||||||
start_app "${@}"
|
start_app "${@}"
|
20
test_logging
20
test_logging
@ -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"
|
|
Loading…
x
Reference in New Issue
Block a user