-
Notifications
You must be signed in to change notification settings - Fork 125
Shipwright Triggers API #1008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shipwright Triggers API #1008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ SPDX-License-Identifier: Apache-2.0 | |
- [Defining the Output](#defining-the-output) | ||
- [Defining Retention Parameters](#defining-retention-parameters) | ||
- [Defining Volumes](#defining-volumes) | ||
- [Defining Triggers](#defining-triggers) | ||
- [BuildRun deletion](#BuildRun-deletion) | ||
|
||
## Overview | ||
|
@@ -602,6 +603,109 @@ spec: | |
name: test-config | ||
``` | ||
|
||
### Defining Triggers | ||
|
||
Using the triggers, you can submit `BuildRun` instances when certain events happen. The idea is to be able to trigger Shipwright builds in an event driven fashion, for that purpose you can watch certain types of events. | ||
|
||
**Note**: triggers rely on the [Shipwright Triggers](https://github.com/shipwright-io/triggers) project to be deployed and configured in the same Kubernetes cluster where you run Shipwright Build. If it is not set up, the triggers defined in a Build are ignored. | ||
|
||
The types of events under watch are defined on the `.spec.trigger` attribute, please consider the following example: | ||
|
||
```yaml | ||
apiVersion: shipwright.io/v1alpha1 | ||
kind: Build | ||
spec: | ||
source: | ||
url: https://github.com/shipwright-io/sample-go | ||
contextDir: docker-build | ||
credentials: | ||
name: webhook-secret | ||
trigger: | ||
when: [] | ||
``` | ||
|
||
Certain types of events will use attributes defined on `.spec.source` to complete the information needed in order to dispatch events. | ||
|
||
#### GitHub | ||
|
||
The GitHub type is meant to react upon events coming from GitHub WebHook interface, the events are compared against the existing `Build` resources, and therefore it can identify the `Build` objects based on `.spec.source.url` combined with the attributes on `.spec.trigger.when[].github`. | ||
|
||
To identify a given `Build` object, the first criteria is the repository URL, and then the branch name listed on the GitHub event payload must also match. Following the criteria: | ||
|
||
- First, the branch name is checked against the `.spec.trigger.when[].github.branches` entries | ||
- If the `.spec.trigger.when[].github.branches` is empty, the branch name is compared against `.spec.source.revision` | ||
- If `spec.source.revision` is empty, the default revision name is used ("main") | ||
|
||
The following snippet shows a configuration machting `Push` and `PullRequest` events on the `main` branch, for example: | ||
|
||
```yaml | ||
# [...] | ||
spec: | ||
source: | ||
url: https://github.com/shipwright-io/sample-go | ||
trigger: | ||
when: | ||
- name: push and pull-request on the main branch | ||
type: GitHub | ||
github: | ||
events: | ||
- Push | ||
- PullRequest | ||
branches: | ||
- main | ||
``` | ||
|
||
#### Image | ||
|
||
In order to watch over images, in combination with the [Image](https://github.com/shipwright-io/image) controller, you can trigger new builds when those container image names change. | ||
|
||
For instance, lets imagine the image named `ghcr.io/some/base-image` is used as input for the Build process and every time it changes we would like to trigger a new build. Please consider the following snippet: | ||
|
||
```yaml | ||
# [...] | ||
spec: | ||
trigger: | ||
when: | ||
- name: watching for the base-image changes | ||
type: Image | ||
image: | ||
names: | ||
- ghcr.io/some/base-image:latest | ||
``` | ||
|
||
#### Tekton Pipeline | ||
|
||
Shipwright can also be used in combination with [Tekton Pipeline](https://github.com/tektoncd/pipeline), you can configure the Build to watch for `Pipeline` resources in Kubernetes reacting when the object reaches the desired status (`.objectRef.status`), and is identified either by its name (`.objectRef.name`) or a label selector (`.objectRef.selector`). The example below uses the label selector approach: | ||
|
||
```yaml | ||
# [...] | ||
spec: | ||
trigger: | ||
when: | ||
- name: watching over for the Tekton Pipeline | ||
type: Pipeline | ||
objectRef: | ||
status: | ||
- Succeeded | ||
selector: | ||
label: value | ||
``` | ||
|
||
While the next snippet uses the object name for identification: | ||
|
||
```yaml | ||
# [...] | ||
spec: | ||
trigger: | ||
when: | ||
- name: watching over for the Tekton Pipeline | ||
type: Pipeline | ||
objectRef: | ||
status: | ||
- Succeeded | ||
Comment on lines
+704
to
+705
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may need to check the ship again, why do we filter on the status here? Should not it be always on successful completion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to have a flexible workflow we should allow any state to be filled in, and it's expected that "Succeeded" is the most common. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flexibility is fine, but out of interest, what would be the use case to trigger a BuildRun on a Pipeline status change other than to Succeeded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "status" is reported as a string, and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my understanding, does Pipeline CRD has a state, or is more about PipelineRun states? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I haven't been clear before. The object that carries the state is the |
||
name: tekton-pipeline-name | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the BuildRun trigger? In my own subjective opinion, that is more important than pipelines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The triggers is a mechanism to instantiate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I meant Build trigger. But I just notice it is not part of the SHIP, then it is fine for now. It is being discussed here: shipwright-io/community#75 (comment). |
||
### Sources | ||
|
||
Sources represent remote artifacts, as in external entities added to the build context before the actual Build starts. Therefore, you may employ `.spec.sources` to download artifacts from external repositories. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not here be the name of the Image resource that must be in the same namespace ? Especially if the image is not at all in an external registry, it would be complicated to provide such an image name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we are looking for a fully qualified image name and to later on rely on the image controller to handle this business logic. However, the image name is a free form string initially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @ricardomaraschini