diff --git a/base/kustomization.yaml b/base/kustomization.yaml index 182fbca..f6b92fc 100644 --- a/base/kustomization.yaml +++ b/base/kustomization.yaml @@ -52,7 +52,7 @@ helmCharts: scheduler: extraInitContainers: - name: airflow-create-connections - image: reg.cadoles.com/cadoles/airflow:latest + image: reg.cadoles.com/cadoles/airflow-init:latest args: - bash - -c diff --git a/images/airflow-init/Dockerfile b/images/airflow-init/Dockerfile new file mode 100644 index 0000000..619731f --- /dev/null +++ b/images/airflow-init/Dockerfile @@ -0,0 +1,11 @@ +FROM reg.cadoles.com/proxy_cache/apache/airflow:slim-2.5.3-python3.10 + +USER root + +COPY --chown=airflow:root ./scripts/ ${AIRFLOW_HOME}/scripts/ +RUN chmod +x ./scripts/* + +USER airflow + +ENTRYPOINT [ "/usr/bin/dumb-init", "--" ] +CMD [ "./scripts/create-connections.sh" ] \ No newline at end of file diff --git a/images/airflow-init/scripts/create-connections.sh b/images/airflow-init/scripts/create-connections.sh new file mode 100644 index 0000000..2a9d8dd --- /dev/null +++ b/images/airflow-init/scripts/create-connections.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Simple script to provision AIRFLOW_CONNECTIONS ! + +export SQLALCHEMY_SILENCE_UBER_WARNING=1 + +echo "=====================================" +conns=$(compgen -v -X '!*AIRFLOW_CONN_*') + +if [ -z "${conns}" ];then + echo " Nothing to do" + echo "=====================================" +else + for conn in ${conns} + do + name="${conn#"AIRFLOW_CONN_"}" + value=$(eval "echo -e ${!conn}") + echo "Creating ${name}: ${value}" + ex=$(airflow connections add "${name}" --conn-uri ${value} 2>&1) + if [ "${?}" -ne 0 ]; then + echo "${conn}: Bad connection definition" + echo "= Error ==========================" + echo "${ex}" + echo "= End error=======================" + else + echo "= Ok ================================" + fi + done +fi \ No newline at end of file diff --git a/skaffold.yaml b/skaffold.yaml index b846c63..6ed1277 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -36,5 +36,10 @@ build: kaniko: dockerfile: Dockerfile cache: {} + - image: reg.cadoles.com/cadoles/airflow-init + context: images/airflow-init + kaniko: + dockerfile: Dockerfile + cache: {} deploy: statusCheckDeadlineSeconds: 600