Skip to content

Commit

Permalink
feat(azure-cron): working cron-jobs every 15mn
Browse files Browse the repository at this point in the history
  • Loading branch information
guilbep committed Mar 11, 2024
1 parent e99fdf8 commit 1536d84
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 44 deletions.
17 changes: 12 additions & 5 deletions azure-cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
FROM alpine
FROM python:3.12-alpine

RUN which crond && \
rm -rf /etc/periodic
RUN apk update
RUN apk add --update openssl curl jq sed

# /etc/periodic/hourly
# /etc/periodic/daily
# /etc/periodic/weekly
# /etc/periodic/monthly

COPY entrypoint.sh /entrypoint.sh
COPY entrypoint.sh /etc/periodic/15min/entrypoint
RUN chmod +x /entrypoint.sh /etc/periodic/15min/entrypoint


ENTRYPOINT ["/entrypoint.sh"]

# source: `docker run --rm -it alpine crond -h`
# -f | Foreground
# -l N | Set log level. Most verbose 0, default 8
CMD ["crond", "-f", "-l", "2"]
CMD ["crond", "-f", "-l", "8", "-L", "/var/log/cron.log"]
10 changes: 0 additions & 10 deletions azure-cron/cron-tab.txt

This file was deleted.

16 changes: 9 additions & 7 deletions azure-cron/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ if [ -z "$COUCHDB_HOST" ]; then
exit 1;
fi

echo "run apk update and install openssl, sed, curl, jq";
apk update;
apk add openssl;
apk add --update sed;
apk add curl;
apk add jq;
# echo "run apk update and install openssl, sed, curl, jq";
# apk update;
# apk add openssl;
# apk add --update sed;
# apk add curl;
# apk add jq;
# have tenand-id in env
# get json from https://login.microsoftonline.com/<tenant-id>/discovery/v2.0/keys

Expand Down Expand Up @@ -71,4 +71,6 @@ rm jwt_keys.json
# not necessary, keeping as a reference for future use
# curl -X POST "http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@${COUCHDB_HOST}:5984/_node/_local/_config/_reload"

echo "end of configuration jwt_keys update";
echo "end of configuration jwt_keys update $(date)";

[ "$#" -eq 0 ] && crond -f -l 8 -L /var/log/cron.log || exec "$@"
4 changes: 0 additions & 4 deletions couchdb/local.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ debug = true

; https://docs.couchdb.org/en/stable/api/server/authn.html#jwt-authentication
[jwt_keys]
; https://login.microsoftonline.com/<tenant-id>/discovery/v2.0/keys
; In format rsa:<kid> = -----BEGIN PUBLIC KEY-----\n<public-key>\n-----END PUBLIC KEY-----\n
; <public-key> can be get by "x509 -pubkey -noout -in cert.cer" where cert.cer is "-----BEGIN CERTIFICATE-----\n<x5c>\n-----END CERTIFICATE-----"
; See /azure/convert.sh
25 changes: 7 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ services:
depends_on:
- couchdb
- reverse-proxy
cron_couchdb:
image: python:3.12-alpine
command: /entrypoint.sh
azure-cron:
build: azure-cron
env_file:
- ./frontend/.env
environment:
- COUCHDB_USER=${COUCHDB_USER}
- COUCHDB_PASSWORD=${COUCHDB_PASSWORD}
- COUCHDB_HOST=couchdb
volumes:
- ./azure-cron/entrypoint.sh:/entrypoint.sh
- ./couchdb/local.ini:/local.ini
init_couchdb:
depends_on:
couchdb:
condition: service_healthy
init-couchdb:
image: python:3.12-alpine
command: /entrypoint.sh
env_file:
Expand All @@ -96,7 +95,7 @@ services:
- "traefik.http.services.couchdb.loadbalancer.server.port=5984"
- "traefik.http.middlewares.test-compress.compress=true"
depends_on:
init_couchdb:
init-couchdb:
condition: service_completed_successfully
expose:
- '5984'
Expand Down Expand Up @@ -139,16 +138,6 @@ services:
# - ./data-setup/.s3cfg:/root/.s3cfg
depends_on:
- nginx-minio
azure-cron:
container_name: azure-cron
build: ./azure-cron
init: true
environment:
- CUSTOM_ENV_VAR=foobar
volumes:
- ./azure-cron/cron-tab.txt:/var/spool/cron/crontabs/root
depends_on:
- couchdb
rest-api:
build: ./rest-api
env_file:
Expand Down

0 comments on commit 1536d84

Please sign in to comment.