Airflow 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

1 # Licensed to the Apache Software Foundation (ASF) under one

2 # or more contributor license agreements. See the NOTICE file


3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17 #
18
19 # Basic Airflow cluster configuration for CeleryExecutor with Redis and PostgreSQL.
20 #
21 # WARNING: This configuration is for local development. Do not use it in a production
deployment.
22 #
23 # This configuration supports basic configuration using environment variables or an .env
file
24 # The following variables are supported:
25 #
26 # AIRFLOW_IMAGE_NAME - Docker image name used to run Airflow.
27 # Default: apache/airflow:2.6.1
28 # AIRFLOW_UID - User ID in Airflow containers
29 # Default: 50000
30 # AIRFLOW_PROJ_DIR - Base path to which all the files will be volumed.
31 # Default: .
32 # Those configurations are useful mostly in case of standalone testing/running Airflow
in test/try-out mode
33 #
34 # _AIRFLOW_WWW_USER_USERNAME - Username for the administrator account (if requested).
35 # Default: airflow
36 # _AIRFLOW_WWW_USER_PASSWORD - Password for the administrator account (if requested).
37 # Default: airflow
38 # _PIP_ADDITIONAL_REQUIREMENTS - Additional PIP requirements to add when starting all
containers.
39 # Use this option ONLY for quick checks. Installing
requirements at container
40 # startup is done EVERY TIME the service is started.
41 # A better way is to build a custom image or extend the
official image
42 # as described in
https://airflow.apache.org/docs/docker-stack/build.html.
43 # Default: ''
44 #
45 # Feel free to modify this file to suit your needs.
46 ---
47 version: '3.8'
48 x-airflow-common:
49 &airflow-common
50 # In order to add custom dependencies or upgrade provider packages you can use your
extended image.
51 # Comment the image line, place your Dockerfile in the directory where you placed the
docker-compose.yaml
52 # and uncomment the "build" line below, Then run `docker-compose build` to build the
images.
53 image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.6.1}
54 # build: .
55 environment:
56 &airflow-common-env
57 AIRFLOW__CORE__EXECUTOR: CeleryExecutor
58 AIRFLOW__DATABASE__SQL_ALCHEMY_CONN:
postgresql+psycopg2://airflow:airflow@postgres/airflow
59 # For backward compatibility, with Airflow <2.3
60 AIRFLOW__CORE__SQL_ALCHEMY_CONN:
postgresql+psycopg2://airflow:airflow@postgres/airflow
61 AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://airflow:airflow@postgres/airflow
62 AIRFLOW__CELERY__BROKER_URL: redis://:@redis:6379/0
63 AIRFLOW__CORE__FERNET_KEY: ''
64 AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true'
65 AIRFLOW__CORE__LOAD_EXAMPLES: 'true'
66 AIRFLOW__API__AUTH_BACKENDS:
'airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session'
67 # yamllint disable rule:line-length
68 # Use simple http server on scheduler for health checks
69 # See
https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/l
ogging-monitoring/check-health.html#scheduler-health-check-server
70 # yamllint enable rule:line-length
71 AIRFLOW__SCHEDULER__ENABLE_HEALTH_CHECK: 'true'
72 # WARNING: Use _PIP_ADDITIONAL_REQUIREMENTS option ONLY for a quick checks
73 # for other purpose (development, test and especially production usage) build/extend
Airflow image.
74 _PIP_ADDITIONAL_REQUIREMENTS: ${_PIP_ADDITIONAL_REQUIREMENTS:-}
75 volumes:
76 - ${AIRFLOW_PROJ_DIR:-.}/dags:/opt/airflow/dags
77 - ${AIRFLOW_PROJ_DIR:-.}/logs:/opt/airflow/logs
78 - ${AIRFLOW_PROJ_DIR:-.}/config:/opt/airflow/config
79 - ${AIRFLOW_PROJ_DIR:-.}/plugins:/opt/airflow/plugins
80 user: "${AIRFLOW_UID:-50000}:0"
81 depends_on:
82 &airflow-common-depends-on
83 redis:
84 condition: service_healthy
85 postgres:
86 condition: service_healthy
87
88 services:
89 postgres:
90 image: postgres:13
91 environment:
92 POSTGRES_USER: airflow
93 POSTGRES_PASSWORD: airflow
94 POSTGRES_DB: airflow
95 volumes:
96 - postgres-db-volume:/var/lib/postgresql/data
97 healthcheck:
98 test: ["CMD", "pg_isready", "-U", "airflow"]
99 interval: 10s
100 retries: 5
101 start_period: 5s
102 restart: always
103
104 redis:
105 image: redis:latest
106 expose:
107 - 6379
108 healthcheck:
109 test: ["CMD", "redis-cli", "ping"]
110 interval: 10s
111 timeout: 30s
112 retries: 50
113 start_period: 30s
114 restart: always
115
116 airflow-webserver:
117 <<: *airflow-common
118 command: webserver
119 ports:
120 - "8080:8080"
121 healthcheck:
122 test: ["CMD", "curl", "--fail", "http://localhost:8080/health"]
123 interval: 30s
124 timeout: 10s
125 retries: 5
126 start_period: 30s
127 restart: always
128 depends_on:
129 <<: *airflow-common-depends-on
130 airflow-init:
131 condition: service_completed_successfully
132
133 airflow-scheduler:
134 <<: *airflow-common
135 command: scheduler
136 healthcheck:
137 test: ["CMD", "curl", "--fail", "http://localhost:8974/health"]
138 interval: 30s
139 timeout: 10s
140 retries: 5
141 start_period: 30s
142 restart: always
143 depends_on:
144 <<: *airflow-common-depends-on
145 airflow-init:
146 condition: service_completed_successfully
147
148 airflow-worker:
149 <<: *airflow-common
150 command: celery worker
151 healthcheck:
152 test:
153 - "CMD-SHELL"
154 - 'celery --app airflow.executors.celery_executor.app inspect ping -d
"celery@$${HOSTNAME}"'
155 interval: 30s
156 timeout: 10s
157 retries: 5
158 start_period: 30s
159 environment:
160 <<: *airflow-common-env
161 # Required to handle warm shutdown of the celery workers properly
162 # See
https://airflow.apache.org/docs/docker-stack/entrypoint.html#signal-propagation
163 DUMB_INIT_SETSID: "0"
164 restart: always
165 depends_on:
166 <<: *airflow-common-depends-on
167 airflow-init:
168 condition: service_completed_successfully
169
170 airflow-triggerer:
171 <<: *airflow-common
172 command: triggerer
173 healthcheck:
174 test: ["CMD-SHELL", 'airflow jobs check --job-type TriggererJob --hostname
"$${HOSTNAME}"']
175 interval: 30s
176 timeout: 10s
177 retries: 5
178 start_period: 30s
179 restart: always
180 depends_on:
181 <<: *airflow-common-depends-on
182 airflow-init:
183 condition: service_completed_successfully
184
185 airflow-init:
186 <<: *airflow-common
187 entrypoint: /bin/bash
188 # yamllint disable rule:line-length
189 command:
190 - -c
191 - |
192 function ver() {
193 printf "%04d%04d%04d%04d" $${1//./ }
194 }
195 airflow_version=$$(AIRFLOW__LOGGING__LOGGING_LEVEL=INFO && gosu airflow airflow
version)
196 airflow_version_comparable=$$(ver $${airflow_version})
197 min_airflow_version=2.2.0
198 min_airflow_version_comparable=$$(ver $${min_airflow_version})
199 if (( airflow_version_comparable < min_airflow_version_comparable )); then
200 echo
201 echo -e "\033[1;31mERROR!!!: Too old Airflow version $${airflow_version}!\e[0m"
202 echo "The minimum Airflow version supported: $${min_airflow_version}. Only use
this or higher!"
203 echo
204 exit 1
205 fi
206 if [[ -z "${AIRFLOW_UID}" ]]; then
207 echo
208 echo -e "\033[1;33mWARNING!!!: AIRFLOW_UID not set!\e[0m"
209 echo "If you are on Linux, you SHOULD follow the instructions below to set "
210 echo "AIRFLOW_UID environment variable, otherwise files will be owned by root."
211 echo "For other operating systems you can get rid of the warning with manually
created .env file:"
212 echo " See:
https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/inde
x.html#setting-the-right-airflow-user"
213 echo
214 fi
215 one_meg=1048576
216 mem_available=$$(($$(getconf _PHYS_PAGES) * $$(getconf PAGE_SIZE) / one_meg))
217 cpus_available=$$(grep -cE 'cpu[0-9]+' /proc/stat)
218 disk_available=$$(df / | tail -1 | awk '{print $$4}')
219 warning_resources="false"
220 if (( mem_available < 4000 )) ; then
221 echo
222 echo -e "\033[1;33mWARNING!!!: Not enough memory available for Docker.\e[0m"
223 echo "At least 4GB of memory required. You have $$(numfmt --to iec
$$((mem_available * one_meg)))"
224 echo
225 warning_resources="true"
226 fi
227 if (( cpus_available < 2 )); then
228 echo
229 echo -e "\033[1;33mWARNING!!!: Not enough CPUS available for Docker.\e[0m"
230 echo "At least 2 CPUs recommended. You have $${cpus_available}"
231 echo
232 warning_resources="true"
233 fi
234 if (( disk_available < one_meg * 10 )); then
235 echo
236 echo -e "\033[1;33mWARNING!!!: Not enough Disk space available for
Docker.\e[0m"
237 echo "At least 10 GBs recommended. You have $$(numfmt --to iec
$$((disk_available * 1024 )))"
238 echo
239 warning_resources="true"
240 fi
241 if [[ $${warning_resources} == "true" ]]; then
242 echo
243 echo -e "\033[1;33mWARNING!!!: You have not enough resources to run Airflow
(see above)!\e[0m"
244 echo "Please follow the instructions to increase amount of resources
available:"
245 echo "
https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/inde
x.html#before-you-begin"
246 echo
247 fi
248 mkdir -p /sources/logs /sources/dags /sources/plugins
249 chown -R "${AIRFLOW_UID}:0" /sources/{logs,dags,plugins}
250 exec /entrypoint airflow version
251 # yamllint enable rule:line-length
252 environment:
253 <<: *airflow-common-env
254 _AIRFLOW_DB_UPGRADE: 'true'
255 _AIRFLOW_WWW_USER_CREATE: 'true'
256 _AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow}
257 _AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow}
258 _PIP_ADDITIONAL_REQUIREMENTS: ''
259 user: "0:0"
260 volumes:
261 - ${AIRFLOW_PROJ_DIR:-.}:/sources
262
263 airflow-cli:
264 <<: *airflow-common
265 profiles:
266 - debug
267 environment:
268 <<: *airflow-common-env
269 CONNECTION_CHECK_MAX_COUNT: "0"
270 # Workaround for entrypoint issue. See:
https://github.com/apache/airflow/issues/16252
271 command:
272 - bash
273 - -c
274 - airflow
275
276 # You can enable flower by adding "--profile flower" option e.g. docker-compose
--profile flower up
277 # or by explicitly targeted on the command line e.g. docker-compose up flower.
278 # See: https://docs.docker.com/compose/profiles/
279 flower:
280 <<: *airflow-common
281 command: celery flower
282 profiles:
283 - flower
284 ports:
285 - "5555:5555"
286 healthcheck:
287 test: ["CMD", "curl", "--fail", "http://localhost:5555/"]
288 interval: 30s
289 timeout: 10s
290 retries: 5
291 start_period: 30s
292 restart: always
293 depends_on:
294 <<: *airflow-common-depends-on
295 airflow-init:
296 condition: service_completed_successfully
297
298 volumes:
299 postgres-db-volume:
300

You might also like