Skip to content

Commit 9f33f0c

Browse files
authored
Merge pull request #35 from puckel/refacto_executor
- Modify entrypoint.sh to select the type of executor. - Split docker-compose.yml definition for local or celery executor - Load examples or not
2 parents 7584530 + 9839fca commit 9f33f0c

File tree

5 files changed

+118
-39
lines changed

5 files changed

+118
-39
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# VERSION 1.7.1.3
1+
# VERSION 1.7.1.3-2
22
# AUTHOR: Matthieu "Puckel_" Roisil
33
# DESCRIPTION: Basic Airflow container
44
# BUILD: docker build --rm -t puckel/docker-airflow

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ For example, if you need to install [Extra Packages](http://pythonhosted.org/air
2727

2828
## Usage
2929

30-
Start the stack (postgres, rabbitmq, airflow-webserver, airflow-scheduler airflow-flower & airflow-worker):
30+
By default, docker-airflow run Airflow with **SequentialExecutor** :
3131

32-
docker-compose up -d
32+
docker run -d -p 8080:8080 puckel/docker-airflow
33+
34+
If you want to run other executor, you've to use the docker-compose.yml files provided in this repository.
35+
36+
For **LocalExecutor** :
37+
38+
docker-compose -f docker-compose-LocalExecutor.yml up -d
39+
40+
For **CeleryExecutor** :
41+
42+
docker-compose -f docker-compose-CeleryExecutor.yml up -d
43+
44+
NB : If you don't want to have DAGs example loaded (default=True), you've to set the following environment variable :
45+
46+
`LOAD_EX=n`
47+
48+
docker run -d -p 8080:8080 -e LOAD_EX=n puckel/docker-airflow
3349

3450
If you want to use Ad hoc query, make sure you've configured connections:
3551
Go to Admin -> Connections and Edit "mysql_default" set this values (equivalent to values in airflow.cfg/docker-compose.yml) :
@@ -48,10 +64,6 @@ Check [Airflow Documentation](http://pythonhosted.org/airflow/)
4864

4965
When using OSX with boot2docker, use: open http://$(boot2docker ip):8080
5066

51-
## Run the test "tutorial"
52-
53-
docker exec dockerairflow_webserver_1 airflow backfill tutorial -s 2015-05-01 -e 2015-06-01
54-
5567
## Scale the number of workers
5668

5769
Easy scaling using docker-compose:
Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
version: '2'
22
services:
3-
postgres:
4-
image: postgres
5-
environment:
6-
- POSTGRES_USER=airflow
7-
- POSTGRES_PASSWORD=airflow
8-
- POSTGRES_DB=airflow
9-
103
rabbitmq:
114
image: rabbitmq:3-management
125
restart: always
@@ -18,40 +11,58 @@ services:
1811
- RABBITMQ_DEFAULT_PASS=airflow
1912
- RABBITMQ_DEFAULT_VHOST=airflow
2013

14+
postgres:
15+
image: postgres
16+
environment:
17+
- POSTGRES_USER=airflow
18+
- POSTGRES_PASSWORD=airflow
19+
- POSTGRES_DB=airflow
20+
2121
webserver:
22-
image: puckel/docker-airflow:1.7.1.3
22+
image: puckel/docker-airflow:1.7.1.3-2
2323
restart: always
24+
depends_on:
25+
- postgres
26+
- rabbitmq
2427
environment:
25-
- AIRFLOW_HOME=/usr/local/airflow
28+
# - LOAD_EX=n
29+
- EXECUTOR=Celery
2630
# volumes:
2731
# - /localpath/to/dags:/usr/local/airflow/dags
2832
ports:
2933
- "8080:8080"
3034
command: webserver
3135

3236
flower:
33-
image: puckel/docker-airflow:1.7.1.3
37+
image: puckel/docker-airflow:1.7.1.3-2
3438
restart: always
39+
depends_on:
40+
- rabbitmq
3541
environment:
36-
- AIRFLOW_HOME=/usr/local/airflow
42+
- EXECUTOR=Celery
3743
ports:
3844
- "5555:5555"
3945
command: flower
4046

4147
scheduler:
42-
image: puckel/docker-airflow:1.7.1.3
48+
image: puckel/docker-airflow:1.7.1.3-2
4349
restart: always
50+
depends_on:
51+
- webserver
4452
# volumes:
4553
# - /localpath/to/dags:/usr/local/airflow/dags
4654
environment:
47-
- AIRFLOW_HOME=/usr/local/airflow
55+
# - LOAD_EX=n
56+
- EXECUTOR=Celery
4857
command: scheduler -n 5
4958

5059
worker:
51-
image: puckel/docker-airflow:1.7.1.3
60+
image: puckel/docker-airflow:1.7.1.3-2
5261
restart: always
62+
depends_on:
63+
- scheduler
5364
# volumes:
5465
# - /localpath/to/dags:/usr/local/airflow/dags
5566
environment:
56-
- AIRFLOW_HOME=/usr/local/airflow
67+
- EXECUTOR=Celery
5768
command: worker

docker-compose-LocalExecutor.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: '2'
2+
services:
3+
postgres:
4+
image: postgres
5+
environment:
6+
- POSTGRES_USER=airflow
7+
- POSTGRES_PASSWORD=airflow
8+
- POSTGRES_DB=airflow
9+
10+
webserver:
11+
image: puckel/docker-airflow:1.7.1.3-2
12+
restart: always
13+
depends_on:
14+
- postgres
15+
environment:
16+
# - LOAD_EX=n
17+
- EXECUTOR=Local
18+
# volumes:
19+
# - /localpath/to/dags:/usr/local/airflow/dags
20+
ports:
21+
- "8080:8080"
22+
command: webserver
23+
24+
scheduler:
25+
image: puckel/docker-airflow:1.7.1.3-2
26+
restart: always
27+
depends_on:
28+
- webserver
29+
# volumes:
30+
# - /localpath/to/dags:/usr/local/airflow/dags
31+
environment:
32+
# - LOAD_EX=n
33+
- EXECUTOR=Local
34+
command: scheduler -n 5

script/entrypoint.sh

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
AIRFLOW_HOME="/usr/local/airflow"
34
CMD="airflow"
45
TRY_LOOP="10"
56
POSTGRES_HOST="postgres"
@@ -8,28 +9,19 @@ RABBITMQ_HOST="rabbitmq"
89
RABBITMQ_CREDS="airflow:airflow"
910
FERNET_KEY=$(python -c "from cryptography.fernet import Fernet; FERNET_KEY = Fernet.generate_key().decode(); print FERNET_KEY")
1011

11-
# Generate Fernet key
12-
sed -i "s/{FERNET_KEY}/${FERNET_KEY}/" $AIRFLOW_HOME/airflow.cfg
13-
14-
# wait for rabbitmq
15-
if [ "$1" = "webserver" ] || [ "$1" = "worker" ] || [ "$1" = "scheduler" ] || [ "$1" = "flower" ] ; then
16-
j=0
17-
while ! curl -sI -u $RABBITMQ_CREDS http://$RABBITMQ_HOST:15672/api/whoami |grep '200 OK'; do
18-
j=`expr $j + 1`
19-
if [ $j -ge $TRY_LOOP ]; then
20-
echo "$(date) - $RABBITMQ_HOST still not reachable, giving up"
21-
exit 1
22-
fi
23-
echo "$(date) - waiting for RabbitMQ... $j/$TRY_LOOP"
24-
sleep 5
25-
done
12+
# Load DAGs exemples (default: Yes)
13+
if [ "x$LOAD_EX" = "xn" ]; then
14+
sed -i "s/load_examples = True/load_examples = False/" "$AIRFLOW_HOME"/airflow.cfg
2615
fi
2716

17+
# Generate Fernet key
18+
sed -i "s|\$FERNET_KEY|$FERNET_KEY|" "$AIRFLOW_HOME"/airflow.cfg
19+
2820
# wait for DB
2921
if [ "$1" = "webserver" ] || [ "$1" = "worker" ] || [ "$1" = "scheduler" ] ; then
3022
i=0
3123
while ! nc $POSTGRES_HOST $POSTGRES_PORT >/dev/null 2>&1 < /dev/null; do
32-
i=`expr $i + 1`
24+
i=$((i+1))
3325
if [ $i -ge $TRY_LOOP ]; then
3426
echo "$(date) - ${POSTGRES_HOST}:${POSTGRES_PORT} still not reachable, giving up"
3527
exit 1
@@ -44,4 +36,34 @@ if [ "$1" = "webserver" ] || [ "$1" = "worker" ] || [ "$1" = "scheduler" ] ; the
4436
sleep 5
4537
fi
4638

47-
exec $CMD "$@"
39+
# If we use docker-compose, we use Celery (rabbitmq container).
40+
if [ "x$EXECUTOR" = "xCelery" ]
41+
then
42+
# wait for rabbitmq
43+
if [ "$1" = "webserver" ] || [ "$1" = "worker" ] || [ "$1" = "scheduler" ] || [ "$1" = "flower" ] ; then
44+
j=0
45+
while ! curl -sI -u $RABBITMQ_CREDS http://$RABBITMQ_HOST:15672/api/whoami |grep '200 OK'; do
46+
j=$((j+1))
47+
if [ $j -ge $TRY_LOOP ]; then
48+
echo "$(date) - $RABBITMQ_HOST still not reachable, giving up"
49+
exit 1
50+
fi
51+
echo "$(date) - waiting for RabbitMQ... $j/$TRY_LOOP"
52+
sleep 5
53+
done
54+
fi
55+
exec $CMD "$@"
56+
elif [ "x$EXECUTOR" = "xLocal" ]
57+
then
58+
sed -i "s/executor = CeleryExecutor/executor = LocalExecutor/" "$AIRFLOW_HOME"/airflow.cfg
59+
exec $CMD "$@"
60+
else
61+
if [ "$1" = "version" ]; then
62+
exec $CMD version
63+
fi
64+
sed -i "s/executor = CeleryExecutor/executor = SequentialExecutor/" "$AIRFLOW_HOME"/airflow.cfg
65+
sed -i "s#sql_alchemy_conn = postgresql+psycopg2://airflow:airflow@postgres/airflow#sql_alchemy_conn = sqlite:////usr/local/airflow/airflow.db#" "$AIRFLOW_HOME"/airflow.cfg
66+
echo "Initialize database..."
67+
$CMD initdb
68+
exec $CMD webserver
69+
fi

0 commit comments

Comments
 (0)