Skip to content

feat(hooks): per-deployment HTTP webhook hooks#1427

Open
foofybuster wants to merge 1 commit into
kimdre:mainfrom
foofybuster:feat/deployment-hooks
Open

feat(hooks): per-deployment HTTP webhook hooks#1427
foofybuster wants to merge 1 commit into
kimdre:mainfrom
foofybuster:feat/deployment-hooks

Conversation

@foofybuster

Copy link
Copy Markdown

What

Adds per-deployment HTTP webhook hooks. A deploy config can declare hooks.on_success and hooks.on_failure lists; each entry POSTs a JSON payload to an endpoint when the deployment succeeds or fails.

Why

Lets external systems (CI, alerting, chatops) react to doco-cd deployments without polling — e.g. notify a channel on success or page on failure.

Config

name: some-project
hooks:
  on_success:
    - url: https://ci.example.com/notify
      headers:
        Authorization: Bearer xxx
  on_failure:
    - url: https://alerts.example.com/webhook
      method: PUT   # defaults to POST

Fields per entry: url (required, http/https), method (default POST), headers (optional map).

Payload

JSON body (Content-Type: application/json):

Field Description
event success or failure
repository source repo / OCI artifact name
stack deployment / stack name
revision deployed reference + commit (e.g. main (abc1234))
job_id unique job id
images resolved image refs (name:tag) of the changed services; omitted when empty
error failure reason (failure events only)

Behaviour

  • Success hooks fire from the post-deploy stage; failure hooks from StageManager.NotifyFailure.
  • Best-effort: 10s timeout per request; a non-2xx response or unreachable endpoint is logged but never fails the deployment.
  • Config validated up front (Hooks.Validate rejects empty / non-http(s) URLs).
  • Multi-doc deploy YAML and allowOverride per-target overrides supported.

Tests

  • internal/hook: URL validation, send (method/headers/body), non-2xx + bad-URL paths.
  • internal/config/deploy: hook parsing from YAML, invalid-URL rejection, multi-doc handling.
  • internal/stages: changedServiceImages (dedup/sort, missing-image, nil-project).

Notes

images currently reflects only changed services, so it is omitted on deploys with no file-detected service changes (e.g. force-recreate / mismatch-driven redeploys). Can be widened to all stack services if desired.

Add deploy-config `hooks.on_success` / `hooks.on_failure` lists that POST
a JSON payload (event, repository, stack, revision, job_id, images, error)
to configured endpoints. Fired from the post-deploy stage on success and
from NotifyFailure on failure. Best-effort: hook failures are logged and
never abort the deployment.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.45055% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.99%. Comparing base (87be85a) to head (1964955).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
internal/stages/types.go 30.18% 37 Missing ⚠️
internal/hook/hook.go 87.09% 2 Missing and 2 partials ⚠️
internal/stages/stage_4_post-deploy.go 0.00% 4 Missing ⚠️
internal/stages/run.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1427      +/-   ##
==========================================
+ Coverage   44.92%   44.99%   +0.07%     
==========================================
  Files         130      131       +1     
  Lines       10858    10934      +76     
==========================================
+ Hits         4878     4920      +42     
- Misses       5341     5373      +32     
- Partials      639      641       +2     
Flag Coverage Δ
unittests 44.99% <49.45%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kimdre

kimdre commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Does this also work with auto-discovery and remote repositories?

@foofybuster

Copy link
Copy Markdown
Author

Does this also work with auto-discovery and remote repositories?

I've already tested on remote repositories in my environments.

Let me validate whether it works properly with auto-discovery.

@kimdre kimdre added the feature New feature label Jun 12, 2026
@foofybuster

foofybuster commented Jun 18, 2026

Copy link
Copy Markdown
Author

@kimdre I'm sorry for taking too long.
I have a concern about this PR. I changed some behavior of deployment settings when force_image_pull: true and force_recreate: true

Should Doco-cd force to pull an image or recreate a container when the Doco-cd is restarted? [e.g. docker restart doco-cd]

As I understood your current version will not force when the Doco-cd only restarts. Is it a bug or your intent?
Note that if there are any change in a service's working_dir and then restarting Doco-cd cause recreating the service's container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants