lighthouse

module
v0.0.600 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: Apache-2.0

README

Lighthouse

A lightweight ChatOps based webhook handler which can trigger Jenkins X Pipelines on webhooks from multiple git providers such as: GitHub, GitHub Enterprise, BitBucket Server, BitBucket Cloud, GitLab, Gitea etc

Building

To build the code clone git then type:

make build

Then to run it:

./bin/lighthouse

Environment variables

The following environment variables are used:

Name Description
GIT_KIND the kind of git server: github, bitbucket, gitea, stash
GIT_SERVER the URL of the server if not using the public hosted git providers: https://github.com or https://bitbucket.org https://gitlab.com
GIT_USER the git user (bot name) to use on git operations
GIT_TOKEN the git token to perform operations on git (add comments, labels etc)
HMAC_TOKEN the token sent from the git provider in webhooks
JX_SERVICE_ACCOUNT the service account to use for generated pipelines

Features

Currently Lighthouse supports the common prow plugins and handles push webhooks to branches to then trigger Jenkins X pipelines.

Lighthouse uses the same config.yaml and plugins.yaml file structure from Prow so that we can easily migrate from prow <-> lighthouse.

This also means we get to reuse the clean generation of Prow configuration from the SourceRepository, SourceRepositoryGroup and Scheduler CRDs integrated into jx boot. e.g. here's the default scheduler configuration which is used for any project imported into your Jenkins X cluster; without you having to touch the actual prow configuration files. You can create many schedulers and associate them to different SourceRepository resources.

We can also reuse Prow's capability of defining many separate pipelines on a repository (for PRs or releases) via having separate contexts. Then on a Pull Request we can use /test something or /test all to trigger pipelines and use the /ok-to-test and /approve or /lgtm commands

Comparisons to Prow

Lighthouse is very prow-like and currently reuses the Prow plugin source code and a bunch of plugins from prow

Its got a few differences though:

  • rather than be GitHub specific lighthouse uses jenkins-x/go-scm so it can support any git provider
  • lighthouse is mostly like hook from Prow; an auto scaling webhook handler - to keep the footprint small
  • lighthouse is also very light. In Jenkins X we have about 10 pods related to prow; with lighthouse we have just 1 along with the tekton controller itself. That one lighthouse pod could easily be auto scaled too from 0 to many as it starts up very quickly.
  • lighthouse focuses purely on Tekton pipelines so it does not require a ProwJob CRD; instead a push webhook to a release or pull request branch can trigger zero to many PipelineRun CRDs instead

Porting Prow commands

If there are any prow commands you want which we've not yet ported over, its relatively easy to port prow plugins.

We've reused the prow plugin code and configuration code; so its mostly a case of switching imports of k8s.io/test-infra/prow to github.com/jenkins-x/lighthouse/pkg/prow - then modifying the github client structs from, say, github.PullRequest to scm.PullRequest.

Most of the github structs map 1-1 with the jenkins-x/go-scm equivalents (e.g. Issue, Commit, PullRequest) though the go-scm API does tend to return slices to pointers to resources by default. There are some naming differences at different parts of the API though.

e.g. compare the githubClient API for the prow lgtm versus the lighthouse lgtm.

All the prow plugin related code lives in the pkg/prow tree of packages. Mostly all we've done is switch to using jenkins-x/go-scm and switch out the current prow agents and instead use a single tekton agent using the PlumberClient to trigger pipelines.

Testing Lighthouse

If you want to hack on lighthouse; such as to try it out with a specific git provider from jenkins-x/go-scm you can run it locally via:

make build

Then to run it:

./bin/lighthouse

Then if you want to test it out with a git provider running on the cloud or inside Kubernetes you can use ngrok to setup a tunnel to your laptop. e.g.:

ngrok http 8080

Now you can use your personal ngrok URL to register a webhook handler with your git provider. NOTE remember to append /hook to the generated ngrok URL. e.g. something like: https://7cc3b3ac.ngrok.io/hook

Any events that happen on your git provider should then trigger your local lighthouse.

Debugging Lighthouse

You can setup a remote debugger for lighthouse using delve via:

dlv --listen=:2345 --headless=true --api-version=2 exec ./bin/lighthouse -- $*        

You can then debug from your go based IDE (e.g. GoLand / IDEA / VS Code).

Using a local go-scm

If you are hacking on support for a specific git provider you may find yourself hacking on the lighthouse code or the jenkins-x/go-scm code together.

Go modules lets you easily swap out the version of a dependency with a local copy of the code; so you can edit code in lighthouse and jenkins-x/go-scm at the same time.

Just add this line to the end of your go.mod file:

replace github.com/jenkins-x/go-scm => /workspace/go/src/github.com/jenkins-x/go-scm

Using the exact path to where you cloned jenkins-x/go-scm.

Then if you do:

make build

It will uses your local jenkins-x/go-scm source.

Directories

Path Synopsis
cmd
gc
hack module
pkg
apis/lighthouse/v1alpha1
Package v1alpha1 contains LighthouseJob +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=github.com/jenkins-x/lighthouse/pkg/apis/lighthouse +k8s:defaulter-gen=TypeMeta +groupName=lighthouse.jenkins.io
Package v1alpha1 contains LighthouseJob +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=github.com/jenkins-x/lighthouse/pkg/apis/lighthouse +k8s:defaulter-gen=TypeMeta +groupName=lighthouse.jenkins.io
client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/lighthouse/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/lighthouse/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.
commentpruner
Package commentpruner facilitates efficiently deleting bot comments as a reaction to webhook events.
Package commentpruner facilitates efficiently deleting bot comments as a reaction to webhook events.
config
Package config knows how to read and parse config.yaml.
Package config knows how to read and parse config.yaml.
config/secret
Package secret implements an agent to read and reload the secrets.
Package secret implements an agent to read and reload the secrets.
errorutil
Package errorutil provides utilities for errors
Package errorutil provides utilities for errors
genfiles
Package genfiles understands the .generated_files config file.
Package genfiles understands the .generated_files config file.
git
git/localgit
Package localgit creates a local git repo that can be used for testing code that uses a git.Client.
Package localgit creates a local git repo that can be used for testing code that uses a git.Client.
interrupts
Package interrupts exposes helpers for graceful handling of interrupt signals
Package interrupts exposes helpers for graceful handling of interrupt signals
jobutil
Package jobutil contains helpers for working with LighthouseJobs.
Package jobutil contains helpers for working with LighthouseJobs.
keeper
Package keeper contains a controller for managing a keeper pool of PRs.
Package keeper contains a controller for managing a keeper pool of PRs.
keeper/history
Package history provides an append only, size limited log of recent actions that Keeper has taken for each subpool.
Package history provides an append only, size limited log of recent actions that Keeper has taken for each subpool.
logrusutil
Package logrusutil implements some helpers for using logrus
Package logrusutil implements some helpers for using logrus
metrics
Package metrics contains utilities for working with metrics in prow.
Package metrics contains utilities for working with metrics in prow.
pluginhelp
Package pluginhelp defines structures that represent plugin help information.
Package pluginhelp defines structures that represent plugin help information.
plugins/blockade
Package blockade defines a plugin that adds the 'do-not-merge/blocked-paths' label to PRs that modify protected file paths.
Package blockade defines a plugin that adds the 'do-not-merge/blocked-paths' label to PRs that modify protected file paths.
plugins/cat
Package cat adds cat images to an issue or PR in response to a /meow comment
Package cat adds cat images to an issue or PR in response to a /meow comment
plugins/cherrypickunapproved
Package cherrypickunapproved adds the `do-not-merge/cherry-pick-not-approved` label to PRs against a release branch which do not have the `cherry-pick-approved` label.
Package cherrypickunapproved adds the `do-not-merge/cherry-pick-not-approved` label to PRs against a release branch which do not have the `cherry-pick-approved` label.
plugins/dog
Package dog adds dog images to the issue or PR in response to a /woof comment
Package dog adds dog images to the issue or PR in response to a /woof comment
plugins/hold
Package hold contains a plugin which will allow users to label their own pull requests as not ready or ready for merge.
Package hold contains a plugin which will allow users to label their own pull requests as not ready or ready for merge.
plugins/lgtm
Package lgtm implements the lgtm plugin
Package lgtm implements the lgtm plugin
plugins/milestone
Package milestone implements the `/milestone` command which allows members of the milestone maintainers team to specify a milestone to be applied to an Issue or PR.
Package milestone implements the `/milestone` command which allows members of the milestone maintainers team to specify a milestone to be applied to an Issue or PR.
plugins/milestonestatus
Package milestonestatus implements the `/status` command which allows members of the milestone maintainers team to specify a `status/*` label to be applied to an Issue or PR.
Package milestonestatus implements the `/status` command which allows members of the milestone maintainers team to specify a `status/*` label to be applied to an Issue or PR.
plugins/override
Package override supports the /override context command.
Package override supports the /override context command.
plugins/pony
Package pony adds pony images to the issue or PR in response to a /pony comment
Package pony adds pony images to the issue or PR in response to a /pony comment
plugins/sigmention
Package sigmention recognize SIG '@' mentions and adds 'sig/*' and 'kind/*' labels as appropriate.
Package sigmention recognize SIG '@' mentions and adds 'sig/*' and 'kind/*' labels as appropriate.
plugins/size
Package size contains a Prow plugin which counts the number of lines changed in a pull request, buckets this number into a few size classes (S, L, XL, etc), and finally labels the pull request with this size.
Package size contains a Prow plugin which counts the number of lines changed in a pull request, buckets this number into a few size classes (S, L, XL, etc), and finally labels the pull request with this size.
plugins/skip
Package skip implements the `/skip` command which allows users to clean up commit statuses of non-blocking presubmits on PRs.
Package skip implements the `/skip` command which allows users to clean up commit statuses of non-blocking presubmits on PRs.
plugins/stage
Package stage defines a Prow plugin that defines the stage of the issue in the features process.
Package stage defines a Prow plugin that defines the stage of the issue in the features process.
plugins/welcome
Package welcome implements a prow plugin to welcome new contributors
Package welcome implements a prow plugin to welcome new contributors
plugins/wip
Package wip will label a PR a work-in-progress if the author provides a prefix to their pull request title to the same effect.
Package wip will label a PR a work-in-progress if the author provides a prefix to their pull request title to the same effect.
scmprovider/reporter
Package reporter contains helpers for writing comments in scm providers.
Package reporter contains helpers for writing comments in scm providers.

Jump to

Keyboard shortcuts

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