-
Notifications
You must be signed in to change notification settings - Fork 183
Add a blog: Introduction to EventWatcher #5787
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5be1dfa
add a blog: eventwatcher-intro
t-kikuc e7ee235
set background color
t-kikuc ab190c0
refine title
t-kikuc 49c3a0f
rename: artifact -> container registry
t-kikuc cbca226
rename 2
t-kikuc 602e41e
nits
t-kikuc a0fdd04
nit
t-kikuc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
--- | ||
date: 2025-04-28 | ||
title: "Introduction to EventWatcher: Connecting CI to PipeCD" | ||
linkTitle: "Introduction to EventWatcher" | ||
weight: 983 | ||
author: Tetsuya Kikuchi ([@t-kikuc](https://github.com/t-kikuc)) | ||
categories: ["Introduction"] | ||
tags: ["Feature Guide"] | ||
--- | ||
|
||
This article explains the basics of "**EventWatcher**", a crucial feature in practical PipeCD usage. | ||
|
||
This article is intended for those who: | ||
- "Don't know how to integrate CI with PipeCD" | ||
- "Have found the EventWatcher feature but can't grasp how it works" | ||
|
||
_This article is based on PipeCD v0.51.2 (latest at the time of writing)._ | ||
|
||
## Background: Why EventWatcher is needed | ||
|
||
Basically, PipeCD is a CD tool that continuously deploys specified config/manifests. | ||
|
||
 | ||
|
||
Deployment typically requires manifest changes. So, how can we "**deploy using a new image (etc.) after CI completion**"? It's annoying to update the manifest repo manually each time. | ||
|
||
 | ||
|
||
This is where the EventWatcher feature comes into play! | ||
|
||
## What is EventWatcher? | ||
|
||
EventWatcher is a feature in PipeCD that seamlessly connects CI and CD. It updates the manifest repo based on events from CI, triggering CD. | ||
|
||
https://pipecd.dev/docs-v0.51.x/user-guide/event-watcher/ | ||
|
||
### Mechanism | ||
|
||
The overall picture of EventWatcher looks like the diagram below. | ||
|
||
 | ||
|
||
The EventWatcher feature itself handles steps 4-6: | ||
|
||
- 1-3. Develop new app code and store the results (container images, etc.) in a container registry | ||
- **4.** Publish an event in CI to pass the new image URI to PipeCD | ||
- **5.** Piped detects the event | ||
- **6.** Update the manifest repo using the data provided by the event (image URI, etc.) | ||
|
||
- 7-8. Automatic deployment occurs through the standard deployment flow of PipeCD | ||
|
||
## Usage | ||
|
||
You need to setup three areas: | ||
|
||
#### 1. Piped Configuration | ||
|
||
1. Which manifest repo events to handle | ||
2. Commit permissions for the manifest repo | ||
|
||
https://pipecd.dev/docs-v0.51.x/user-guide/managing-piped/configuring-event-watcher/ | ||
|
||
#### 2. app.pipecd.yaml Configuration | ||
|
||
1. Which events to handle for the Application (`matcher`) | ||
2. What actions to take for matched events (`handler`) | ||
|
||
(Example) Configuration to update the `spec.template.spec.containers[0].image` field in `deployment.yaml` when the `helloworld-image-update` event is triggered: | ||
|
||
```yaml | ||
apiVersion: pipecd.dev/v1beta1 | ||
kind: KubernetesApp | ||
spec: | ||
name: helloworld | ||
eventWatcher: | ||
- matcher: # Which events to handle | ||
name: helloworld-image-update | ||
handler: # What actions to take | ||
type: GIT_UPDATE | ||
config: | ||
replacements: | ||
- file: deployment.yaml | ||
yamlField: $.spec.template.spec.containers[0].image | ||
``` | ||
|
||
Full configuration reference: | ||
https://pipecd.dev/docs-v0.51.x/user-guide/configuration-reference/#eventwatcher | ||
|
||
#### 3. Event Triggering via pipectl or GitHub Actions | ||
|
||
1. Event name (set in `app.pipecd.yaml` as `matcher.name`) | ||
2. New value (image URI, etc.) | ||
|
||
(Example) Command to trigger an event named `helloworld-image-update` to change the image URI to `ghcr.io/xxx/helloworld:v0.2.0`: | ||
|
||
```sh | ||
pipectl event register \ | ||
--address={CONTROL_PLANE_API_ADDRESS} \ | ||
--api-key={API_KEY} \ | ||
--name=helloworld-image-update \ | ||
--data=ghcr.io/xxx/helloworld:v0.2.0 | ||
``` | ||
|
||
If you use GitHub Actions for your CI, using PipeCD's official `actions-event-register` is recommended (configurations are the same): | ||
|
||
https://github.com/marketplace/actions/pipecd-register-event | ||
|
||
For example, triggering an event named `helloworld-image-update` to change the image URI to `ghcr.io/xxx/helloworld:v0.2.0`: | ||
```yaml | ||
- uses: pipe-cd/[email protected] | ||
with: | ||
api-address: ${{ secrets.API_ADDRESS }} | ||
api-key: ${{ secrets.API_KEY }} | ||
event-name: helloworld-image-update | ||
data: ghcr.io/xxx/helloworld:v0.2.0 | ||
``` | ||
|
||
You can also handle events differently by environment using the `--labels` option, even for events with the same name. | ||
|
||
##### Advanced: `--contexts` Option | ||
|
||
Adding `--contexts` to `pipectl event register` allows you to include various information in the manifest repo commit. For example, passing the **"commit hash and URL of the app repo that triggered the event"** makes it easier to track "which app repo changes caused this event" in the manifest repo. This is particularly useful when deployments occur frequently. | ||
|
||
https://pipecd.dev/docs-v0.51.x/user-guide/event-watcher/#optional-using-contexts | ||
|
||
## Appendix: Code Reading | ||
|
||
The EventWatcher code is consolidated in one file (though it's quite long). Remembering that "EventWatcher runs continuously as a goroutine from Piped startup" makes it slightly easier to read. | ||
|
||
https://github.com/pipe-cd/pipecd/blob/v0.50.2/pkg/app/piped/eventwatcher/eventwatcher.go | ||
|
||
## Conclusion | ||
|
||
Using EventWatcher enables seamless integration between CI and CD. There are various advanced applications, and it would be great to see more examples being shared. | ||
|
||
Additionally, **Deployment Traces** feature enhances the integration of CI and PipeCD. For more details, please see this article: | ||
|
||
https://pipecd.dev/blog/2024/12/26/the-gap-between-ci/cd-and-how-pipecd-appeared-to-fulfill-the-gap/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(Example) Using
actions-event-register
to trigger an event namedhelloworld-image-update
to change the image URI toghcr.io/xxx/helloworld:v0.2.0
:I think clarify with an example could be better 👀
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.
thanks, i fixed
a0fdd04