Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Fixes #56

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
653dcb4
chore: update alpine image.
SimplicityGuy Jul 16, 2022
9701554
fix: SC2086 shellcheck fixes.
SimplicityGuy Jul 16, 2022
82875ab
fix: SC2004 shellcheck fixes.
SimplicityGuy Jul 16, 2022
8c8e19c
fix: SC2006 shellcheck fixes.
SimplicityGuy Jul 16, 2022
4d94552
fix: SC2236 shellcheck fixes.
SimplicityGuy Jul 16, 2022
96e699c
fix: SC2162 shellcheck fixes.
SimplicityGuy Jul 16, 2022
dcd3e42
fix: SC2166 shellcheck fixes.
SimplicityGuy Jul 16, 2022
6d92c31
fix: SC2005 and SC2046 shellcheck fixes.
SimplicityGuy Jul 16, 2022
882fb13
fix: SC1001, SC2018, SC2019 shellcheck fixes.
SimplicityGuy Jul 16, 2022
f18275e
fix: simplifying logic.
SimplicityGuy Jul 16, 2022
99aa59d
chore: whitespace and dead code cleanup.
SimplicityGuy Jul 16, 2022
dc18a51
chore: reorganization.
SimplicityGuy Jul 16, 2022
c685687
chore: rename function to better describe what it does.
SimplicityGuy Jul 16, 2022
8426541
chore: adding error handling.
SimplicityGuy Jul 16, 2022
f0c3063
chore: standardize on {}.
SimplicityGuy Jul 16, 2022
7f29f06
chore: standardizing on env vars.
SimplicityGuy Jul 16, 2022
1d844f8
chore: missed one spot using previously set env var.
SimplicityGuy Jul 16, 2022
2b1c209
Merge pull request #1 from SimplicityGuy/fixes
SimplicityGuy Jul 16, 2022
8f1d920
chore: tabs to spaces.
SimplicityGuy Jul 16, 2022
c4da20c
fix: addressing issue with parsing json.
SimplicityGuy Jul 16, 2022
36ef24f
chore: omit additional items.
SimplicityGuy Jul 16, 2022
a523ad7
fix: reset COMMENT.
SimplicityGuy Jul 16, 2022
9316c9f
fix: address jq parsing errors when some properties are not set.
SimplicityGuy Jul 16, 2022
0643e9c
chore: moving line to be consistent.
SimplicityGuy Jul 16, 2022
08bbcef
fix: cleaning script creation.
SimplicityGuy Jul 16, 2022
e69b276
chore: nicer formatting.
SimplicityGuy Jul 16, 2022
31d0b73
chore: cleaning up echos.
SimplicityGuy Jul 16, 2022
9da4249
fix: moving the top level key name to the "name" property.
SimplicityGuy Jul 16, 2022
c530324
Merge pull request #2 from SimplicityGuy/additional-fixes
SimplicityGuy Jul 16, 2022
76b524f
chore: merge from private git repo.
SimplicityGuy Aug 7, 2022
035cd4a
feat: Major Updates
SimplicityGuy Feb 19, 2023
022399e
feat: adding TEST_MODE.
SimplicityGuy Mar 5, 2023
2b364b9
fix: fixing @random since it was broken and removing @every since it …
SimplicityGuy Mar 5, 2023
899ec9c
fix: allow multiple networks.
SimplicityGuy May 21, 2023
2b46bb2
chore: remove FUNDING.yml
SimplicityGuy May 21, 2023
ccaf605
chore: remove forked build.yml.
SimplicityGuy Jun 24, 2023
e3bfdeb
chore: move build to the repo rather than the dockerfiles repo.
SimplicityGuy Jun 24, 2023
4cfb302
fix: typo.
SimplicityGuy Jun 24, 2023
ac49cae
chore: remove arm64.
SimplicityGuy Jun 24, 2023
c7a8352
chore: update and upgrade require the cache.
SimplicityGuy Jun 24, 2023
c3a1963
feat: cleanup old images on the 15th of the month.
SimplicityGuy Jun 26, 2023
9c8b32c
chore: add discord notification to cleanup.
SimplicityGuy Jun 26, 2023
5aeeb19
fix: missed id.
SimplicityGuy Jun 26, 2023
a72e847
chore: update pre-commit.
SimplicityGuy Dec 31, 2024
5172ed0
fix: use docker user.
SimplicityGuy Dec 31, 2024
a87292b
chore: casing.
SimplicityGuy Dec 31, 2024
1a540df
fix: make /var/log/crontab writeable for everyone.
SimplicityGuy Jan 5, 2025
18880be
fix: LOG_DIR is not used anywhere, remove it.
SimplicityGuy Jan 5, 2025
799ccc8
fix: permissions for /opt/crontab.
SimplicityGuy Jan 5, 2025
176cb2e
fix: move back to root user to debug permissions more completely.
SimplicityGuy Jan 5, 2025
7725e2f
fix: handle users at Dockerfile instead of in entrypoint script.
SimplicityGuy Jan 11, 2025
165ea6a
chore: update pre-commit.
SimplicityGuy Jan 11, 2025
495c98f
fix: use rootless.
SimplicityGuy Jan 11, 2025
8cd6616
fix: using docker user and back to dind.
SimplicityGuy Jan 11, 2025
903fb60
fix: trying out gosu.
SimplicityGuy Jan 11, 2025
7b24975
fix: change group.
SimplicityGuy Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# 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']
github: [SimplicityGuy]
ko_fi: robertwlodarczyk
custom: [paypal.me/RWlodarczyk]
92 changes: 59 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,75 @@
name: build
---
name: crontab

