docker-airflow icon indicating copy to clipboard operation
docker-airflow copied to clipboard

How to set up airlfow variables?

Open renjithpaul27 opened this issue 4 years ago • 7 comments

Is it possible to set airflow variables in docker compose? I have a bunch of variables available as json and want to see how it can be supplied in docker compose file so that i can avoid the manual step of setting these variables when the code is migrated to diff envs. Can someone please help on this?

renjithpaul27 avatar Jun 20 '20 16:06 renjithpaul27

Hi, have you figured any way out to resolve this? Even I am facing the same issue.

neilharia7 avatar Jun 25 '20 12:06 neilharia7

Hi, have you figured any way out to resolve this? Even I am facing the same issue.

Not yet. One idea is to use the entrypoint.sh and docker file for airflow and then declare the variables there. But it wont give the comfort level in using this.

renjithpaul27 avatar Jun 25 '20 12:06 renjithpaul27

Variables are set in DB. So entrypoint is your bet.

swapniel99 avatar Jul 24 '20 17:07 swapniel99

Hi, just found that Airflow 1.10.10 can read variables from environment. There's a PR for upgrading to 1.10.11. See here https://airflow.apache.org/docs/stable/concepts.html?highlight=variable#storing-variables-in-environment-variables

runa avatar Jul 24 '20 21:07 runa

I'm trying to set some variables from a JSON file for LocalExecutor. Could someone provide an example of how to set the variables? I'm kind of new to both airflow and docker.

I think I need to add the command airflow variables --import /path/to/variables.json somewhere before or after the exec airflow webserver line in the case statement

case "$1" in
  webserver)
    airflow initdb
    if [ "$AIRFLOW__CORE__EXECUTOR" = "LocalExecutor" ] || [ "$AIRFLOW__CORE__EXECUTOR" = "SequentialExecutor" ]; then
      # With the "Local" and "Sequential" executors it should all run in one container.
      airflow scheduler &
    fi
    exec airflow webserver
    airflow variables --import /path/to/variables   # <----
    ;;
  worker|scheduler)

I tried this, but no variables seem to get added

apanagar avatar Jul 30 '20 03:07 apanagar

figured it out, I just reversed the lines, so

    airflow variables --import /path/to/variables.json   # <----
    exec airflow webserver

apanagar avatar Jul 31 '20 01:07 apanagar

airflow variables import /path/to/variables.json it works for me

evgeniikozhanov avatar Feb 12 '23 15:02 evgeniikozhanov