【问题标题】:Run airflow commands on official Airflow docker-compose在官方 Airflow docker-compose 上运行气流命令
【发布时间】:2021-12-21 15:16:01
【问题描述】:

我正在使用官方的docker-compose.yml 在本地运行airflow 2.1.4,当我在airflow-init 服务(以下文件)上运行一些airflow 命令时,我无法理解会发生什么。

这是日志输出: log output

我不明白为什么我有重复的指示。我应该在单独的入口点脚本中从airflow-init 运行这个command 吗?

谢谢

airflow-init:
    <<: *airflow-common
    entrypoint: /bin/bash
    # yamllint disable rule:line-length
    command:
      - -c
      - |
        function ver() {
          printf "%04d%04d%04d%04d" $${1//./ }
        }
        airflow_version=$$(gosu airflow airflow version)
        airflow_version_comparable=$$(ver $${airflow_version})
        min_airflow_version=2.1.0
        min_airflow_version_comparable=$$(ver $${min_airflow_version})
        if (( airflow_version_comparable < min_airflow_version_comparable )); then
          echo
          echo -e "\033[1;31mERROR!!!: Too old Airflow version $${airflow_version}!\e[0m"
          echo "The minimum Airflow version supported: $${min_airflow_version}. Only use this or higher!"
          echo
          exit 1
        fi
        if [[ -z "${AIRFLOW_UID}" ]]; then
          echo
          echo -e "\033[1;33mWARNING!!!: AIRFLOW_UID not set!\e[0m"
          echo "If you are on Linux, you SHOULD follow the instructions below to set "
          echo "AIRFLOW_UID and AIRFLOW_GID environment variables, otherwise files will be owned by root."
          echo "For other operating systems you can get rid of the warning with manually created .env file:"
          echo "    See: https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html#setting-the-right-airflow-user"
          echo
        fi
        one_meg=1048576
        mem_available=$$(($$(getconf _PHYS_PAGES) * $$(getconf PAGE_SIZE) / one_meg))
        cpus_available=$$(grep -cE 'cpu[0-9]+' /proc/stat)
        disk_available=$$(df / | tail -1 | awk '{print $$4}')
        warning_resources="false"
        if (( mem_available < 4000 )) ; then
          echo
          echo -e "\033[1;33mWARNING!!!: Not enough memory available for Docker.\e[0m"
          echo "At least 4GB of memory required. You have $$(numfmt --to iec $$((mem_available * one_meg)))"
          echo
          warning_resources="true"
        fi
        if (( cpus_available < 2 )); then
          echo
          echo -e "\033[1;33mWARNING!!!: Not enough CPUS available for Docker.\e[0m"
          echo "At least 2 CPUs recommended. You have $${cpus_available}"
          echo
          warning_resources="true"
        fi
        if (( disk_available < one_meg * 10 )); then
          echo
          echo -e "\033[1;33mWARNING!!!: Not enough Disk space available for Docker.\e[0m"
          echo "At least 10 GBs recommended. You have $$(numfmt --to iec $$((disk_available * 1024 )))"
          echo
          warning_resources="true"
        fi
        if [[ $${warning_resources} == "true" ]]; then
          echo
          echo -e "\033[1;33mWARNING!!!: You have not enough resources to run Airflow (see above)!\e[0m"
          echo "Please follow the instructions to increase amount of resources available:"
          echo "   https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html#before-you-begin"
          echo
        fi
        mkdir -p /sources/logs /sources/dags /sources/plugins
        chown -R "${AIRFLOW_UID}:${AIRFLOW_GID}" /sources/{logs,dags,plugins}
        /entrypoint airflow connections import /sources/connections.json  
        /entrypoint airflow variables import /sources/variables.json
      
    # yamllint enable rule:line-length
    environment:
      <<: *airflow-common-env
      _AIRFLOW_DB_UPGRADE: 'true'
      _AIRFLOW_WWW_USER_CREATE: 'true'
      _AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow}
      _AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow}
    user: "0:${AIRFLOW_GID:-0}"
    volumes:
      - .:/sources

【问题讨论】:

    标签: docker airflow


    【解决方案1】:

    因为您正在使用 _PIP_ADDITIONAL_REQUIREMENTS,如果您想尝试一下,这只是一个方便的工具,可以快速安装依赖项。

    您应该将它用于其他任何事情,因为您将观察您在此处看到的内容 - 每次运行任何命令时都会动态安装新的依赖项。

    正如这里所解释的:https://airflow.apache.org/docs/docker-stack/entrypoint.html#installing-additional-requirements 当您想要添加依赖项时,您应该构建并使用您自己的自定义映像。在此处阅读更多信息:https://airflow.apache.org/docs/docker-stack/build.html,您可以在其中找到说明和大量有用的示例。

    【讨论】:

    • 完全有道理!谢谢
    • 我不认为这涵盖了所有内容。我已将安装 python 包的部分移动到自定义映像,但我仍然在我的日志中得到重复的说明。我相信这是由于重复了 /entrypoint,但是我没有找到另一种运行我需要的气流命令的方法
    • 您的 docker-compose 中可能仍然设置了 _PIP_ADDITIONAL_REQUIREMENTS。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多