-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
.PHONY: run | ||
run: setup-containers create-example-variable | ||
run: \ | ||
create-logs-dir \ | ||
setup-containers \ | ||
create-example-variable \ | ||
create-path-tmp-variable \ | ||
create-inlabs-db \ | ||
create-inlabs-db-connection \ | ||
create-inlabs-portal-connection \ | ||
activate-inlabs-load-dag | ||
|
||
create-logs-dir: | ||
mkdir -p ./mnt/airflow-logs -m a=rwx | ||
|
||
setup-containers: | ||
docker compose up -d --force-recreate --remove-orphans | ||
|
@@ -22,6 +33,79 @@ create-example-variable: | |
}' > /dev/null; \ | ||
fi" | ||
|
||
create-path-tmp-variable: | ||
@echo "Creating 'path_tmp' Airflow variable" | ||
@docker exec airflow-webserver sh -c \ | ||
"if ! curl -f -s -LI 'http://localhost:8080/api/v1/variables/path_tmp' --user \"airflow:airflow\" > /dev/null; \ | ||
then \ | ||
curl -s -X 'POST' \ | ||
'http://localhost:8080/api/v1/variables' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
--user \"airflow:airflow\" \ | ||
-d '{ \ | ||
\"key\": \"path_tmp\", \ | ||
\"value\": \"/tmp\" \ | ||
}' > /dev/null; \ | ||
fi" | ||
|
||
create-inlabs-db: | ||
@echo "Creating 'inlabs' database" | ||
@docker exec -e PGPASSWORD=airflow ro-dou-postgres-1 sh -c "psql -q -U airflow -f /sql/init-db.sql > /dev/null" | ||
|
||
create-inlabs-db-connection: | ||
@echo "Creating 'inlabs_db' Airflow connection" | ||
@docker exec airflow-webserver sh -c \ | ||
"if ! curl -f -s -LI 'http://localhost:8080/api/v1/connections/inlabs_db' --user \"airflow:airflow\" > /dev/null; \ | ||
then \ | ||
curl -s -X 'POST' \ | ||
'http://localhost:8080/api/v1/connections' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
--user \"airflow:airflow\" \ | ||
-d '{ \ | ||
\"connection_id\": \"inlabs_db\", \ | ||
\"conn_type\": \"postgres\", \ | ||
\"schema\": \"inlabs\", \ | ||
\"host\": \"ro-dou-postgres-1\", \ | ||
\"login\": \"airflow\", \ | ||
\"password\": \"airflow\", \ | ||
\"port\": 5432 \ | ||
}' > /dev/null; \ | ||
fi" | ||
|
||
create-inlabs-portal-connection: | ||
@echo "Creating 'inlabs_portal' Airflow connection" | ||
@docker exec airflow-webserver sh -c \ | ||
"if ! curl -f -s -LI 'http://localhost:8080/api/v1/connections/inlabs_portal' --user \"airflow:airflow\" > /dev/null; \ | ||
then \ | ||
curl -s -X 'POST' \ | ||
'http://localhost:8080/api/v1/connections' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
--user \"airflow:airflow\" \ | ||
-d '{ \ | ||
\"connection_id\": \"inlabs_portal\", \ | ||
\"conn_type\": \"http\", \ | ||
\"description\": \"Credencial para acesso no Portal do INLabs\", \ | ||
\"host\": \"https://inlabs.in.gov.br/\", \ | ||
\"login\": \"[email protected]\", \ | ||
\"password\": \"password\" \ | ||
}' > /dev/null; \ | ||
fi" | ||
|
||
activate-inlabs-load-dag: | ||
@echo "Activating 'dou_inlabs_load_pg' Airflow DAG" | ||
@docker exec airflow-webserver sh -c \ | ||
"curl -s -X 'PATCH' \ | ||
'http://localhost:8080/api/v1/dags/ro-dou_inlabs_load_pg' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/json' \ | ||
--user \"airflow:airflow\" \ | ||
-d '{ \ | ||
\"is_paused\": false \ | ||
}' > /dev/null;" | ||
|
||
.PHONY: down | ||
down: | ||
docker compose down | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE DATABASE inlabs; | ||
|
||
\c inlabs | ||
|
||
CREATE SCHEMA IF NOT EXISTS dou_inlabs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters