Skip to content

Add a /api/deploy endpoint for the k8s hosted site#641

Merged
tim-eves merged 4 commits intostagingfrom
k8s-deploy-webhook-endpoint
Nov 3, 2022
Merged

Add a /api/deploy endpoint for the k8s hosted site#641
tim-eves merged 4 commits intostagingfrom
k8s-deploy-webhook-endpoint

Conversation

@tim-eves
Copy link
Copy Markdown
Contributor

@tim-eves tim-eves commented Nov 3, 2022

This implements a deploy webhook by having a dedicated small responder directly perform a git pull. It turns out to be less trouble than watching for files in sidecar container, and more efficient than polling in a bash script signal files. This only maps the /api/deploy path to respond to GH push webhook events, leaving the rest of the '/api' space for the site's php. It is integrated to pull the secret from k8s a Secret volume (not defined here) and configuration (branch name to deploy, deploy script, and responder config) from k8s ConfigMap (included).

Add a webhook responder using a sidecar container to securely validate
and pull from the repo, in response to GH push webevents. We can do this
directly without needing to poll for lock files.
@tim-eves tim-eves requested a review from mcdurdin November 3, 2022 03:53
@darcywong00 darcywong00 added this to the B16S1 milestone Nov 3, 2022
Comment thread resources/kubectl/help-kubectl-dev.yaml
Copy link
Copy Markdown
Member

@mcdurdin mcdurdin 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 LGTM although there's a lot of k8s special sauce magic that I don't really grok!

Make it clear this a dummy key for testing purposes, so should be here, and it should not be used in production.
@tim-eves
Copy link
Copy Markdown
Contributor Author

tim-eves commented Nov 3, 2022

Not sure where this kind of detail should go, as it seems a bit long for a yaml comment, but to trigger the deploy hook with a minimal simulated GitHub event, you can use the following on a docker-desktop k8s cluster deployed pod:

$> curl -v --request POST \
    -H "Content-Type: application/json" \
    -H "X-Hub-Signature-256: sha256=49af8531106a369bfee369f91dadec597e8ea3992ec2802bbe655be0ece17f15" \
    --data '{"action":"push","ref":"refs/heads/staging"}' \
    help.keyman.com.localhost:30900/api/deploy

@mcdurdin
Copy link
Copy Markdown
Member

mcdurdin commented Nov 3, 2022 via email

Explain how to bring up the Kubernetes pod and resources to simulate deployment, and test a near production environment.
@tim-eves tim-eves merged commit fb6f835 into staging Nov 3, 2022
@tim-eves tim-eves deleted the k8s-deploy-webhook-endpoint branch November 3, 2022 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants