Skip to content

Commit 97b3c20

Browse files
VincentRichieEscarez
authored andcommitted
Replace service.yaml with the correct contents (#1378)
* Replace service.yaml with the correct contents * edit for clarity, domain as req., PR #1202 * Update docs/serving/samples/gitwebhook-go/README.md Co-Authored-By: RichieEscarez <[email protected]> * Apply suggestions from code review Co-Authored-By: RichieEscarez <[email protected]>
1 parent 45f7861 commit 97b3c20

File tree

1 file changed

+71
-36
lines changed

1 file changed

+71
-36
lines changed

docs/serving/samples/gitwebhook-go/README.md

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ webhook.
33

44
## Before you begin
55

6-
- A Kubernetes cluster with Knative installed. Follow the
7-
[installation instructions](../../../install/README.md) if you need to create
8-
one.
9-
- [Docker](https://www.docker.com) installed and running on your local machine,
10-
and a Docker Hub account configured (we'll use it for a container registry).
11-
- An account on [GitHub](https://github.com) with read/write access to a
12-
repository.
6+
You must meet the following requirements to run this sample:
7+
8+
- Own a public domain. For example, you can create a domain with
9+
[Google Domains](https://domains.google/).
10+
- A Kubernetes cluster running with the following:
11+
- Knative Serving must be installed. For details about
12+
setting up a Knative cluster, see the
13+
[installation guides](../../../install/README.md).
14+
- Your Knative cluster must be
15+
[configured to use your custom domain](../../using-a-custom-domain.md).
16+
- You must ensure that your Knative cluster uses a static IP address:
17+
- For Google Kubernetes Engine, see
18+
[assigning a static IP address](../../gke-assigning-static-ip-address.md).
19+
- For other cloud providers, refer to your provider's documentation.
20+
- An installed version of [Docker](https://www.docker.com).
21+
- A [Docker Hub account](https://hub.docker.com/) to which you are able to
22+
upload your sample's container image.
1323

1424
## Build the sample code
1525

@@ -20,7 +30,7 @@ webhook.
2030
cd knative-docs/serving/samples/gitwebhook-go
2131
```
2232

23-
1. Use Docker to build a container image for this service. Replace `username`
33+
1. Use Docker to build a container image for this service. Replace `{DOCKER_HUB_USERNAME}`
2434
with your Docker Hub username in the following commands.
2535

2636
```shell
@@ -33,14 +43,14 @@ webhook.
3343
docker push ${DOCKER_HUB_USERNAME}/gitwebhook-go
3444
```
3545

36-
1. Create a secret that holds two values from GitHub, a personal access token
37-
used to make API requests to GitHub, and a webhook secret, used to validate
38-
incoming requests.
46+
1. Create a secret that holds two values from GitHub:
47+
- A [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)
48+
that you will use to make API requests to GitHub.
49+
- Ensure that you grant `read/write` permission in the repo for that personal access token.
3950

4051
1. Follow the GitHub instructions to
41-
[create a personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/).
42-
Ensure to grant the `repo` permission to give `read/write` access to the
43-
personal access token.
52+
- A webhook secret that you will use to validate requests.
53+
4454
1. Base64 encode the access token:
4555

4656
```shell
@@ -50,6 +60,7 @@ webhook.
5060

5161
1. Copy the encoded access token into `github-secret.yaml` next to
5262
`personalAccessToken:`.
63+
5364
1. Create a webhook secert value unique to this sample, base64 encode it, and
5465
copy it into `github-secret.yaml` next to `webhookSecret:`:
5566

@@ -74,51 +85,75 @@ webhook.
7485
name: gitwebhook
7586
namespace: default
7687
spec:
77-
- containers:
78-
# Replace {DOCKER_HUB_USERNAME} with your actual docker hub username
79-
image: docker.io/{DOCKER_HUB_USERNAME}/gitwebhook-go
80-
env:
81-
- name: SECRET_TOKEN
88+
template:
89+
spec:
90+
containers:
91+
- # Replace {DOCKER_HUB_USERNAME} with your actual docker hub username
92+
image: docker.io/{DOCKER_HUB_USERNAME}/gitwebhook-go:latest
93+
env:
94+
- name: GITHUB_PERSONAL_TOKEN
8295
valueFrom:
8396
secretKeyRef:
8497
name: githubsecret
85-
key: secretToken
86-
- name: ACCESS_TOKEN
98+
key: personalAccessToken
99+
- name: WEBHOOK_SECRET
87100
valueFrom:
88101
secretKeyRef:
89102
name: githubsecret
90-
key: accessToken
103+
key: webhookSecret
91104
```
92105

93106
1. Use `kubectl` to apply the `service.yaml` file.
94107

95108
```shell
96109
$ kubectl apply --filename service.yaml
110+
```
111+
112+
Response:
113+
114+
```shell
97115
service "gitwebhook" created
98116
```
99117

100-
1. Finally, once the service is running, create the webhook from your GitHub
101-
repo to the URL for this service. For this to work properly you will need to
102-
[configure a custom domain](../../using-a-custom-domain.md) and
103-
[assign a static IP address](../../gke-assigning-static-ip-address.md).
118+
1. Create a webhook in your GitHub repo using the URL for your `gitwebhook` service:
104119

105120
1. Retrieve the hostname for this service, using the following command:
106121

107122
```shell
108123
$ kubectl get ksvc gitwebhook \
109-
--output=custom-columns=NAME:.metadata.name,URL:.status.url
110-
NAME URL
111-
gitwebhook http://gitwebhook.default.example.com
124+
--output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
125+
```
126+
127+
Example response:
128+
129+
```shell
130+
NAME DOMAIN
131+
gitwebhook gitwebhook.default.MYCUSTOMDOMAIN.com
112132
```
133+
134+
where `MYCUSTOMDOMAIN` is the domain that you set as your
135+
[custom domain](../../using-a-custom-domain.md).
136+
137+
1. Go to the GitHub repository for which you have privileges to create a
138+
webhook.
139+
140+
1. Click **Settings** > **Webhooks** > **Add webhook** to open the Webhooks
141+
page.
142+
143+
1. Enter the **Payload URL** as `http://{DOMAIN}`, where `{DOMAIN}` is the
144+
address from the `kubectl get ksvc gitwebhook` command.
145+
For example: `http://gitwebhook.default.MYCUSTOMDOMAIN.com`
113146

114-
1. Browse on GitHub to the repository where you want to create a webhook.
115-
1. Click **Settings**, then **Webhooks**, then **Add webhook**.
116-
1. Fill in **Payload URL** with the value of URL listed above.
117147
1. Set the **Content type** to `application/json`.
118-
1. Enter the **Secret** value to be the same as the original base used for
119-
`webhookSecret` above (the original value, not the base64 encoded value).
120-
1. Select **Disable** under SSL Validation, unless you've
121-
[enabled SSL](../../using-an-ssl-cert.md).
148+
149+
1. Enter your webhook secret in **Secret** using the original base value that
150+
you set in `webhookSecret` (not the base64 encoded value). For example:
151+
`mygithubwebhooksecret`
152+
153+
1. If you did not
154+
[enabled TLS certificates](../../using-a-tls-cert.md),
155+
click **Disable** under **SSL Validation**.
156+
122157
1. Click **Add webhook** to create the webhook.
123158

124159
## Exploring

0 commit comments

Comments
 (0)