on:
workflow_dispatch:
push:
branches:
- main
tags:
- '*'
pull_request:
branches:
- main
schedule:
- cron: '0 0 * * *'
- cron: '0 1 * * 6'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.actor }}/crontab

jobs:
multi:
build-crontab:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
- name: Checkout repository.
uses: actions/checkout@v3
with:
submodules: true

- name: Log in to the GitHub Container Registry.
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- if: github.ref == 'refs/heads/main'
name: Conditional(Set tag as `latest`)
run: echo "tag=willfarrell/crontab:latest" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker.
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=schedule,pattern={{date 'YYYYMMDD'}}

- if: startsWith(github.ref, 'refs/tags/')
name: Conditional(Set tag as `{version}`)
run: echo "tag=willfarrell/crontab:${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Set up QEMU.
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx.
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64

-
name: Build and push
uses: docker/build-push-action@v2
- name: Build and push Docker image to GitHub Container Registry.
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.tag }}
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: true
sbom: true

- name: Send notification to Discord.
uses: sarisia/[email protected]
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
39 changes: 39 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: cleanup

on:
schedule:
- cron: '0 0 15 * *'

env:
IMAGE_NAME: ${{ github.actor }}/docker-crontab

jobs:
cleanup-docker-crontab:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Delete Docker images older than a month.
id: cleanup-images
uses: snok/container-retention-policy@v2
with:
account-type: personal
cut-off: One month ago UTC
keep-at-least: 4
skip-tags: latest
image-names: ${{ env.IMAGE_NAME }}
token: ${{ secrets.GHCR_TOKEN }}

- name: Send notification to Discord.
uses: sarisia/[email protected]
if: always()
with:
title: ${{ env.IMAGE_NAME }}
description: |
succeded cleanup : ${{ steps.cleanup-images.outputs.deleted }}
failed cleanup : ${{ steps.cleanup-images.outputs.failed }}
webhook: ${{ secrets.DISCORD_WEBHOOK }}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.idea
*.iml

config.json
.vscode
.DS_Store

config.json
config.working.json

jobs/
projects/
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-yaml
- id: detect-aws-credentials
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 62833a79b57fcd1bc372b136911a0edca60c3dcb # frozen: 0.31.0
hooks:
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: e20b1ac5acb8aba0b49d3a9109c6e6b58684ee83 # frozen: 0.7.21
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm

- repo: https://github.com/hadolint/hadolint
rev: c3dc18df7a501f02a560a2cc7ba3c69a85ca01d3 # frozen: v2.13.1-beta
hooks:
- id: hadolint
69 changes: 55 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
FROM alpine:3.12 as rq-build
#hadolint ignore=DL3007
FROM alpine:latest AS builder

LABEL org.opencontainers.image.title="crontab builder" \
org.opencontainers.image.description="crontab builder" \
org.opencontainers.image.authors="[email protected]" \
org.opencontainers.image.source="https://github.com/SimplicityGuy/alertmanager-discord/blob/main/Dockerfile" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.created="$(date +'%Y-%m-%d')" \
org.opencontainers.image.base.name="docker.io/library/alpine"

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
#hadolint ignore=DL3018
RUN apk update --quiet && \
apk upgrade --quiet && \
apk add --quiet --no-cache \
upx && \
rm /var/cache/apk/* && \
wget --quiet 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
#hadolint ignore=DL3007
FROM docker:latest AS release

COPY --from=rq-build /root/rq /usr/local/bin
LABEL org.opencontainers.image.title="crontab" \
org.opencontainers.image.description="A docker job scheduler (aka crontab for docker)." \
org.opencontainers.image.authors="[email protected]" \
org.opencontainers.image.source="https://github.com/SimplicityGuy/docker-crontab/blob/main/Dockerfile" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.created="$(date +'%Y-%m-%d')" \
org.opencontainers.image.base.name="docker.io/library/docker"

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"]
#hadolint ignore=DL3018
RUN apk update --quiet && \
apk upgrade --quiet && \
apk add --quiet --no-cache \
bash \
coreutils \
curl \
gettext \
jq \
tini \
wget && \
apk add --quiet --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
gosu && \
rm /var/cache/apk/* && \
rm -rf /etc/periodic /etc/crontabs/root && \
adduser -S docker -D && \
mkdir -p ${HOME_DIR}/jobs && \
chown -R docker:root ${HOME_DIR}

USER docker

COPY --from=builder /usr/bin/rq/rq /usr/local/bin
COPY entrypoint.sh /opt

ENTRYPOINT ["/usr/bin/gosu", "docker", "/sbin/tini", "--", "/opt/entrypoint.sh"]

HEALTHCHECK --interval=5s --timeout=3s \
CMD ps aux | grep '[c]rond' || exit 1

CMD ["crond", "-f", "-d", "6", "-c", "/etc/crontabs"]
CMD ["crond", "-f", "-d", "7", "-c", "/etc/crontabs"]
Loading