From 6337ef001194aaebe1e297613aa30605d4276c4d Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Thu, 15 Feb 2024 13:48:42 +1030 Subject: [PATCH 1/2] refactor: removes duplicated code in favour of using script files --- .../aspects/jobs/init/aspects/init-aspects.sh | 44 +------------------ 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/tutoraspects/templates/aspects/jobs/init/aspects/init-aspects.sh b/tutoraspects/templates/aspects/jobs/init/aspects/init-aspects.sh index f843b09ff..816b96ded 100644 --- a/tutoraspects/templates/aspects/jobs/init/aspects/init-aspects.sh +++ b/tutoraspects/templates/aspects/jobs/init/aspects/init-aspects.sh @@ -1,45 +1,5 @@ #!/usr/bin/env bash -## WARNING: If you modify this block, make sure to also update the -## corresponding block in the alembic.sh file. +bash /app/aspects/scripts/alembic.sh upgrade head -cd /app/aspects/migrations - -alembic upgrade head - -cd - - -## WARNING: If you modify this block, make sure to also update the -## corresponding block in the dbt.sh file. - -echo "Installing dbt packages..." - -pip install -r /app/aspects/dbt/requirements.txt - -{% if DBT_SSH_KEY %} -mkdir -p /root/.ssh -echo "{{ DBT_SSH_KEY}}" | tr -d '\r' > /root/.ssh/id_rsa -chmod 600 /root/.ssh/id_rsa -eval `ssh-agent -s` -ssh -o StrictHostKeyChecking=no git@github.com || true -ssh-add /root/.ssh/id_rsa -{% endif %} - -rm -rf {{ DBT_REPOSITORY_PATH }} - -echo "Installing aspects-dbt" -echo "git clone -b {{ DBT_BRANCH }} {{ DBT_REPOSITORY }}" -git clone -b {{ DBT_BRANCH }} {{ DBT_REPOSITORY }} - -cd {{ DBT_REPOSITORY_PATH }} || exit - -export ASPECTS_EVENT_SINK_DATABASE={{ASPECTS_EVENT_SINK_DATABASE}} -export ASPECTS_XAPI_DATABASE={{ASPECTS_XAPI_DATABASE}} - -echo "Installing dbt dependencies" -dbt deps --profiles-dir /app/aspects/dbt/ - -echo "Running dbt $*" -dbt run --profiles-dir /app/aspects/dbt/ - -rm -rf {{ DBT_REPOSITORY_PATH }} +bash /app/aspects/scripts/dbt.sh run From 7ed7362e03e776ebe66fa60ca14b96e79629be03 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Thu, 15 Feb 2024 13:48:52 +1030 Subject: [PATCH 2/2] refactor: removes the DBT_REPOSITORY_PATH variable in favour of hard-coding the git cloned directory name in the script, because the name of the directory doesn't matter. --- tutoraspects/plugin.py | 2 -- .../templates/aspects/apps/aspects/scripts/dbt.sh | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tutoraspects/plugin.py b/tutoraspects/plugin.py index af50fdfe8..700d6a1f1 100644 --- a/tutoraspects/plugin.py +++ b/tutoraspects/plugin.py @@ -353,8 +353,6 @@ ("DBT_REPOSITORY", "https://github.com/openedx/aspects-dbt"), ("DBT_BRANCH", "v3.4.1"), ("DBT_SSH_KEY", ""), - # Path to the dbt project inside the repository - ("DBT_REPOSITORY_PATH", "aspects-dbt"), # This is a pip compliant list of Python packages to install to run dbt # make sure packages with versions are enclosed in double quotes ("EXTRA_DBT_PACKAGES", []), diff --git a/tutoraspects/templates/aspects/apps/aspects/scripts/dbt.sh b/tutoraspects/templates/aspects/apps/aspects/scripts/dbt.sh index 27b262fc3..cca3643ca 100644 --- a/tutoraspects/templates/aspects/apps/aspects/scripts/dbt.sh +++ b/tutoraspects/templates/aspects/apps/aspects/scripts/dbt.sh @@ -16,13 +16,13 @@ ssh -o StrictHostKeyChecking=no git@github.com || true ssh-add /root/.ssh/id_rsa {% endif %} -rm -rf {{ DBT_REPOSITORY_PATH }} +rm -rf aspects-dbt echo "Installing aspects-dbt" echo "git clone -b {{ DBT_BRANCH }} {{ DBT_REPOSITORY }}" -git clone -b {{ DBT_BRANCH }} {{ DBT_REPOSITORY }} +git clone -b {{ DBT_BRANCH }} {{ DBT_REPOSITORY }} aspects-dbt -cd {{ DBT_REPOSITORY_PATH }} || exit +cd aspects-dbt || exit export ASPECTS_EVENT_SINK_DATABASE={{ASPECTS_EVENT_SINK_DATABASE}} export ASPECTS_XAPI_DATABASE={{ASPECTS_XAPI_DATABASE}} @@ -33,4 +33,4 @@ dbt deps --profiles-dir /app/aspects/dbt/ echo "Running dbt $*" dbt "$@" --profiles-dir /app/aspects/dbt/ -rm -rf {{ DBT_REPOSITORY_PATH }} +rm -rf aspects-dbt