docksal / service-cli

CLI service image for Docksal
https://docksal.io
MIT License
19 stars 45 forks source link

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

Open lmakarov opened 4 years ago

lmakarov commented 4 years ago

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: https://github.com/docksal/service-cli/blob/113ca9fd22b888b520c2b9bd50e7b2127207a226/7.3/startup.sh#L107-L108

References:

Related issues: #128 , #187, https://github.com/docksal/docksal/issues/1401

prudloff-insite commented 2 years ago

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 commented 2 years ago

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 commented 5 months ago

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