Skip to content

Commit

Permalink
Add tzdata to allow changing timezone and use UTC for logging (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pastakhov authored Oct 21, 2024
1 parent 2e24f57 commit 6eb7918
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LABEL maintainers="[email protected]"
LABEL org.opencontainers.image.source=https://github.com/WikiTeq/docker-cron

# Install required tools
RUN apk add --no-cache jq curl docker-cli
RUN apk add --no-cache jq curl docker-cli tzdata

Check failure on line 7 in Dockerfile

View workflow job for this annotation

GitHub Actions / test

DL3018 warning: Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`

# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.32/supercronic-linux-amd64 \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
environment:
- COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}
- DEBUG=${CRON_DEBUG:-0}
- TZ=America/New_York

app:
build: ./app
Expand All @@ -38,4 +39,4 @@ The `example_compose.yml` file uses several environment variables. Make sure to
- `COMPOSE_PROJECT_NAME`: if defined, the cron looks for the jobs in this compose project only
- `DEBUG`: when it is `true`, it outputs more iformation for debugging
- `CRON_LOG_DIR`: the directory where cron puts the log files of the executed jobs, `/var/log/cron` by default

- `TZ` timezone used for scheduling the cron jobs
4 changes: 2 additions & 2 deletions update_cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CRON_LOG_DIR=${CRON_LOG_DIR:-/var/log/cron}
mkdir -p "$CRON_LOG_DIR"

timestamp() {
date "+%Y-%m-%d %H:%M:%S"
date -u "+%Y-%m-%d %H:%M:%S %Z"
}

# Function to extract specific cron job labels from a container
Expand Down Expand Up @@ -65,7 +65,7 @@ for container in $containers; do
# Check if both schedule and command labels are set
if [ -n "$job_schedule" ] && [ -n "$job_command" ]; then
target_container=$(docker inspect -f '{{.Name}}' "$container" | cut -c2-) # Remove leading /
cron_entry="$job_schedule docker exec $target_container sh -c '$job_command' 2>&1 | tee -a $CRON_LOG_DIR/\$(date +\%Y-\%m-\%d_\%H-\%M-\%S)-$job_key.log"
cron_entry="$job_schedule docker exec $target_container sh -c '$job_command' 2>&1 | tee -a $CRON_LOG_DIR/\$(date -u +\%Y-\%m-\%d_\%H-\%M-\%S_\%Z)_$job_key.log"
echo "$cron_entry" >> $CRON_FILE_NEW # Write in one line to the cron file
log "Scheduled task for $target_container: $cron_entry"
else
Expand Down

0 comments on commit 6eb7918

Please sign in to comment.