github

command
v0.0.0-...-d5b48cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

GitHub Flow

A GitHub webhook will be created on a repository and a Knative Service will be deployed to receive the webhook's event deliveries and forward them into a Channel, through a Bus, and out to the consumer via a Subscription. The Flow resource takes care of provisioning the webhook, the Service, the Channel, and the Subscription.

Prerequisites

  1. Setup your development environment
  2. Start Knative
  3. For GitHub to be able to call into the cluster,
    configure a custom domain and assign a static IP address.
  4. Install a ClusterBus

update knative/eventing/config/buses/stub-bus.yaml, changing kind to ClusterBus, like:

apiVersion: channels.knative.dev/v1alpha1
kind: ClusterBus
metadata:
  name: stub
spec:
  dispatcher:
    name: dispatcher
    image: github.com/knative/eventing/pkg/buses/stub
    args: [
      "-logtostderr",
      "-stderrthreshold", "INFO",
    ]

and apply the stub bus

ko apply -f config/buses/stub
  1. Install GitHub as an event source
ko apply -f pkg/sources/github/
  1. Check that the GitHub is now showing up as an event source and there's an event type for pullrequests
kubectl get eventsources
kubectl get eventtypes
  1. Create a personal access token to GitHub repo that you can use to register webhooks with the GitHub API. Also decide on a token that your code will use to authenticate the incoming webhooks from GitHub (accessToken). Update sample/github/githubsecret.yaml with those values. If your generated access token is 'asdfasfdsaf' and you choose your secretToken as 'password', you'd modify sample/github/githubsecret.yaml like so:
apiVersion: v1
kind: Secret
metadata:
  name: githubsecret
type: Opaque
stringData:
  githubCredentials: >
    {
      "accessToken": "asdfasfdsaf",
      "secretToken": "password"
    }

Running

In response to a pull request event, the legit Service will add (looks pretty legit) to the PR title.

Deploy the legit service via:

ko apply sample/github/legit-service.yaml

Once deployed, you can inspect the created resources with kubectl commands:

# This will show the Service that we created:
kubectl get service.serving.knative.dev -o yaml

# This will show the Route that the Service created:
kubectl get route -o yaml

# This will show the Configuration that the Service created:
kubectl get configurations -o yaml

# This will show the Revision that was created by the Configuration:
kubectl get revisions -o yaml

The Flow will accept the Webhook calls from GitHub and pass them to the legit service.

You can inspect those resources with the following kubectl commands:

# This will show the available EventSources that you can generate feeds from:
kubectl get eventsources -o yaml

# This will show the available EventTypes that you can generate feeds from:
kubectl get eventtypes -o yaml

Configure the Flow to point to a GitHub repository you are able to control and update spec.trigger.resource in samples/github/flow.yaml.

And then apply the resources:

ko apply -f sample/github/auth.yaml
ko apply -f sample/github/flow.yaml

Once deployed, you can inspect the created resources with kubectl commands:

# This will show the available Flows we created:
kubectl get flows -o yaml

# This will show the available Feeds created from the Flow:
kubectl get feeds -o yaml

# This will show the available Channels created from the Flow:
kubectl get channels -o yaml

# This will show the available Subscriptions created from the Flow:
kubectl get subscriptions -o yaml

# This will show the available ClusterBuses we created in the prerequisites:
kubectl get clusterbuses -o yaml

Then create the secret so that you can see changes:

 ko apply -f sample/github/githubsecret.yaml

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 Flow:

 ko delete -f sample/github/flow.yaml

And you can check the repo and see the webhook has been removed

ko delete -f sample/github/

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL