39 Commits
0.3.0 ... 0.6.0

Author SHA1 Message Date
a4e4227327 doc: clean up 2020-12-02 13:22:35 -07:00
ef29a8dadc ci: build on all tags 2020-12-02 13:18:01 -07:00
e28e8dbd2f docs: bump version 2020-12-02 13:16:14 -07:00
cba326b800 ci: remove platform list 2020-12-02 12:54:34 -07:00
16396988c2 ci: fix typo 2020-12-02 12:49:55 -07:00
22900fddd1 ci: extra logging 2020-12-02 12:47:50 -07:00
ff6fde0e5b ci: echo tag value 2020-12-02 12:41:45 -07:00
5f5abd5251 ci: fix typo 2020-12-02 12:01:31 -07:00
84ce659f86 ci: change how tag is built 2020-12-02 11:50:10 -07:00
92d2c91227 ci: force expression tag 2020-12-02 11:45:32 -07:00
0ef158253f ci: fix str 2020-12-02 11:43:12 -07:00
af7994a740 ci: fix how tag is built 2020-12-02 11:42:08 -07:00
1af64f5f7d ci: log env 2020-12-02 11:39:27 -07:00
44a4708123 ci: change how env is set 2020-12-02 11:35:28 -07:00
85a0ecf368 ci: ensure push always happens 2020-12-02 11:32:39 -07:00
cdf3f1a005 docs: update tag versions 2020-12-02 11:31:16 -07:00
e81c5c7fb9 ci: fix docker login 2020-12-02 11:26:30 -07:00
71b0bf9ac2 ci: fix eq operator 2020-12-02 11:23:41 -07:00
61149875ae ci: fix expression 2020-12-02 11:22:09 -07:00
2c633af586 ci: syntax fix 2020-12-02 11:20:25 -07:00
8940b3300e ci: add in build process 2020-12-02 11:18:46 -07:00
6406e1f6e4 docs: add docker pull count 2020-12-01 17:34:27 -07:00
9349a92372 docs: add funcing 2020-11-30 22:41:56 -07:00
c82354e261 Merge pull request #29 from martinec/patch-1
Update README.md
2020-02-26 12:33:12 -07:00
21e58d0588 feat: add license 2019-08-04 17:10:47 -06:00
911eed81f6 Update README.md
The final Ofelia image has now a size of ~10MB

@see https://github.com/mcuadros/ofelia/pull/20
2019-03-27 14:28:48 +01:00
ac1760ce71 Merge pull request #27 from sergey-shambir/docs-for-docker-compose-use-case
Documented usage with docker-compose
2019-03-17 13:10:49 -06:00
68fa96e2e8 Merge pull request #25 from sergey-shambir/issue_20
Use another way to ensure docker socket is accessible
2019-03-17 13:10:08 -06:00
b0f5681faf Merge pull request #26 from sergey-shambir/docker-cmd-fix
Improve crond command in Dockerfile
2019-03-17 13:09:12 -06:00
945357ce4a Merge pull request #24 from sergey-shambir/envsubst
Added support for envsubst in image/container name
2019-03-17 13:08:19 -06:00
5d9d345dd5 Merge pull request #23 from iusmac/patch-1
Fix issue "ambiguous redirect"
2019-03-04 09:21:45 -07:00
5946f3545d Documented usage with docker-compose 2019-03-02 16:16:07 +03:00
46407e1e27 Turned off verbose logging
For busybox cron level 6 is enough to see errors and hide debug info
Debug info shown at level 5
Nothing shown at levels 0, 1, 2, 3, 4
See https://unix.stackexchange.com/questions/412805/crond-log-level-meaning
2019-03-02 16:02:57 +03:00
e3afe6c3e5 Fix crond command in Dockerfile
- added logging to docker logs
- run with /etc/crontabs dir
See also https://unix.stackexchange.com/questions/412805/crond-log-level-meaning
2019-03-02 16:02:52 +03:00
0a4e3f5753 Use another way to ensure docker socket is accessible
- check if socket group ID is presented in /etc/group
- if presented, just add 'docker' user to this group
- if not, create 'docker' group and add 'docker' user to this group
Fixes issue #20
2019-03-02 16:01:40 +03:00
71661b4971 Added support for envsubst in image/container name
Envsubst allows to use dynamic container name
We use image name env substitution with docker-compose and .env to select right image tag for local development
Within alpine, envsubst installed with gettext package.
2019-03-02 15:49:26 +03:00
cba3bcb0d0 Fix issue "ambiguous redirect"
Full error message: "/docker-entrypoint.sh: line 58: ${HOME_DIR}/projects/${SCRIPT_NAME}.sh: ambiguous redirect"

The error appears when in Config.json is present `name` and `container`.
2019-03-01 20:50:12 +01:00
02a89f6dac fix: clean up logic and only apply group if needed 2018-06-30 15:23:27 -06:00
b89e312569 fix: Change group id
Change group id to not conflict with host common id

Fix #13
2018-02-27 23:44:47 -07:00
6 changed files with 127 additions and 15 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,12 @@
# These are supported funding model platforms
github: [willfarrell]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

48
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: build
on:
push:
branches:
- main
tags:
- '*'
schedule:
- cron: '0 0 * * *'
jobs:
multi:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker 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
- 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 }}

View File

@ -1,7 +1,7 @@
FROM library/docker:stable FROM library/docker:stable
ENV HOME_DIR=/opt/crontab ENV HOME_DIR=/opt/crontab
RUN apk add --no-cache --virtual .run-deps bash jq \ RUN apk add --no-cache --virtual .run-deps gettext bash jq \
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \ && mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \
&& adduser -S docker -D && adduser -S docker -D
@ -11,4 +11,4 @@ ENTRYPOINT ["/docker-entrypoint"]
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
CMD ["crond","-f"] CMD ["crond", "-f", "-d", "6", "-c", "/etc/crontabs"]

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 will Farrell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -5,12 +5,12 @@ A simple wrapper over `docker` to all complex cron job to be run in other contai
## Supported tags and Dockerfile links ## Supported tags and Dockerfile links
- [`latest` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/master/Dockerfile) - [`latest` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/master/Dockerfile)
- [`0.6.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/0.6.0/Dockerfile)
[![](https://images.microbadger.com/badges/version/willfarrell/crontab.svg)](http://microbadger.com/images/willfarrell/crontab "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/willfarrell/crontab.svg)](http://microbadger.com/images/willfarrell/crontab "Get your own image badge on microbadger.com") ![](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")
## Why? ## Why?
Yes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (280MB), it was the main inspiration for this project. Yes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (~10MB), it was the main inspiration for this project.
A great project, don't get me wrong. It was just missing certain key enterprise features I felt were required to support where docker is heading. A great project, don't get me wrong. It was just missing certain key enterprise features I felt were required to support where docker is heading.
## Features ## Features
@ -57,6 +57,7 @@ See [`config.sample.json`](https://github.com/willfarrell/docker-crontab/blob/ma
## 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 \
@ -67,7 +68,19 @@ docker run -d \
crontab crontab
``` ```
### 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`
* otherwise [read the docker-compose docs](https://docs.docker.com/compose/networking/)
2. Add `dockerargs` to your docker-crontab `config.json`
* 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
```Dockerfile ```Dockerfile
FROM willfarrell/crontab FROM willfarrell/crontab
@ -76,6 +89,7 @@ COPY config.json ${HOME_DIR}/
``` ```
### Logrotate Dockerfile ### Logrotate Dockerfile
```Dockerfile ```Dockerfile
FROM willfarrell/crontab FROM willfarrell/crontab
@ -87,13 +101,13 @@ CMD ["crond", "-f"]
``` ```
### Logging - In Dev ### 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. 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` 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}` grok: `CRONTABLOG %{DATA:request_id} %{TIMESTAMP_ISO8601:timestamp} \[%{LOGLEVEL:severity}\] %{GREEDYDATA:message}`
## TODO ## TODO
- [ ] Have ability to auto regenerate crontab on file change (signal HUP?) - [ ] Have ability to auto regenerate crontab on file change (signal HUP?)
- [ ] Run commands on host machine (w/ --privileged?) - [ ] Run commands on host machine (w/ --privileged?)

View File

@ -22,12 +22,26 @@ CRONTAB_FILE=/etc/crontabs/docker
# Ensure dir exist - in case of volume mapping # Ensure dir exist - in case of volume mapping
mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects
# Create docker group using correct gid from host, and add docker user to it ensure_docker_socket_accessible() {
if ! grep -q "^docker:" /etc/group; then if ! grep -q "^docker:" /etc/group; then
# Ensure 'docker' user has permissions for docker socket (without changing permissions)
DOCKER_GID=$(stat -c '%g' ${DOCKER_SOCK}) DOCKER_GID=$(stat -c '%g' ${DOCKER_SOCK})
if [ "${DOCKER_GID}" != "0" ]; then
if ! grep -qE "^[^:]+:[^:]+:${DOCKER_GID}:" /etc/group; then
# No group with such gid exists - create group docker
addgroup -g ${DOCKER_GID} docker addgroup -g ${DOCKER_GID} docker
adduser docker docker adduser docker docker
else
# Group with such gid exists - add user "docker" to this group
DOCKER_GROUP_NAME=`getent group "${DOCKER_GID}" | awk -F':' '{{ print $1 }}'`
adduser docker $DOCKER_GROUP_NAME
fi fi
else
# Docker socket belongs to "root" group - add user "docker" to this group
adduser docker root
fi
fi
}
slugify() { slugify() {
echo "$@" | iconv -t ascii | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z echo "$@" | iconv -t ascii | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
@ -36,7 +50,7 @@ slugify() {
make_image_cmd() { make_image_cmd() {
DOCKERARGS=$(echo ${1} | jq -r .dockerargs) DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi
IMAGE=$(echo ${1} | jq -r .image) IMAGE=$(echo ${1} | jq -r .image | envsubst)
TMP_COMMAND=$(echo ${1} | jq -r .command) TMP_COMMAND=$(echo ${1} | jq -r .command)
echo "docker run ${DOCKERARGS} ${IMAGE} ${TMP_COMMAND}" echo "docker run ${DOCKERARGS} ${IMAGE} ${TMP_COMMAND}"
} }
@ -45,8 +59,9 @@ make_container_cmd() {
DOCKERARGS=$(echo ${1} | jq -r .dockerargs) DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi
SCRIPT_NAME=$(echo ${1} | jq -r .name) SCRIPT_NAME=$(echo ${1} | jq -r .name)
SCRIPT_NAME=$(slugify $SCRIPT_NAME)
PROJECT=$(echo ${1} | jq -r .project) PROJECT=$(echo ${1} | jq -r .project)
CONTAINER=$(echo ${1} | jq -r .container) CONTAINER=$(echo ${1} | jq -r .container | envsubst)
TMP_COMMAND=$(echo ${1} | jq -r .command) TMP_COMMAND=$(echo ${1} | jq -r .command)
if [ "${PROJECT}" != "null" ]; then if [ "${PROJECT}" != "null" ]; then
@ -215,6 +230,8 @@ EOF
done done
} }
ensure_docker_socket_accessible
if [ "$1" = "crond" ]; then if [ "$1" = "crond" ]; then
if [ -f ${CONFIG} ]; then if [ -f ${CONFIG} ]; then
build_crontab build_crontab