Skip to content

Commit

Permalink
Merge pull request #225 from NASA-IMPACT/feature/move-makefile-inside…
Browse files Browse the repository at this point in the history
…-sm2a

Move Makefile to SM2A folder
  • Loading branch information
amarouane-ABDELHAK authored Aug 28, 2024
2 parents 12a8030 + 23435b5 commit 8df1198
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 55 deletions.
68 changes: 15 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
SECRET_NAME=""
ENV_FILE=".env"
SM2A_FOLDER="sm2a"



important_message = \
@echo "\033[0;31m$(1) \033[0m"

info_message = \
@echo "\033[0;32m$(1) \033[0m"


count_down = \
@echo "Spinning up the system please wait..."; \
secs=40 ;\
while [ $$secs -gt 0 ]; do \
printf "%d\033[0K\r" $$secs; \
sleep 1; \
: $$((secs--)); \
done;


.PHONY:
Expand All @@ -27,44 +6,27 @@ count_down = \
test


all: sm2a-local-init sm2a-local-run
all:
$(MAKE) -C sm2a all

test:
pytest tests

sm2a-local-run:
$(MAKE) -C sm2a sm2a-local-run

sm2a-local-run: sm2a-local-stop sm2a-cp-dags
@echo "Running SM2A"
cd ${SM2A_FOLDER} && \
docker compose up -d
$(call important_message, "Give the resources a minute to be healthy 💪")
$(count_down)
$(call info_message, "Please visit http://localhost:8080")
echo "username:airflow | password:airflow"
echo "To use local SM2A with AWS update ${SM2A_FOLDER}/sm2a-local-config/.env AWS credentials"
sm2a-local-init:
$(MAKE) -C sm2a sm2a-local-init

sm2a-local-init: sm2a-cp-dags
cp ${SM2A_FOLDER}/sm2a-local-config/env_example ${SM2A_FOLDER}/sm2a-local-config/.env
docker compose -f ${SM2A_FOLDER}/docker-compose.yml run --rm airflow-cli db init
docker compose -f ${SM2A_FOLDER}/docker-compose.yml run --rm airflow-cli users create --email airflow@example.com --firstname airflow --lastname airflow --password airflow --username airflow --role Admin

sm2a-local-stop:
docker compose -f ${SM2A_FOLDER}/docker-compose.yml down
$(MAKE) -C sm2a sm2a-local-stop


sm2a-cp-dags:
cp -r dags ${SM2A_FOLDER}/.

sm2a-deploy: sm2a-cp-dags
@echo "Installing the deployment dependency"
cd ${SM2A_FOLDER} && \
pip install -r deploy_requirements.txt && \
echo "Deploying SM2A" && \
python ./scripts/generate_env_file.py --secret-id ${SECRET_NAME} --env-file ${ENV_FILE} && \
./scripts/deploy.sh ${ENV_FILE} <<< init && \
./scripts/deploy.sh ${ENV_FILE} <<< deploy
sm2a-deploy:
$(MAKE) -C sm2a sm2a-deploy

clean: sm2a-local-stop
@echo "Cleaning local env"
docker container prune -f
docker image prune -f
docker volume prune -f
clean:
$(MAKE) -C sm2a clean

test:
pytest tests
62 changes: 62 additions & 0 deletions sm2a/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
SECRET_NAME=""
ENV_FILE=".env"


important_message = \
@echo "\033[0;31m$(1) \033[0m"

info_message = \
@echo "\033[0;32m$(1) \033[0m"


count_down = \
@echo "Spinning up the system please wait..."; \
secs=40 ;\
while [ $$secs -gt 0 ]; do \
printf "%d\033[0K\r" $$secs; \
sleep 1; \
: $$((secs--)); \
done;


.PHONY:
clean
all



all: sm2a-local-init sm2a-local-run


sm2a-local-run: sm2a-local-stop
@echo "Running SM2A"
docker compose up -d
$(call important_message, "Give the resources a minute to be healthy 💪")
$(count_down)
$(call info_message, "Please visit http://localhost:8080")
@echo "username:airflow | password:airflow"
@echo "To use local SM2A with AWS update ${SM2A_FOLDER}/sm2a-local-config/.env AWS credentials"

sm2a-local-init:
cp sm2a-local-config/env_example sm2a-local-config/.env
docker compose run --rm airflow-cli db init
docker compose run --rm airflow-cli users create --email airflow@example.com --firstname airflow --lastname airflow --password airflow --username airflow --role Admin

sm2a-local-stop:
docker compose down


sm2a-deploy:
@echo "Installing the deployment dependency"
pip install -r deploy_requirements.txt
@echo "Deploying SM2A"
cp -r ../dags .
python scripts/generate_env_file.py --secret-id ${SECRET_NAME} --env-file ${ENV_FILE}
./scripts/deploy.sh ${ENV_FILE} <<< init
./scripts/deploy.sh ${ENV_FILE} <<< deploy

clean: sm2a-local-stop
@echo "Cleaning local env"
docker container prune -f
docker image prune -f
docker volume prune -f
4 changes: 2 additions & 2 deletions sm2a/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ x-airflow-common:
# Gotcha: Even though we set this to "True" in airflow.cfg, an environment variable overrides it
AIRFLOW__CORE__LOAD_EXAMPLES: false
volumes:
- ./dags:/opt/airflow/dags
- ../dags:/opt/airflow/dags
- ./plugins:/opt/airflow/plugins
- ./sm2a-local-config/local_airflow.cfg:/opt/airflow/airflow.cfg
- ./sm2a-local-config/local_webserver_config.py:/opt/airflow/webserver_config.py
Expand All @@ -47,7 +47,7 @@ x-airflow-worker:
environment:
<<: *airflow-common-env
volumes:
- ./dags:/opt/airflow/dags
- ../dags:/opt/airflow/dags
- ./plugins:/opt/airflow/plugins
- ./sm2a-local-config/local_airflow.cfg:/opt/airflow/airflow.cfg
- ./infrastructure/configuration:/opt/airflow/configuration
Expand Down

0 comments on commit 8df1198

Please sign in to comment.