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

Add webhook/ with webhook JSON config and deploy.sh with docs #400

Merged
merged 2 commits into from
Mar 25, 2023

Conversation

humphd
Copy link
Contributor

@humphd humphd commented Mar 21, 2023

Closes #77
Closes #76
Closes #74
Closes #50

This finishes the work begun in #57 to get our deployment webhook in place. ITS wants it to run outside of Docker, and has already installed webhook on the manager nodes.

This is the first of at least 2 parts to get this completed. I need to land the major bits here, then test it and adjust and document things in a follow-up.

The main points here are as follows:

  1. On staging (and later production), we'll run a webhook server. It will listen on :8000 and ITS will route anything that comes to /hooks/* to this server.
  2. The webhook will listen for deploy messages from GitHub, which will include 2 things. First a new tag to use with Docker. When we update to a new version on main, this will send that image tag so it can be deployed; second, we'll send a digest created with a secret. Our deployment servers will only respond to webhooks that can sign the body (i.e., no one else can hit this endpoint)
  3. Assuming the webhook can be verified by the server (calculating the secret + body to see if it matches the digest), the deploy.sh script will be run. The new tag will be sent along as an ENV var. Docker will try to update the starchart image to the new tag.

As we discussed in #291, I'm not doing any database migration/syncing in here. Any changes to the database schema would require a manual shut-down and update of the DB first. It would be good to get to an automated version of this some day, but not in this PR.

@humphd humphd added category: deployment Related to building our local code into a working unit area: devOps Services/tools that are not our main functionality, but help the project dependency: docker label used by Dependabot for docker related updates labels Mar 21, 2023
@humphd humphd self-assigned this Mar 21, 2023
with:
url: https://mycustomdomain-dev.senecacollege.ca/hooks/deploy
hmacSecret: ${{ env.HMAC_SECRET }}
data: '{"tag": "${{ env.IMAGE }}:sha-${{ env.GITHUB_SHA_SHORT }}"}'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't send image here, only the new tag.

Copy link
Contributor

@Eakam1007 Eakam1007 Mar 22, 2023

Choose a reason for hiding this comment

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

Apart from changing this as you mentioned, and one small question looks good

permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Define GITHUB_SHORT_SHA
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
Copy link
Contributor

@sfrunza13 sfrunza13 Mar 22, 2023

Choose a reason for hiding this comment

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

I don't think this really makes a difference (and I may also be entirely wrong) but aren't the characters on the tail end of a sha the most meaningful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can take any hash and truncate it to use only the first part of it as a short-hand. This is what GitHub does when they show my commit as 93a5088 vs. 93a508896294bdd9f74b1d4ca92a57c49999f34e

sfrunza13
sfrunza13 previously approved these changes Mar 22, 2023
Copy link
Contributor

@sfrunza13 sfrunza13 left a comment

Choose a reason for hiding this comment

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

I don't think I am going to be able to find a fault with this. After everything in the needs occurs add IMAGE to env, then build and push an image with new tags, use navied/[email protected] to post to hooks safely, then deploy.sh logic which you already noticed uses image twice there because you pass image in with tag

webhook/deploy.sh Show resolved Hide resolved
webhook/hooks.json Show resolved Hide resolved
with:
url: https://mycustomdomain-dev.senecacollege.ca/hooks/deploy
hmacSecret: ${{ env.HMAC_SECRET }}
data: '{"tag": "${{ env.IMAGE }}:sha-${{ env.GITHUB_SHA_SHORT }}"}'
Copy link
Contributor

@Eakam1007 Eakam1007 Mar 22, 2023

Choose a reason for hiding this comment

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

Apart from changing this as you mentioned, and one small question looks good

@humphd
Copy link
Contributor Author

humphd commented Mar 23, 2023

Fixed the review issue.

sfrunza13
sfrunza13 previously approved these changes Mar 23, 2023
Eakam1007
Eakam1007 previously approved these changes Mar 23, 2023
Copy link
Contributor

@Eakam1007 Eakam1007 left a comment

Choose a reason for hiding this comment

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

Just a small question out of curiosity, but looks good

webhook/hooks.json Show resolved Hide resolved
@humphd
Copy link
Contributor Author

humphd commented Mar 23, 2023

Just a small question out of curiosity, but looks good

Correct, these files won't be used as is. They are a template for manually setting this up on staging.

@humphd
Copy link
Contributor Author

humphd commented Mar 24, 2023

I've updated this again. I've added the systemd startup unit file, so the webhook runs as a service (it's already installed on staging). I think this is ready to test!

@humphd
Copy link
Contributor Author

humphd commented Mar 25, 2023

Thanks for the review! I'm going to try this now...

@humphd
Copy link
Contributor Author

humphd commented Mar 25, 2023

Crap, I got my order wrong, I have to do another PR to make this happen.

@humphd humphd merged commit e625c7a into DevelopingSpace:main Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: devOps Services/tools that are not our main functionality, but help the project category: deployment Related to building our local code into a working unit dependency: docker label used by Dependabot for docker related updates
Projects
None yet
3 participants