Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: implement tag-based deployment #2213

Merged
merged 8 commits into from
Jul 18, 2024
Merged

Conversation

lalver1
Copy link
Member

@lalver1 lalver1 commented Jul 11, 2024

This PR implements the second step of code changes needed to transition the benefits repository to tag-based deployments as described in #1527.

The code changes are associated with:

  • GitHub workflows
  • Azure DevOps/Terraform pipeline
  • Python package versioning using git metadata

The last step needed to close #1527, will be to remove the test and prod branches and remove references to them in all the GitHub workflows.

Acceptance Criteria

  • Merging to main deploys to the dev environment
  • Pushing a pre-release tag deploys to the test environment
  • Pushing a release tag deploys to the prod environment and triggers the release job
  • The conditional environment, dev and prod Azure jobs (terraform stage) run correctly
  • Python package versioning uses git metadata
  • There is a guarantee that the required checks have passed on the commit to be deployed

@lalver1 lalver1 self-assigned this Jul 11, 2024
@github-actions github-actions bot added the actions Related to GitHub Actions workflows label Jul 11, 2024
Copy link

github-actions bot commented Jul 11, 2024

Coverage report

This PR does not seem to contain any modification to coverable code.

@lalver1 lalver1 changed the title Chore: implement tag-based deployment Refactor: implement tag-based deployment Jul 11, 2024
@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch 2 times, most recently from 1577ac1 to 69c3691 Compare July 11, 2024 15:21
.github/workflows/release.yml Outdated Show resolved Hide resolved
@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch 4 times, most recently from c29fe08 to d48ebce Compare July 12, 2024 02:52
@lalver1
Copy link
Member Author

lalver1 commented Jul 12, 2024

Now deploy and release are two sequential jobs in the Deploy workflow. I grouped the two release steps into the release job to set the if condition and the permissions just once at the job level instead of twice if they had been at the step level.

Unfortunately I couldn't set ${{ github.ref_type != 'tag' && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }} as an environment variable using env in the workflow and avoid duplicating writing it out since the env context is not available at the job level, only at the step level.

With this implementation we'll have the following behavior in main:

@lalver1 lalver1 marked this pull request as ready for review July 12, 2024 13:50
@lalver1 lalver1 requested a review from a team as a code owner July 12, 2024 13:50
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good so far! I think the workflow updates all look correct.

But we still need the updates to the Azure DevOps/Terraform pipeline, which is looking at the old test and prod branches etc.

Take a look at Server for how those pipelines work with tag-based.

thekaveman
thekaveman previously approved these changes Jul 12, 2024
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, don't forget that tag-based deployment means we get the version number from the tag instead of hardcoding it in the source.

That means changes at least to pyproject.toml and probably the Docker build process.

See these PRs for how it was done elsewhere:

@thekaveman thekaveman dismissed their stale review July 12, 2024 20:59

Accidental approval

@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch 4 times, most recently from ead861e to 80ebb05 Compare July 15, 2024 21:15
@thekaveman
Copy link
Member

@lalver1 you should be able to rebase on main now to get the Cypress tests passing.

Fixed by #2214

@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch from 80ebb05 to 2914299 Compare July 15, 2024 22:29
@lalver1
Copy link
Member Author

lalver1 commented Jul 15, 2024

Thanks @thekaveman, trying it now!

@lalver1
Copy link
Member Author

lalver1 commented Jul 15, 2024

Thanks for the review, I had overlooked the Azure DevOps/Terraform pipeline and the dynamic versioning part. I think we should now have all the parts ready for tag-based deployment.

The only thing I don't feel very confident about is if we need COPY .git .gitin the dev container's Dockerfile since we already have this line in the app container's Dockerfile. If indeed we don't need it, I guess including it has no impact in how it works, it would just make the code cleaner.

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting really close @lalver1, this is looking great.

Just a few more small notes and I think it's ready.

.github/workflows/deploy.yml Outdated Show resolved Hide resolved
terraform/pipeline/deploy.yml Outdated Show resolved Hide resolved
@thekaveman
Copy link
Member

The only thing I don't feel very confident about is if we need COPY .git .gitin the dev container's Dockerfile since we already have this line in the app container's Dockerfile. If indeed we don't need it, I guess including it has no impact in how it works, it would just make the code cleaner.

I was wondering the same thing. I see we do it this way in Server, so there must have been a reason. No worries, it is copied over immediately once we launch the devcontainer, so I think you can just leave it as-is.

.devcontainer/Dockerfile Outdated Show resolved Hide resolved
@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch from 2914299 to f4304d0 Compare July 16, 2024 17:08
python terraform/pipeline/workspace.py

TAG_TYPE=$(python terraform/pipeline/tag.py)
echo "##vso[task.setvariable variable=tag_type;isOutput=true]$TAG_TYPE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines could be normalized to move the TAG_TYPE and echo in tag.py similar to how it works in workspace.py, but not a priority for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Great, I'll create an issue to come back to this later.

@lalver1
Copy link
Member Author

lalver1 commented Jul 16, 2024

Thanks @angela-tran, that's a good point about the tests! I'm thinking about reusing these workflows:

  • tests-ui
  • tests-pytest
  • tests-cypress
  • check-migrations-and-messages

I don't think we need to run codeql and check-api 🤔. If this makes sense, I'll add on: workflow_call to those workflows that don't already have it, and will call them from deploy.yml using uses: before the deploy job.

Oh and one more question, I'm thinking about setting if: github.ref_type == 'tag' when calling these tests, since we already run them as part of the branch protection status checks when ref_type is branch and we probably don't want to run them again?

@angela-tran
Copy link
Member

Thanks @angela-tran, that's a good point about the tests! I'm thinking about reusing these workflows:

  • tests-ui
  • tests-pytest
  • tests-cypress
  • check-migrations-and-messages

I don't think we need to run codeql and check-api 🤔. If this makes sense, I'll add on: workflow_call to those workflows that don't already have it, and will call them from deploy.yml using uses: before the deploy job.

That list looks good to me. And we'll want deploy to depend on the tests succeeding.

Oh and one more question, I'm thinking about setting if: github.ref_type == 'tag' when calling these tests, since we already run them as part of the branch protection status checks when ref_type is branch and we probably don't want to run them again?

Yep, that's definitely needed. eligibility-server does it too in its GitHub workflow.

@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch 2 times, most recently from 0a3b639 to 1644262 Compare July 17, 2024 15:25
@lalver1
Copy link
Member Author

lalver1 commented Jul 17, 2024

@angela-tran @thekaveman I added the tests to the deploy workflow and required them to successfully complete before the deploy job starts.

I did notice that eligibility-server has these lines in its docker-publish workflow

deploy:
    needs: test
    # !cancelled() is needed because if the whole workflow was cancelled, we don't want this job to run.
    # (github.ref_type != 'tag' || needs.test.result == 'success') is needed because if `test` did run, we only want this to run if `test` succeeded.
    if: (!cancelled() && (github.ref_type != 'tag' || needs.test.result == 'success'))

and I'm wondering if I should add if: (!cancelled() to the benefits deploy job since I guess we could manually want to cancel a deploy before it finishes running. I think the second part && (github.ref_type != 'tag' || needs.test.result == 'success') may not be needed because

needs:
      [tests-ui, tests-pytest, tests-cypress, check-migrations-and-messages]

covers this case?

@angela-tran
Copy link
Member

I'm wondering if I should add if: (!cancelled() to the benefits deploy job since I guess we could manually want to cancel a deploy before it finishes running. I think the second part && (github.ref_type != 'tag' || needs.test.result == 'success') may not be needed because

needs:
      [tests-ui, tests-pytest, tests-cypress, check-migrations-and-messages]

covers this case?

Great catch @lalver1 -- yes, I think we should add if: (!cancelled()).

I took a closer look at that second part from eligibility-server, and I think you're right that it's not needed. GitHub docs on needs confirms that the jobs listed must complete successfully before the dependent job will run, so it would be redundant to include this condition. I think it's a remnant from an older version of the expression.

Long story short 😄, we don't need the second part here, and it could also be removed in eligibility-server.

@lalver1 lalver1 force-pushed the refactor/tag-based-deployment branch from 1644262 to 8910c31 Compare July 17, 2024 19:24
@lalver1
Copy link
Member Author

lalver1 commented Jul 17, 2024

Thanks @angela-tran! I added if: (!cancelled()) to the deploy job and will make a ticket to remove the second part of the expression in eligibility-server; I think this one is ready for a review 🙂

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to go 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions Related to GitHub Actions workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider a "Deploy on Release" model
3 participants