Illyoung Choi | 3926274 | 2019-07-23 13:28:00 -0700 | [diff] [blame] | 1 | #!/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 | |
| 17 | POSTGRES_HOST="postgres" |
| 18 | POSTGRES_PORT=5432 |
| 19 | POSTGRES_USER="airflow" |
| 20 | POSTGRES_PASSWORD="airflow" |
| 21 | POSTGRES_DB="airflow" |
| 22 | |
| 23 | export AIRFLOW__CORE__FERNET_KEY=$(python -c "from cryptography.fernet import Fernet; fk = Fernet.generate_key().decode(); print(fk)") |
| 24 | echo "export AIRFLOW__CORE__FERNET_KEY=${AIRFLOW__CORE__FERNET_KEY}" >> ~/.bashrc |
| 25 | export AIRFLOW__CORE__LOAD_EXAMPLES=False |
| 26 | echo "export AIRFLOW__CORE__LOAD_EXAMPLES=${AIRFLOW__CORE__LOAD_EXAMPLES}" >> ~/.bashrc |
| 27 | export AIRFLOW__CORE__SQL_ALCHEMY_CONN="postgresql+psycopg2://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB" |
| 28 | echo "export AIRFLOW__CORE__SQL_ALCHEMY_CONN=${AIRFLOW__CORE__SQL_ALCHEMY_CONN}" >> ~/.bashrc |
| 29 | |
| 30 | TRY=20 |
| 31 | |
| 32 | wait_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 | |
| 46 | wait_for_port "Postgres" "$POSTGRES_HOST" "$POSTGRES_PORT" |
| 47 | |
| 48 | airflow initdb |
| 49 | airflow scheduler & |
| 50 | airflow webserver |