Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cron runs with different env variables #36

Open
tobias-kuendig opened this issue May 14, 2020 · 4 comments · May be fixed by #37
Open

cron runs with different env variables #36

tobias-kuendig opened this issue May 14, 2020 · 4 comments · May be fixed by #37

Comments

@tobias-kuendig
Copy link
Contributor

tobias-kuendig commented May 14, 2020

By default, cron does not care about the environment variables that are set in the Dockerfile. This means that all scheduled cronjobs will run with a completely different configuration ‒ in my case they run against the wrong database.

A workaround for this is to print all env variables to /etc/environment where crontab will pick them up.

Adding this line to the entrypoint script will fix this problem:

printenv  >> /etc/environment
@tobias-kuendig tobias-kuendig linked a pull request May 14, 2020 that will close this issue
@petehalverson
Copy link
Member

Thanks for the input. The cron examples need some attention.

Which method do you prefer using to trigger your cron process?

@tobias-kuendig
Copy link
Contributor Author

I'm currently using the ENABLE_CRON method, but mostly because of a current hosting setup that we don't control ourselfes, so it's easier to have everything in one container.

I do think the separate cron container is the nicer solution and I would prefer it for other projects.

@jacksun101
Copy link

By default, cron does not care about the environment variables that are set in the Dockerfile. This means that all scheduled cronjobs will run with a completely different configuration ‒ in my case they run against the wrong database.

A workaround for this is to print all env variables to /etc/environment where crontab will pick them up.

Adding this line to the entrypoint script will fix this problem:

printenv  >> /etc/environment

Thanks, tobias. But where exactly did you add the line in the entrypoint script?

@tobias-kuendig
Copy link
Contributor Author

I did add this right before the exec line:

# Put env variables to /etc/environtment
printenv | grep -v "no_proxy" >> /etc/environment

exec "$@"

I don't remember why the exclusion of the no_proxy variable was necessary in our case (it's been a while 🙈)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants