1
0

Run export on a cron schedule

This commit is contained in:
Tony Grosinger 2022-07-23 09:31:32 -07:00
parent 55a85c51ea
commit b30c256190
3 changed files with 41 additions and 3 deletions

View File

@ -3,13 +3,20 @@ FROM dastapov/hledger:1.26 as hledger
FROM library/python:3.10-slim FROM library/python:3.10-slim
RUN apt install cron && \
apt-get clean && \
rm -rf /var/lib/{apt,dpkg,cache,log}
COPY --from=hledger /usr/bin/hledger /usr/bin/hledger COPY --from=hledger /usr/bin/hledger /usr/bin/hledger
COPY src /code COPY src /code
COPY docker-entrypoint.sh /entrypoint.sh
# TODO: Support more than one ledger file # TODO: Support more than one ledger file
ENV LEDGER_FILE=/data/all.ledger ENV LEDGER_FILE=/data/all.ledger
ENV OUTPUT_FILE=/data/all.sqlite ENV OUTPUT_FILE=/data/all.sqlite
ENV OVERWRITE_OUTPUT=true ENV OVERWRITE_OUTPUT=true
ENV CRONTAB_SCHEDULE="0 15 * * *"
ENTRYPOINT ["python", "/code/main.py"] ENTRYPOINT ["sh", "/entrypoint.sh"]
CMD ["crond", "-f", "-l", "0"]

View File

@ -6,6 +6,28 @@ Exports are not designed to be consistent across iterations. It is recommended t
## Usage ## Usage
TBD The default configuration is to run in a long-lived mode where the conversion will happen on a regular schedule defined by cron. You can use [crontab guru](https://crontab.guru) to build the value for the `CRONTAB_SCHEDULE` variable.
Currently planning on designing the container to be able to run as a long-lived job with a cron schedule for exporting. There will also be a method for running as a one-off. ```
docker run \
--name ledger-sqlite \
--env "LEDGER_FILE=/data/journal.ledger" \
--env "OUTPUT_FILE=/data/journal.sqlite" \
--env "CRONTAB_SCHEDULE=0 15 * * *" \
-v /path/to/data:/data \
ghcr.io/tgrosinger/ledger-sqlite:latest
```
Alternatively, a single conversion can be performed and the container will exit when complete. This can also be useful for debugging as the logs are easier to retrieve.
```
docker run \
--rm
--env "LEDGER_FILE=/data/journal.ledger" \
--env "OUTPUT_FILE=/data/journal.sqlite" \
-v /path/to/data:/data \
--entrypoint python \
ghcr.io/tgrosinger/ledger-sqlite:latest \
/code/main.py
```

9
docker-entrypoint.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
# Inspired by https://github.com/dkruger/docker-cron
cat << EOF > /var/spool/cron/crontabs/root
${CRONTAB_ENTRY} python /code/main.py
EOF
exec "$@"