diff --git a/.circleci/config.yml b/.circleci/config.yml index 656b8c7..10e0e0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ jobs: parameters: ssh: type: string - default: "ssh -o StrictHostKeyChecking=no $SCOPULI_RUNNER_SSH_USER@$SCOPULI_RUNNER_SSH_HOST SCOPULI_RUNNER_DIR=$SCOPULI_RUNNER_DIR" + default: "ssh -o StrictHostKeyChecking=no $JOBRUNNER_SSH_USER@$JOBRUNNER_SSH_HOST JOBRUNNER_DIR=$JOBRUNNER_DIR" scp: type: string default: "scp -o StrictHostKeyChecking=no" @@ -27,14 +27,17 @@ jobs: name: Add SSH forwarding command: | eval `ssh-agent -s` && ssh-add -k + - run: + name: Print environment vars + command: printenv - run: name: Pull Latest Head of Main command: | - << parameters.ssh >> "cd $SCOPULI_RUNNER_DIR/scopuli && git checkout $SCOPULI_ENV && git pull" + << parameters.ssh >> "cd $JOBRUNNER_DIR/jobrunner && git checkout ashannon/jobrunner/dispatch_jobs && git pull" - run: name: Set up server's environment variables description: | - Sets up the server's environmnet variables. Avoid using ssh to source the variables in this step. + Sets up the server's environment variables. Avoid using ssh to source the variables in this step. It can cause an exit 255 since the scp command precedes it. command: | echo "export SCOPULI_PROD_PG_HOST=${SCOPULI_PROD_PG_HOST}" >> .env @@ -47,7 +50,24 @@ jobs: - run: name: Update the cron schedule command: | - << parameters.ssh >> "bash $SCOPULI_RUNNER_DIR/scopuli/scheduler/schedule.sh" + << parameters.ssh >> "bash $JOBRUNNER_DIR/jobrunner/schedule.sh" + - run: + name: List crontab + command: | + << parameters.ssh >> "crontab -l" + - run: + name: Check crontab + command: | + << parameters.ssh >> "bash $JOBRUNNER_DIR/jobrunner/check_crontab.sh" + test: + docker: + - image: cimg/base:2023.06 + steps: + - run: + name: Test push to remote main trigger + command: | + echo "new commit to main" + workflows: deploy-to-prod: jobs: @@ -57,3 +77,16 @@ workflows: filters: branches: only: main + push-to-remote-main: + jobs: + - test: + filters: + branches: + only: ashannon/jobrunner/dispatch_jobs + - deploy: + context: + - aethersphere-prod + filters: + branches: + only: ashannon/jobrunner/dispatch_jobs + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..107d2ac --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "scopuli"] + path = scopuli + url = git@github.com:tm41m/scopuli.git diff --git a/check_crontab.sh b/check_crontab.sh new file mode 100644 index 0000000..67e6e88 --- /dev/null +++ b/check_crontab.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +target_job="0 0 */2 * * docker run --env-file /home/circleci/.env --network=host --mount type=bind,source=/home/circleci/jobrunner/scopuli/ganymede/,target=/usr/app --mount type=bind,source=/home/circleci/jobrunner/scopuli/,target=/root/.dbt/ ghcr.io/dbt-labs/dbt-postgres:1.5.2 run --target prod" + +crontab_content=$(crontab -l) + +if [[ $crontab_content == *"$target_job"* ]]; then + echo "dbt job has been scheduled" +else + echo "error, dbt job has not been properly scheduled" +fi diff --git a/schedule.sh b/schedule.sh index 2fc9f3c..93e56fd 100644 --- a/schedule.sh +++ b/schedule.sh @@ -4,8 +4,7 @@ crontab -r # dbt run -dbt_run="0 0 */2 * * docker run --env-file /home/circleci/.env --network=host --mount type=bind,source=/home/circleci/scopuli/ganymede/,target=/usr/app --mount type=bind,source=/home/circleci/scopuli/,target=/root/.dbt/ ghcr.io/dbt-labs/dbt-postgres:1.5.2 run --target prod" -cmd_1="0 0 */2 * * pwd" +dbt_run="0 0 */2 * * docker run --env-file /home/circleci/.env --network=host --mount type=bind,source=/home/circleci/jobrunner/scopuli/ganymede/,target=/usr/app --mount type=bind,source=/home/circleci/jobrunner/scopuli/,target=/root/.dbt/ ghcr.io/dbt-labs/dbt-postgres:1.5.2 run --target prod" # Create a temporary file to store the cron job entries temp_file=$(mktemp) diff --git a/scopuli b/scopuli new file mode 160000 index 0000000..901a2ab --- /dev/null +++ b/scopuli @@ -0,0 +1 @@ +Subproject commit 901a2ab608c60e03bc0497f2e3e6eb61e5b1cddb