From 99d4fb6a9e3f1a75d568290e0c1201965e710e39 Mon Sep 17 00:00:00 2001 From: abandoned-prototype <41744410+abandoned-prototype@users.noreply.github.com> Date: Sun, 24 Sep 2023 01:02:18 -0500 Subject: [PATCH] Fix production deployments (#1066) ## Fixes issue Prod deploy failed. ## Description of Changes Pushing into the main branch is now longer required for production deployments, but the task.py script was hard-coded to fetch the (out of date) main branch. After this change, the script will now fetch the given git ref, in the prod deploy case this is the tag used in the release. --- .github/workflows/build_deploy.yml | 2 +- tasks.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index 968b17be9..eb696de37 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -74,6 +74,6 @@ jobs: - name: backup db run: invoke backup ${{ env.env_name }} - name: deploy - run: invoke deploy ${{ env.env_name }} ${{ github.actor }} ${{ secrets.GITHUB_TOKEN }} + run: invoke deploy ${{ env.env_name }} ${{ github.actor }} ${{ secrets.GITHUB_TOKEN }} ${{ github.ref_name }} - name: cleanup run: invoke cleanup ${{ env.env_name }} diff --git a/tasks.py b/tasks.py index c02957525..d5b22eaed 100644 --- a/tasks.py +++ b/tasks.py @@ -87,9 +87,9 @@ def get_configs( return configs[env] -def pull_repository(c: Connection, config: HostConfig): +def pull_repository(c: Connection, github_ref: str): """Pull the code on the repo down to the server.""" - c.run(f"git fetch origin {config.git_branch}") + c.run(f"git fetch origin {github_ref}") c.run("git reset --hard FETCH_HEAD") c.run("git clean -df") @@ -102,7 +102,7 @@ def migrate(c, config): ) -def deploy_(c: Connection, config: HostConfig): +def deploy_(c: Connection, config: HostConfig, github_ref: str): """Deploy the most recent docker image for the given environment.""" logging.info("Start new deployment.") with c.cd(config.code_dir): @@ -120,7 +120,7 @@ def deploy_(c: Connection, config: HostConfig): echo=True, ) logging.info("Get code changes from repo") - pull_repository(c, config) + pull_repository(c, github_ref) logging.info("Run necessary migrations.") migrate(c, config) logging.info("Bring docker service back up.") @@ -136,13 +136,14 @@ def deploy_(c: Connection, config: HostConfig): "environment": "'staging' or 'prod' indicating which environment to target", "github_user": "GitHub user name to authenticate with", "github_token": "token to use together with github_user", + "github_ref": "ref of the branch or tag to deploy (e.g. /refs/tag/v1.0.1 or /refs/heads/main)", } ) -def deploy(c, environment, github_user, github_token): +def deploy(c, environment, github_user, github_token, github_ref): """Deploy the most recent docker image for the given environment.""" config = get_configs(environment, github_user, github_token) connection = config.get_connection() - deploy_(connection, config) + deploy_(connection, config, github_ref) def backup_(c: Connection, config: HostConfig):