From 8e7ac03e0a48a90cd8c92b4e110d6fcd3f5ed4bb Mon Sep 17 00:00:00 2001 From: encalada Date: Fri, 28 Jun 2024 16:59:34 +0200 Subject: [PATCH] add README Signed-off-by: encalada --- github-webhook/README.md | 24 ++++++++++++++++++++++++ github-webhook/cmd/builder/main.go | 17 ++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 github-webhook/README.md diff --git a/github-webhook/README.md b/github-webhook/README.md new file mode 100644 index 00000000..a0071e14 --- /dev/null +++ b/github-webhook/README.md @@ -0,0 +1,24 @@ +# Integrating IBM Cloud Code Engine with Github and Event Notifications + +Automating software deployment upon changes in your Git repository isn't a novel idea. In IBM Cloud Code Engine, we provide samples like [Github](https://github.com/IBM/CodeEngine/tree/main/github) or [Github Action Workflows](https://github.com/IBM/CodeEngine/tree/main/github-action-workflows), enabling users to respond to changes in their repositories through Code Engine workloads. + +Given the importance of automated continuous deployments for cloud-native applications, this blog post delves deeper into the topic and proposes a new architecture. + +By integrating, Git, Code Engine and IBM Cloud [Event Notifications](https://cloud.ibm.com/docs/event-notifications?topic=event-notifications-getting-started), we can offer users an end-to-end workflow from changes in Git to notifications across multiple destinations, including a Code Engine Job. + +## Architecture + +Our starting point is Git. Cloud Native Applications code is commonly hosted in version control systems like Git. Through Github [webhooks](https://docs.github.com/en/webhooks), changes such as `push` events(_e.g. commiting to your main branch_) can trigger integrations to take responsive actions. + +Knowing when these events occur leads us to the question; what actions can we take? Before addressing this, let's consider who should be notified about such actions. + + +## Using IBM Cloud Event Notifications + + +## Tell me more! + +## Try It! + + + diff --git a/github-webhook/cmd/builder/main.go b/github-webhook/cmd/builder/main.go index c388cb20..7ce8875a 100644 --- a/github-webhook/cmd/builder/main.go +++ b/github-webhook/cmd/builder/main.go @@ -140,7 +140,7 @@ func main() { l.Info("non knative services found, that match the image output", "namespace", ns, "image", imageOutput) } else { l.Info("A matching knative service was found", "namespace", ns, "image", imageOutput) - deleteService(ctx, servingClient, svc) + updateService(ctx, servingClient, svc) } } @@ -229,12 +229,11 @@ func findService(ctx context.Context, servingClient *serving.ServingV1Client, na return nil, err } - for i := range services.Items { - var service = services.Items[i] - - if userImage, ok := service.Annotations[userImageAnnotation]; ok { - if userImage == image { - return &service, nil + for _, ksvc := range services.Items { + if len(ksvc.Spec.Template.Spec.Containers) > 0 { + userContainer := ksvc.Spec.Template.Spec.Containers[0] + if userContainer.Image == image { + return &ksvc, nil } } } @@ -242,9 +241,9 @@ func findService(ctx context.Context, servingClient *serving.ServingV1Client, na return nil, nil } -func deleteService(ctx context.Context, servingClient *serving.ServingV1Client, service *servingv1.Service) { +func updateService(ctx context.Context, servingClient *serving.ServingV1Client, service *servingv1.Service) { l := *logger - l.Info("deleting Knative servive to force a new revision", "namespace", service.Namespace, "name", service.Name) + l.Info("updating Knative servive to force a new revision", "namespace", service.Namespace, "name", service.Name) annotations := service.Spec.Template.GetAnnotations() if annotations == nil {