Skip to content
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

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

Open
ffjlabo opened this issue Jul 8, 2024 · 1 comment
Open
Labels
good first issue Good for newcomers kind/enhancement New feature or request

Comments

@ffjlabo
Copy link
Member

ffjlabo commented Jul 8, 2024

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 ffjlabo added the kind/enhancement New feature or request label Jul 8, 2024
@Warashi
Copy link
Contributor

Warashi commented Jul 10, 2024

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.
    • // parseCommitMsg parses event watcher's commit message.
      // Currently, only {{ .Value }} and {{ .EventName }} are supported.
      func parseCommitMsg(msg string, args argsTemplate) string {
      if msg == "" {
      return fmt.Sprintf(defaultCommitMessageFormat, args.Value, args.EventName)
      }
      t, err := template.New("EventWatcherCommitMsgTemplate").Parse(msg)
      if err != nil {
      return msg
      }
      buf := new(strings.Builder)
      if err := t.Execute(buf, args); err != nil {
      return msg
      }
      return buf.String()
      }

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
    • message RegisterEventRequest {
      string name = 1 [(validate.rules).string.min_len = 1];
      string data = 2 [(validate.rules).string.min_len = 1];
      map<string,string> labels = 3 [(validate.rules).map.keys.string.min_len = 1, (validate.rules).map.values.string.min_len = 1];
      }
  4. add map<string,string> context here and store contexts
    • message Event {
      reserved 7;
      // The generated unique identifier.
      string id = 1 [(validate.rules).string.min_len = 1];
      // The name of event.
      string name = 2 [(validate.rules).string.min_len = 1];
      // The data of event.
      string data = 3 [(validate.rules).string.min_len = 1];
      // The ID of the project this event belongs to.
      string project_id = 4 [(validate.rules).string.min_len = 1];
      // The key/value pairs that are attached to event.
      // This is intended to be used to specify additional attributes of event.
      map<string,string> labels = 5;
      // A fixed-length identifier consists of its own name and labels.
      string event_key = 6 [(validate.rules).string.min_len = 1];
      // The handle status of event.
      EventStatus status = 8 [(validate.rules).enum.defined_only = true];
      string status_description = 9;
      // Unix time when the event was handled.
      int64 handled_at = 13;
      // Unix time when the event was created.
      int64 created_at = 14 [(validate.rules).int64.gt = 0];
      // Unix time of the last time when the event was updated.
      int64 updated_at = 15 [(validate.rules).int64.gt = 0];
      }
  5. add Context map[string]string here and pass contexts
  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 Warashi added the good first issue Good for newcomers label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/enhancement New feature or request
Projects
Status: 🤔 In voting
Development

No branches or pull requests

2 participants