Repository: gestaogovbr/FastETL (language: python)

Issue:
Add a build container step for tests
The test container fails to setup (`make setup`) on Github Actions because Airflow is not ready when it runs `airflow db reset`.

A proposed solution is to build a new container inheriting from the Airflow container that add the `airflow db init` step before the setup phase.
Add a build container step for tests
The test container fails to setup (`make setup`) on Github Actions because Airflow is not ready when it runs `airflow db reset`.

A proposed solution is to build a new container inheriting from the Airflow container that add the `airflow db init` step before the setup phase.


Discussion / hints:

Fix patch:
diff --git a/Makefile b/Makefile
index d793eae..475c974 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,6 @@
 .PHONY: setup
 setup:
 	docker-compose -f tests/docker-compose.yml up -d --force-recreate --remove-orphans
-	docker exec airflow sh -c "airflow db reset -y && airflow scheduler -D"
 
 .PHONY: down
 down:
@@ -9,4 +8,4 @@ down:
 
 .PHONY: tests
 tests:
-	docker exec airflow pytest -vvv
+	docker exec airflow pytest -vvv --color=yes


Test patch:
diff --git a/tests/Dockerfile b/tests/Dockerfile
index 3ac0a77..c37bfb6 100644
--- a/tests/Dockerfile
+++ b/tests/Dockerfile
@@ -2,6 +2,6 @@ FROM ghcr.io/economiagovbr/airflow2-docker:latest
 
 RUN airflow db init
 
-ENTRYPOINT airflow webserver
+ENTRYPOINT airflow scheduler
 
 EXPOSE 8080
diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml
index 756205e..dee67f3 100644
--- a/tests/docker-compose.yml
+++ b/tests/docker-compose.yml
@@ -39,6 +39,7 @@
     version: '3'
     services:
       airflow:
+        # image: ghcr.io/economiagovbr/airflow2-docker:latest
         build: .
         environment:
           AIRFLOW__CORE__EXECUTOR: SequentialExecutor
diff --git a/tests/wait-for-airflow.sh b/tests/wait-for-airflow.sh
new file mode 100755
index 0000000..83427f8
--- /dev/null
+++ b/tests/wait-for-airflow.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+# Wait for Airflow to be ready,
+while [[ "$(curl --silent 'http://localhost:8080/health' \
+    | python3 -c 'import sys, json; print(json.load(sys.stdin)["scheduler"]["status"])')" != "healthy" ]];
+do {
+    printf "."; sleep 2;  
+} done
\ No newline at end of file