blob: 9cf381fff8406b7bdd6187ebdcc9d9ed8800ae90 [file] [log] [blame]
Illyoung Choi39262742019-07-23 13:28:00 -07001#!/usr/bin/env bash
2
3# Copyright Matthieu "Puckel_" Roisil (https://github.com/puckel)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# 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, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17POSTGRES_HOST="postgres"
18POSTGRES_PORT=5432
19POSTGRES_USER="airflow"
20POSTGRES_PASSWORD="airflow"
21POSTGRES_DB="airflow"
22
23export AIRFLOW__CORE__FERNET_KEY=$(python -c "from cryptography.fernet import Fernet; fk = Fernet.generate_key().decode(); print(fk)")
24echo "export AIRFLOW__CORE__FERNET_KEY=${AIRFLOW__CORE__FERNET_KEY}" >> ~/.bashrc
25export AIRFLOW__CORE__LOAD_EXAMPLES=False
26echo "export AIRFLOW__CORE__LOAD_EXAMPLES=${AIRFLOW__CORE__LOAD_EXAMPLES}" >> ~/.bashrc
27export AIRFLOW__CORE__SQL_ALCHEMY_CONN="postgresql+psycopg2://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB"
28echo "export AIRFLOW__CORE__SQL_ALCHEMY_CONN=${AIRFLOW__CORE__SQL_ALCHEMY_CONN}" >> ~/.bashrc
29
30TRY=20
31
32wait_for_port() {
33 local name="$1" host="$2" port="$3"
34 local j=0
35 while ! nc -z "$host" "$port" >/dev/null 2>&1 < /dev/null; do
36 j=$((j+1))
37 if [ $j -ge $TRY ]; then
38 echo >&2 "$(date) - $host:$port still not reachable, giving up"
39 exit 1
40 fi
41 echo "$(date) - waiting for $name... $j/$TRY"
42 sleep 5
43 done
44}
45
46wait_for_port "Postgres" "$POSTGRES_HOST" "$POSTGRES_PORT"
47
48airflow initdb
49airflow scheduler &
50airflow webserver