mcuadros/ofelia

Provide the ability to use the same environment as a running container for `job-run` jobs

kopf opened this issue · 3 comments

I'd love to use job-run to run my cronjobs - spinning up a new container to service each cronjob. However, my cronjobs (primarily django management jobs) require an awful lot of environment variables to be set in order to do their job.

Therefore, the easiest solution is to simply run them on an already running webserver container. The only problem with this is that they're killed if the webserver container is cycled.

So - wouldn't it be great if we could provide a simple "copy the environment of container X" directive for job-run jobs? Is this possible? If so, I'll have a look at its implementation. If not, thank you for letting me know and saving me the time and effort.

I wonder if job-run can be used with Docker labels (see my question #270)
This could be a solution to your problement as you could simply copy paste in docker-compose.yml environment variables from one service to an another one.

kopf commented

@scls19fr - this is undesirable as it would break the DRY principle. You'd have multiple places to update environment variables when they're changed.

I understand. Maybe you can put values into a .env file like so

MYSERVER_NAME=myserver
MYSERVER_EMAIL=me@domain.com

and use docker-compose.yml like so

environment:
  - MYSERVER_NAME=${MYSERVER_NAME}
  - MYSERVER_EMAIL=${MYSERVER_EMAIL}

so you won't have to modify you docker-compose into several places... just one your .env file (to avoid to repeat yourself).

That's just an idea