pipecd icon indicating copy to clipboard operation
pipecd copied to clipboard

Link application repository PR and the PipeCD deployment related to it.

Open ffjlabo opened this issue 1 year ago • 1 comments

What would you like to be added:

When separating the app code repo and manifests repo by using event watcher, it would be nice to link the app repo PR and PipeCD deployment.

Why is this needed:

There are some use cases. For example,

  • rollback the app code repo quickly when the incident occurs.
  • record the time from when a PR is closed until the PipeCD deployment is triggered

ffjlabo avatar Jul 08 '24 05:07 ffjlabo

I investigated the plan to solve this issue.

Pre-condition:

  • The event operation flow is as follows, so we can only use the commit information of the manifest repository for the deployment operation.
    1. Commit to the Application repository
    2. pipe-cd/actions-event-register is invoked
      • In this action, pipectl event register is invoked
    3. piped receives the event from the control plane server and commits to the manifest repository
    4. piped pull the manifest repository and detect changes
    5. piped deploy changes to the infrastructure, we can use only the information of the pulled commits.
  • We can use the text/template feature in the commit message through the event GIT_UPDATE; this is undocumented.
    • https://github.com/pipe-cd/pipecd/blob/713fb032551ce01dd8d15c3ffa7063d91cf4cca1/pkg/app/piped/eventwatcher/eventwatcher.go#L772-L789

Plan:

Overview:

Pass the context information through actions-event-register -> pipectl -> control-plane-server -> piped -> manifest repo -> piped

Detail

  1. collect GitHub repo/commit context in actions-event-register
  2. create a new option --context to the pipectl and pass contexts to it
  3. add map<string,string> context here and pass contexts
    • https://github.com/pipe-cd/pipecd/blob/713fb032551ce01dd8d15c3ffa7063d91cf4cca1/pkg/app/server/service/apiservice/service.proto#L228-L232
  4. add map<string,string> context here and store contexts
    • https://github.com/pipe-cd/pipecd/blob/713fb032551ce01dd8d15c3ffa7063d91cf4cca1/pkg/model/event.proto#L29-L55
  5. add Context map[string]string here and pass contexts
    • https://github.com/pipe-cd/pipecd/blob/713fb032551ce01dd8d15c3ffa7063d91cf4cca1/pkg/app/piped/eventwatcher/eventwatcher.go#L766-L770
  6. add a document about the text/template feature of the GIT_UPDATE event
  7. finally, users can use {{ .Context.GITHUB_SHA }} or something like this in the commit message format through the GIT_UPDATE event config so that users can use the application repository context in the deployment SCRIPT_RUN stage or from the webhook.

Warashi avatar Jul 10 '24 02:07 Warashi

📝 It might be useful to add some metadata as git trailer https://git-scm.com/docs/git-interpret-trailers#_description

ffjlabo avatar Oct 23 '24 09:10 ffjlabo

We will fix actions-event-register after releasing this fix. Follow https://github.com/pipe-cd/pipecd/issues/5307 for it.

ffjlabo avatar Nov 05 '24 03:11 ffjlabo