* Update samples to not use Ingress. This is follow-up of https://github.com/knative/serving/pull/1228. We moved to Istio v1alpha3 / Gateway which requires a different way to get the external IP address to send traffic to our samples. * Also update the command to find service domain. |
||
---|---|---|
.. | ||
README.md | ||
gitwebhook.go | ||
sample.yaml |
README.md
gitwebhook
A simple git webhook handler that demonstrates interacting with github. Modeled after GCF example
Prerequisites
- Install Knative Serving
- Install docker
Setup
Build the app container and publish it to your registry of choice:
REPO="gcr.io/<your-project-here>"
# Build and publish the container, run from the root directory.
docker build \
--build-arg SAMPLE=gitwebhook \
--tag "${REPO}/sample/gitwebhook" \
--file=sample/Dockerfile.golang .
docker push "${REPO}/sample/gitwebhook"
# Replace the image reference with our published image.
perl -pi -e "s@github.com/knative/serving/sample/gitwebhook@${REPO}/sample/gitwebhook@g" sample/gitwebhook/*.yaml
# Deploy the Knative Serving sample
kubectl apply -f sample/gitwebhook/sample.yaml
Exploring
Once deployed, you can inspect the created resources with kubectl
commands:
# This will show the Route that we created:
kubectl get route -o yaml
# This will show the Configuration that we created:
kubectl get configurations -o yaml
# This will show the Revision that was created by our configuration:
kubectl get revisions -o yaml
To make this service accessible to github, we first need to determine its ingress address
(might have to wait a little while until EXTERNAL-IP
gets assigned):
watch kubectl get svc knative-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
knative-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d
Once the EXTERNAL-IP
gets assigned to the cluster, you need to assign a DNS name for that IP address.
Using GCP DNS
So, you'd need to create an A record for demostuff.aikas.org pointing to 35.202.30.59.
Then you need to go to github and [set up a webhook](https://cloud.google.com/community/tutorials/github-auto-assign-r eviewers-cloud-functions). For the Payload URL however, use your DNS entry you created above, so for my example it would be: http://demostuff.aikas.org/
Create a secret that has access to the tokens. Take the Secret you used for the webhook (secretToken) and the generated access token (accessToken) (as per the above webhook)
echo -n "your-chosen-secret-token" > secretToken
echo -n "github-generated-access-token" > accessToken
kubectl create secret generic githubsecret --from-file=./secretToken --from-file=./accessToken
Then create a PR for the repo you configured the webhook for, and you'll see that the Title will be modified with the suffix '(looks pretty legit)'
Cleaning up
To clean up the sample service:
kubectl delete -f sample/gitwebhook/sample.yaml