From f18bb9a288c036cade78e30d5d4178b6793c2f56 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 20 Mar 2023 22:36:17 -0400 Subject: [PATCH 1/2] Have the cron schedule be overridden during the build step --- Dockerfile | 8 +++++--- README.md | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8569dcf..c3b39f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM alpine:latest -# docker run --rm -it -v /home/ace/Scripts/nfs-dynamic-dns:/root - COPY *.tcl /root/ COPY packages/* /root/packages/ COPY LICENSE /root/LICENSE @@ -20,6 +18,10 @@ RUN curl -sSL https://github.com/tcltk/tcllib/archive/release.tar.gz | tar -xz - rm -rf /tmp/tcllib* RUN mkdir /logs + WORKDIR /root -RUN echo "$(crontab -l 2>&1; echo "*/60 * * * * /root/dns.tcl")" | crontab - + +ARG CRON_SCHEDULE="*/30 * * * *" +RUN echo "$(crontab -l 2>&1; echo "${CRON_SCHEDULE} /root/dns.tcl")" | crontab - + CMD ["crond", "-f", "2>&1"] diff --git a/README.md b/README.md index 0262a8f..46968e4 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,30 @@ to run the container locally and be put into a shell where you can run `./dns.tc If your setup uses environment variables, you will also need to add the `--env-file` argument (or specify variables individually with [the `-e` docker flag](https://docs.docker.com/engine/reference/run/#env-environment-variables)). The `--env-file` option is for [docker run](https://docs.docker.com/engine/reference/commandline/run/) and the env file format can be found [here](https://docs.docker.com/compose/env-file/). ## Scheduling -It can even be setup to run as a cron job to completely automate this process. Something such as: +It can be setup to run as a cron job to completely automate this process. Something such as: > @hourly /usr/local/bin/tclsh /scripts/nfs-dynamic-dns/dns.tcl +### Docker +When using the Docker file, it's by default scheduled to run every 30 minutes. However, this is configurable when building the +container. The `CRON_SCHEDULE` [build arg](https://docs.docker.com/engine/reference/builder/#arg) can be overriden. + +With docker, the build step (step 2) can be done like this: +`$ docker build --build-arg CRON_SCHEDULE="*/5 * * * *" -t nfs-dynamic-dns .` + +With docker compose, it can be done like this: +```yaml +version: "3" + +services: + nfs-dynamic-dns: + image: nfs-dynamic-dns + build: + context: ./nfs-dynamic-dns + args: + - CRON_SCHEDULE=*/5 * * * * + container_name: nfs-dynamic-dns +... + ``` + ## Troubleshooting The script communicates with NearlyFreeSpeech.NET via its RESTful API. Specifics about the API can be found [here](https://members.nearlyfreespeech.net/wiki/API/Introduction). From e1b175f33586ca46097f3c87d571e3c76089cd14 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 20 Mar 2023 22:40:47 -0400 Subject: [PATCH 2/2] Extra line in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 46968e4..80794be 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ When using the Docker file, it's by default scheduled to run every 30 minutes. H container. The `CRON_SCHEDULE` [build arg](https://docs.docker.com/engine/reference/builder/#arg) can be overriden. With docker, the build step (step 2) can be done like this: + `$ docker build --build-arg CRON_SCHEDULE="*/5 * * * *" -t nfs-dynamic-dns .` With docker compose, it can be done like this: