feat(cleanup): cleaning up the project with somme standards
This commit is contained in:
9
images/airflow/Dockerfile
Normal file
9
images/airflow/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM apache/airflow:2.5.3-python3.10
|
||||
|
||||
USER root
|
||||
|
||||
COPY --chown=airflow:root ./dags/ ${AIRFLOW_HOME}/dags/
|
||||
COPY --chown=airflow:root ./scripts/ ${AIRFLOW_HOME}/scripts/
|
||||
RUN chmod +x ./scripts/*
|
||||
|
||||
USER airflow
|
42
images/airflow/dags/dag_http.py
Normal file
42
images/airflow/dags/dag_http.py
Normal file
@ -0,0 +1,42 @@
|
||||
import json
|
||||
from airflow.utils.dates import days_ago
|
||||
from airflow import DAG
|
||||
from airflow.providers.http.operators.http import SimpleHttpOperator
|
||||
# Sensors
|
||||
from airflow.providers.http.sensors.http import HttpSensor
|
||||
from airflow.models.param import Param
|
||||
|
||||
default_dag_args = {
|
||||
'start_date': days_ago(2)
|
||||
}
|
||||
|
||||
with DAG(
|
||||
dag_id='mse_cmd_over_http',
|
||||
default_args=default_dag_args,
|
||||
schedule=None,
|
||||
params={
|
||||
"cmdName": Param("", type="string"),
|
||||
"format": Param("", type="string"),
|
||||
"env": Param("prod", type="string"),
|
||||
}
|
||||
) as dag:
|
||||
is_api_available = HttpSensor(
|
||||
task_id='is_api_available',
|
||||
http_conn_id='mse_api',
|
||||
endpoint='/api/v1/cmds'
|
||||
)
|
||||
task = SimpleHttpOperator(
|
||||
task_id='mse_cmd',
|
||||
method="GET",
|
||||
http_conn_id='mse_api',
|
||||
endpoint='/api/v1/cmds',
|
||||
data={
|
||||
"cmdName": "{{ dag_run.conf.get('cmdName') }}",
|
||||
"format": "{{ dag_run.conf.get('format') }}",
|
||||
"env": "{{ dag_run.conf.get('env') }}"
|
||||
},
|
||||
headers={"Content-Type": "application/json"},
|
||||
dag=dag
|
||||
)
|
||||
|
||||
is_api_available >> task
|
24
images/airflow/scripts/create-connections.sh
Normal file
24
images/airflow/scripts/create-connections.sh
Normal file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Simple script to provision AIRFLOW_CONNECTIONS !
|
||||
|
||||
export SQLALCHEMY_SILENCE_UBER_WARNING=1
|
||||
|
||||
conns=$(compgen -v -X '!*AIRFLOW_CONN_*')
|
||||
|
||||
for conn in ${conns}
|
||||
do
|
||||
echo "====================================="
|
||||
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
|
Reference in New Issue
Block a user