Skip to content

Commit

Permalink
Rename cron image to util as it now more than just cron also use same…
Browse files Browse the repository at this point in the history
… util image for both cron services and cleanup compose file somewhat
  • Loading branch information
aequitas committed Oct 14, 2024
1 parent 371b7e7 commit c3cf41f
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 50 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
- image: grafana
dockerfile: docker/grafana.Dockerfile
target:
- image: cron
dockerfile: docker/cron.Dockerfile
- image: util
dockerfile: docker/util.Dockerfile
target:

outputs:
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
--volume /var/run/docker.sock:/var/run/docker.sock \\
--volume /opt/Internet.nl:/opt/Internet.nl \\
--network none \\
${{ env.DOCKER_REGISTRY }}/cron:${{ needs.build-docker.outputs.internetnl_version }} \\
${{ env.DOCKER_REGISTRY }}/util:${{ needs.build-docker.outputs.internetnl_version }} \\
/deploy.sh
EOF
Expand Down
4 changes: 4 additions & 0 deletions docker/cron-docker/periodic/15min/restart_nassl_worker_cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
# find nassl worker and restart the container(s)
docker ps --filter label=com.docker.compose.service=worker-nassl --quiet | xargs --no-run-if-empty docker restart
4 changes: 4 additions & 0 deletions docker/cron-docker/periodic/hourly/restart_worker_cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
# find worker and restart the container(s)
docker ps --filter label=com.docker.compose.service=worker --quiet | xargs --no-run-if-empty docker restart
4 changes: 4 additions & 0 deletions docker/cron-docker/periodic/weekly/docker_image_prune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
# remove unused images, --all to remove images not used by containers, --force to skip confirm prompt
docker image prune --all --force
2 changes: 1 addition & 1 deletion docker/cron/periodic/15min/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# for iterative development
# docker run -ti -e INTERNETNL_DOMAINNAME=internet.nl -v $PWD/docker/cron/periodic/15min/tests.py:/tests.py \
# ghcr.io/internetstandards/cron:latest /tests.py --debug
# ghcr.io/internetstandards/util:latest /tests.py --debug

import sys
import os
Expand Down
1 change: 0 additions & 1 deletion docker/defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ DOCKER_IMAGE_REDIS=redis:7.0-alpine
DOCKER_IMAGE_RABBITMQ=rabbitmq:3.12-management-alpine
DOCKER_IMAGE_POSTGRES=postgres:15.5-alpine
DOCKER_IMAGE_ROUTINATOR=nlnetlabs/routinator:v0.12.1
DOCKER_IMAGE_CRON_DOCKER=alpinelinux/docker-cli:v0.1.1
DOCKER_IMAGE_PROMETHEUS=prom/prometheus:v2.44.0
DOCKER_IMAGE_PROMETHEUS_ALERTMANAGER=prom/alertmanager:v0.27.0
DOCKER_IMAGE_POSTGRESQL_EXPORTER=prometheuscommunity/postgres-exporter:v0.12.0
Expand Down
File renamed without changes.
46 changes: 8 additions & 38 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,11 @@ services:
retries: 10

cron:
image: ${DOCKER_IMAGE_CRON:-${DOCKER_REGISTRY:-ghcr.io/internetstandards}/cron:${RELEASE}}
image: ${DOCKER_IMAGE_UTIL:-${DOCKER_REGISTRY:-ghcr.io/internetstandards}/util:${RELEASE}}
build:
context: ..
dockerfile: docker/cron.Dockerfile
dockerfile: docker/util.Dockerfile
command: crond -f -d7
environment:
- HOSTERS_HOF_URL
- DB_HOST=$IPV4_IP_POSTGRES_INTERNAL
Expand Down Expand Up @@ -717,21 +718,11 @@ services:

# cron daemon with access to Docker socket but no networking
cron-docker:
image: ${DOCKER_IMAGE_CRON_DOCKER}
command: crond -f -d7
configs:
# restart worker to prevent memory issues
- source: restart_worker_cron
target: /etc/periodic/hourly/restart_worker
mode: 0755
# restart nassl worker to prevent memory issues
- source: restart_nassl_worker_cron
target: /etc/periodic/15min/restart_nassl_worker
mode: 0755
# remove unused old docker images to reduce disk space usage
- source: docker_image_prune
target: /etc/periodic/weekly/docker-image-prune
mode: 0755
image: ${DOCKER_IMAGE_UTIL:-${DOCKER_REGISTRY:-ghcr.io/internetstandards}/util:${RELEASE}}
command: crond -f -d7 -c /etc/crontabs-docker
environment:
- AUTO_UPDATE_TO

restart: unless-stopped
logging:
driver: $LOGGING_DRIVER
Expand Down Expand Up @@ -1115,27 +1106,6 @@ configs:
headers:
subject: $ALERTMANAGER_SUBJECT
restart_worker_cron:
content: |
#!/bin/sh
set -e
# find worker and restart the container(s)
docker restart $(docker ps --filter label=com.docker.compose.service=worker --quiet)
restart_nassl_worker_cron:
content: |
#!/bin/sh
set -e
# find nassl worker and restart the container(s)
docker restart $(docker ps --filter label=com.docker.compose.service=worker-nassl --quiet)
docker_image_prune:
content: |
#!/bin/sh
set -e
# remove unused images, --all to remove images not used by containers, --force to skip confirm prompt
docker image prune --all --force
networks:
# disable default network
default:
Expand Down
15 changes: 11 additions & 4 deletions docker/cron.Dockerfile → docker/util.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ FROM alpine:3.20

RUN apk add --no-cache curl postgresql15 python3 py3-prometheus-client py3-requests jq docker-cli docker-cli-compose

# install cron tasks
COPY docker/cron/periodic /etc/periodic/

COPY docker/cron/deploy.sh /deploy.sh
# create separate periodic config for cron-docker service
RUN cp -r /etc/crontabs /etc/crontabs-docker
RUN sed -i 's/periodic/periodic-docker/' /etc/crontabs-docker/root

# install cron tasks for cron-docker
COPY docker/cron-docker/periodic /etc/periodic-docker/

# install deploy script
COPY docker/deploy.sh /deploy.sh

RUN mkdir -p /dist/docker
COPY docker/defaults.env /dist/docker/defaults.env
COPY docker/host-dist.env /dist/docker/host-dist.env
COPY docker/docker-compose.yml /dist/docker/docker-compose.yml
COPY docker/user_manage.sh /dist/docker/user_manage.sh
RUN chmod a-w /dist/docker/*

ARG RELEASE
ENV RELEASE=$RELEASE

# run crond in foreground and log output of crons
CMD crond -f -l2
5 changes: 2 additions & 3 deletions documentation/images/dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
}

with Diagram(NAME, show=False, direction="LR", outformat=["png"], graph_attr=graph_attr):
with Cluster("cron.Dockerfile"):
with Cluster("util.Dockerfile"):
[
DockerHub("alpine"),
File("cron/periodic/*"),
] >> Image("ghcr.io/internetstandards/cron")
] >> Image("ghcr.io/internetstandards/util")

with Cluster("grafana.Dockerfile"):
[
Expand Down Expand Up @@ -122,4 +122,3 @@
build_app >> image_linttest
build_linttest_deps >> Edge(label="dev dependencies") >> image_linttest
tools_dependencies >> image_linttest

0 comments on commit c3cf41f

Please sign in to comment.