Skip to content

Commit

Permalink
Fix production deployments (#1066)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
abandoned-prototype authored Sep 24, 2023
1 parent 24a7605 commit 99d4fb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
13 changes: 7 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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):
Expand All @@ -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.")
Expand All @@ -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):
Expand Down

0 comments on commit 99d4fb6

Please sign in to comment.