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

Make Docker-set environment variables accessible in cron jobs #188

Open
lmakarov opened this issue Jun 16, 2020 · 3 comments
Open

Make Docker-set environment variables accessible in cron jobs #188

lmakarov opened this issue Jun 16, 2020 · 3 comments
Assignees

Comments

@lmakarov
Copy link
Member

lmakarov commented Jun 16, 2020

Docker set environment variables (from Dockerfile ENV and docker-compose environment) are currently not visible in the environment of a cron job process.

We need to figure out a way to pass them correctly to cron jobs/etc. We could write to /etc/profile.d/docker-environment.sh, similar to how we handle secrets' conversion:

service-cli/7.3/startup.sh

Lines 107 to 108 in 113ca9f

# Write new variables to /etc/profile.d/secrets.sh to make them available for all users/sessions
echo "export ${key}=\"${secret_value}\"" | tee -a "/etc/profile.d/secrets.sh" >/dev/null

References:

Related issues: #128 , #187, docksal/docksal#1401

@prudloff-insite
Copy link

prudloff-insite commented Mar 18, 2022

We needed VIRTUAL_HOST to be exposed to our cron jobs (because we run some tasks that need to build absolute URLs) so we used this workaround in docksal.yml:

  cli:
    environment:
      - SECRET_VIRTUAL_HOST=${VIRTUAL_HOST}

This is not very clean because it hijacks the secret system for something else, so it would be better if Docksal could handle this automatically.

@prudloff-insite
Copy link

We noticed a related problem.
Our container was spammed with requests like this:

web_1    | 192.168.32.9 - - [18/Mar/2022:18:12:19 +0000] "GET /exec_in_progress_inside_cli HTTP/1.1" 200 21
web_1    | 192.168.32.9 - - [18/Mar/2022:18:12:19 +0000] "GET /exec_in_progress_inside_cli HTTP/1.1" 200 21
web_1    | 192.168.32.9 - - [18/Mar/2022:18:12:19 +0000] "GET /exec_in_progress_inside_cli HTTP/1.1" 200 21
web_1    | 192.168.32.9 - - [18/Mar/2022:18:12:19 +0000] "GET /exec_in_progress_inside_cli HTTP/1.1" 200 21
web_1    | 192.168.32.9 - - [18/Mar/2022:18:12:19 +0000] "GET /exec_in_progress_inside_cli HTTP/1.1" 200 21

It seems the problem is that we have a crontab calling bash, which loads ~/.profile which calls /opt/ping-web.sh but without the WEB_KEEPALIVE environment variable being set so the script calls curl in a loop.

This fixed the problem:

  cli:
    environment:
      - SECRET_WEB_KEEPALIVE=0

@nguyenlouis90
Copy link

I make a workaround by transfer ENV to crobtab through env file:

  • Dockerfile:
    CMD (env > /run/crontab.env) && (cron -f)

  • crobtab:
    * * * * * BASH_ENV=/run/crontab.env echo $(pwd) System online at date > /proc/1/fd/1 2>&1

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

No branches or pull requests

4 participants