forked from adiii717/docker-python-cronjob
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cb8a87
commit 299b089
Showing
3 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
FROM python:3.12-alpine | ||
FROM python:3.12-slim | ||
|
||
# Update apt-get package list, grab pre-requisites 'cron' & 'vim' | ||
RUN apt-get update && apt-get -y install cron vim | ||
|
||
# Set the working directory for following commands in this docker container to '/app' | ||
WORKDIR /app | ||
|
||
COPY crontab /etc/cron.d/crontab | ||
COPY extract.py /app/extract.py | ||
COPY extract.py ./extract.py | ||
|
||
# Make the crontab executable | ||
RUN chmod 0644 /etc/cron.d/crontab | ||
RUN /usr/bin/crontab /etc/cron.d/crontab | ||
|
||
# run crond as main process of container | ||
CMD ["/usr/sbin/crond", "-f", "-d", "0"] | ||
# Set the cron job | ||
RUN crontab /etc/cron.d/crontab | ||
|
||
# Create empty log (TAIL needs this) | ||
RUN touch /tmp/out.log | ||
|
||
# Run cron and tail the log | ||
CMD cron && tail -f /tmp/out.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# START CRON JOB | ||
* * * * * python3 /app/extract.py | ||
*/5 * * * * /usr/local/bin/python /app/extract.py >>/tmp/out.log 2>&1 | ||
# END CRON JOB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ | |
|
||
with open("/output/certs/key.pem", "w") as key_file: | ||
key_file.write(key) | ||
|
||
print("Cert extracted successfully.") |