Skip to content

Commit 57fcb5d

Browse files
authored
Merge pull request #2 from panubo/renovation
Renovation
2 parents fe9bce4 + c965f0a commit 57fcb5d

File tree

7 files changed

+155
-40
lines changed

7 files changed

+155
-40
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.dockerignore
12
.git
3+
.github
4+
.gitignore
25
Dockerfile
6+
LICENSE
37
README.md

.github/workflows/build-push.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Panubo build and push to Quay.io and ECR Public
1+
# Source: https://github.com/panubo/reference-github-actions/blob/main/docker-images/build-push.yml
2+
#
3+
# Description: Panubo build and push to Quay.io and ECR Public
24
# This GH Action is intended for public docker images that package upstream applications/services (ie not for projects of Panubo's).
35
# For repos that build multiple repos use the multi-build-push.yml workflow.
46
#
@@ -9,6 +11,8 @@
911
# Automated testing is triggered by `make _ci_test`, if no test is required the Makefile target should just run `true`.
1012
# Before tests are run a Docker build is performed, the resulting image has a tag of "test"
1113
# BATS is installed since it is commonly required by the tests.
14+
#
15+
# LICENSE: MIT License, Copyright (c) 2021-2025 Volt Grid Pty Ltd t/a Panubo
1216

1317
name: build and push on main and tags
1418

@@ -33,7 +37,9 @@ jobs:
3337
runs-on: ubuntu-latest
3438
steps:
3539
- name: Checkout
36-
uses: actions/checkout@v3
40+
uses: actions/checkout@v5
41+
with:
42+
submodules: true
3743

3844
- name: Get repo name
3945
id: image_name
@@ -42,7 +48,7 @@ jobs:
4248
4349
- name: Docker meta
4450
id: meta
45-
uses: docker/metadata-action@v4
51+
uses: docker/metadata-action@v5
4652
with:
4753
# list of Docker images to use as base name for tags
4854
images: |
@@ -59,28 +65,28 @@ jobs:
5965
# type=sha
6066
6167
- name: Set up QEMU
62-
uses: docker/setup-qemu-action@v2
68+
uses: docker/setup-qemu-action@v3
6369

6470
- name: Set up Docker Buildx
6571
id: buildx
66-
uses: docker/setup-buildx-action@v2
72+
uses: docker/setup-buildx-action@v3
6773

6874
# The values provided to these two AWS steps are always the same for Panubo owned repos
6975
- name: Configure AWS Credentials
70-
uses: aws-actions/configure-aws-credentials@v1-node16
76+
uses: aws-actions/configure-aws-credentials@v4
7177
with:
7278
role-to-assume: ${{ env.GITHUB_ROLE_ARN }}
7379
aws-region: us-east-1
7480

7581
- name: Login to ECR
7682
if: github.event_name != 'pull_request'
77-
uses: docker/login-action@v2
83+
uses: docker/login-action@v3
7884
with:
7985
registry: public.ecr.aws
8086

8187
- name: Login to Quay.io
8288
if: github.event_name != 'pull_request'
83-
uses: docker/login-action@v2
89+
uses: docker/login-action@v3
8490
with:
8591
registry: quay.io
8692
username: ${{ secrets.PANUBUILD_QUAYIO_USERNAME }}
@@ -92,7 +98,7 @@ jobs:
9298
bats-version: 1.7.0
9399

94100
- name: Build and export to Docker
95-
uses: docker/build-push-action@v4
101+
uses: docker/build-push-action@v6
96102
with:
97103
builder: ${{ steps.buildx.outputs.name }}
98104
cache-from: type=gha
@@ -104,7 +110,7 @@ jobs:
104110
make _ci_test
105111
106112
- name: Build and Push
107-
uses: docker/build-push-action@v3
113+
uses: docker/build-push-action@v6
108114
with:
109115
builder: ${{ steps.buildx.outputs.name }}
110116
push: ${{ github.event_name != 'pull_request' }}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Source: https://github.com/panubo/reference-github-actions/blob/main/github-release.yml
2+
# Description: Create a GitHub release
3+
# LICENSE: MIT License, Copyright (c) 2021-2025 Volt Grid Pty Ltd t/a Panubo
4+
5+
name: GitHub Release
6+
7+
on:
8+
push:
9+
tags:
10+
- "v*"
11+
workflow_call:
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
build:
18+
name: Create GitHub Release
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v5
23+
with:
24+
fetch-depth: 0 # Required for git log to work
25+
26+
- name: Get Release Notes
27+
id: get_release_notes
28+
run: |
29+
NOTES=$(git log --pretty=format:%s $(git tag --sort=-v:refname | head -1)...$(git tag --sort=-v:refname | head -2 | tail -1) | awk '{ print "-", $0 }')
30+
printf "notes<<EOF\\n%s\\nEOF\\n" "${NOTES}" >> "$GITHUB_OUTPUT"
31+
32+
- name: Create Release
33+
id: create_release
34+
uses: actions/create-release@v1
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
37+
with:
38+
tag_name: ${{ github.ref }}
39+
release_name: ${{ github.ref }}
40+
body: |
41+
Changes since last release:
42+
43+
${{ steps.get_release_notes.outputs.notes }}
44+
45+
draft: false
46+
prerelease: false

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.19
1+
FROM alpine:3.23
22

33
RUN set -x \
44
&& apk --no-cache add bash curl libc6-compat logrotate ssmtp \

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2023 Volt Grid Pty Ltd
3+
Copyright (c) 2016-2024,2026 Volt Grid Pty Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,100 @@
11
# Docker Cron
22

3-
Cron in a container.
3+
[![build and push on main and tags](https://github.com/panubo/docker-cron/actions/workflows/build-push.yml/badge.svg)](https://github.com/panubo/docker-cron/actions/workflows/build-push.yml)
44

5-
This image is available on quay.io `quay.io/panubo/cron` and AWS ECR Public `public.ecr.aws/panubo/cron`.
5+
Cron in a container, based on Alpine Linux and [go-crond](https://github.com/webdevops/go-crond).
66

7-
## Configuration
7+
This image is publicly available from:
8+
- **Quay.io:** `quay.io/panubo/cron`
9+
- **AWS ECR Public:** `public.ecr.aws/panubo/cron`
10+
11+
## Features
12+
13+
- **Unprivileged Cron:** Cron jobs run as a non-root `cron` user.
14+
- **Lightweight:** Based on Alpine Linux.
15+
- **Flexible Logging:** `go-crond` logs to stdout/stderr, making it easy to integrate with container logging systems.
16+
- **Mail Support:** Send cron output via email using `ssmtp`.
17+
- **Dynamic Reloading:** Crontabs can be reloaded without restarting the container.
18+
19+
## Usage
20+
21+
### Basic Example
22+
23+
To run a simple cron job, you need to mount a crontab file at `/crontab`.
824

9-
Mount the crontab at `/crontab`. The cron jobs will be run with the underprivileged `cron` user.
25+
`crontab` file:
26+
```crontab
27+
# Run every minute
28+
* * * * * echo "Hello from cron!"
29+
```
1030

11-
N.B. The container will need to be restarted if the crontab is changed or exec `/reload.sh`.
31+
Run the container:
32+
```sh
33+
docker run --rm \
34+
-v $(pwd)/crontab:/crontab \
35+
quay.io/panubo/cron
36+
```
1237

13-
Configure timezone with `TZ` environment variable. eg: `-e TZ=Australia/Sydney`
14-
or use `CRON_TZ` for each crontab line.
38+
### Docker Compose Example
1539

16-
For linking to SMTP container (optional):
40+
For a more persistent setup, use `docker-compose`:
1741

18-
- `SMTP_HOST`
19-
- `SMTP_PORT`
20-
- `SMTP_USER`
21-
- `SMTP_PASS`
42+
```yaml
43+
services:
44+
cron:
45+
image: quay.io/panubo/cron
46+
container_name: my-cron-service
47+
restart: unless-stopped
48+
volumes:
49+
- ./crontab:/crontab
50+
environment:
51+
- TZ=Australia/Sydney
52+
- EMAIL_TO=your-email@example.com
53+
# SMTP settings if you want email notifications
54+
# - SMTP_HOST=smtp.example.com
55+
# - SMTP_PORT=587
56+
# - SMTP_USER=user
57+
# - SMTP_PASS=password
58+
# - EMAIL_FROM=cron@example.com
59+
```
60+
61+
### Reloading Crontab
62+
63+
If you update the `/crontab` file, you can reload it without restarting the container by executing the `/reload.sh` script:
64+
65+
```sh
66+
docker exec my-cron-service /reload.sh
67+
```
68+
69+
## Configuration
2270

23-
Cron Email settings (optional):
71+
Configuration is managed through environment variables.
2472

25-
- `EMAIL_FROM`
26-
- `EMAIL_TO`
27-
- `HOSTNAME`
73+
| Variable | Description | Default |
74+
|---------------|------------------------------------------------------------------------------------|-----------------|
75+
| `TZ` | Sets the container's timezone (e.g., `Australia/Sydney`). | `UTC` |
76+
| `CRON_TZ` | Sets the timezone for individual cron jobs in the crontab file. | - |
77+
| `EMAIL_FROM` | The `From:` address for cron emails. | `cron` |
78+
| `EMAIL_TO` | The `To:` address for cron emails. | `cron` |
79+
| `SMTP_HOST` | The SMTP server host. | `localhost` |
80+
| `SMTP_PORT` | The SMTP server port. | `25` |
81+
| `SMTP_USER` | Username for SMTP authentication. | `''` |
82+
| `SMTP_PASS` | Password for SMTP authentication. | `''` |
83+
| `HOSTNAME` | Hostname to use for email headers. | container host |
84+
| `DEBUG` | Set to `true` to enable verbose script execution (`set -x`). | `false` |
2885

29-
## Example
86+
## Building from Source
3087

31-
Example with timezone set:
88+
To build the image locally, you can use the provided `Makefile`:
3289

33-
`docker run --rm -t -i -v $(pwd)/crontab:/crontab -e TZ=Australia/Sydney quay.io/panubo/cron:2.0.0`
90+
```sh
91+
make build
92+
```
3493

3594
## History
3695

37-
- v1.x - Debian based
38-
- v2.x - Alpine Linux with [go-crond](https://github.com/webdevops/go-crond/), also includes additional tooling eg logrotate.
96+
- **v1.x:** Debian-based, using standard `vixie-cron`.
97+
- **v2.x:** Migrated to Alpine Linux with [go-crond](https://github.com/webdevops/go-crond) for better container integration. Also includes additional tooling like `logrotate` and `ssmtp`.
3998

4099
## Status
41100

entry.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ set -e
77
echo ">> Running entry.sh"
88

99
# Defaults
10-
: ${HOSTNAME:=$(hostname)}
11-
: ${EMAIL_FROM:='cron'}
12-
: ${EMAIL_TO:='cron'}
13-
: ${SMTP_HOST:='localhost'}
14-
: ${SMTP_PORT:='25'}
15-
: ${SMTP_USER:=''}
16-
: ${SMTP_PASS:=''}
10+
: "${HOSTNAME:=$(hostname)}"
11+
: "${EMAIL_FROM:='cron'}"
12+
: "${EMAIL_TO:='cron'}"
13+
: "${SMTP_HOST:='localhost'}"
14+
: "${SMTP_PORT:='25'}"
15+
: "${SMTP_USER:=''}"
16+
: "${SMTP_PASS:=''}"
1717

1818
# Config checks
1919
[ ! -f "/crontab" ] && echo "Error: crontab must be mounted at /crontab" && exit 128 || true

0 commit comments

Comments
 (0)