Last week, I needed to create a docker image doing a simple thing:
- downloading 1 XML file
- converting it to JSON
- serve both files
But I've a hard part: every 15 minutes, I need to look if a new version of the XML file is available and in case, running the entire process.
Let's go to see how I did it
PermalinkRequirements
PermalinkDocker image creation
I use Python container based on alpine linux as the base, adding an environment variable to avoid PIP cache.
To have multiple processes inside the contianer, I use s6-overlay and I think to rewrite the global path because by default it's not including the path where Python binaries (pip, python) are installed.
PermalinkProcess with dependencies and type of run
S6-overlay permits to define dependencies between processus and it's exactly what I need because:
- docker-entrypoint needs to run before running the real nginx daemon but without persistance, it's a oneshot at boot
- cron daemon needs to run in background and has 0 dependency
- nginx unit needs to run in background when docker-entrypoint has ended the configuration
Permalinkcron
To setup cron, we have few steps inside the Dockerfile:
- copy the shell script to execute cron as the daemon
- set this script has "longrun"
- add it to be run at boot
Permalinknginx unit
Steps:
- copy the shell script to execute nginx unit as a daemon
- set unit log file to output on /dev/stdout
- set nginx access log to output on /dev/stdout
- set this script has "longrun"
- add docker-entrypoint has a dependency
- add it to be run at boot
Permalinkdocker-entrypoint
Steps:
- create the directory where we'll had config files
- set this script has "oneshot"
- set the command to execute the docker-entrypoint (I don't copy the file like for other service)
PermalinkEntrypoint
Finally, we'll use s6 has the entrypoint for this container
PermalinkLink
The repository: xmltv_tnt_json_unit