Repository navigation
feat: serve tag overview page with relacs serve command #98
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
Draft
tommartensen
wants to merge
28
commits into
main
Choose a base branch
from
tm/relacs-serve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e76f02f
add relacs serve command with tag page
tommartensen 6fdac3a
return error if no pipelinerun groups are found
tommartensen f18da01
add repository selector to relacs serve
tommartensen db5a4d0
serve: adapt to the new ListConformaViolations signature
tommartensen 800e644
serve: group conforma violations by component version with arch filter
tommartensen 6fc3e21
serve: note that conforma violations are for the dev policy only
tommartensen 686d93e
serve: render conforma violations for all repositories
tommartensen 7b3dbb6
serve: render the conforma policy note for all repositories
tommartensen c5c01a9
serve: link the custom snapshot in the conforma policy note
tommartensen cb09132
serve: reword the conforma policy note
tommartensen 82c1585
serve: pass the conforma scenario explicitly
tommartensen 0fb95c2
conforma: carry URL and reason for skipped and in-progress runs
tommartensen 91e16b1
serve: add Conforma Release Preview widget and combined tag status
tommartensen d58fa5d
serve: point the conforma policy note at the Release Preview widget
tommartensen 7c73e91
serve: sort pipeline run groups into release milestones
tommartensen abfe597
serve: rename the pipeline milestones
tommartensen 5461d30
serve: drop the conforma policy note from the status box
tommartensen caa5bd4
serve: display the component label as the pipeline run group name
tommartensen bbd9e79
serve: add retest instructions modal to the pipeline milestones
tommartensen ba544da
serve: right-align the pipeline milestone retest button
tommartensen ce78a1e
serve: show running status for pipeline groups and widget
tommartensen ff75858
serve: compute the pipeline running status before the error return
tommartensen f870416
serve: offer retest instructions per failed component group
tommartensen 9aa3dd9
serve: fix arch filter default and treat running conforma as waiting
tommartensen 6c199ca
serve: show waiting badge on the Conforma Dev widget
tommartensen 7a89f1d
serve: copy button for the retest instructions
tommartensen 6194832
serve: one retest comment per failed pipeline in the milestone modal
tommartensen 52b4005
serve: more space between the suggested retest comments
tommartensen 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
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,95 @@ | ||
| package serve | ||
|
|
||
| import ( | ||
| "context" | ||
| "embed" | ||
| "fmt" | ||
| "html/template" | ||
| "io/fs" | ||
| "log" | ||
| "net" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/stackrox/relacs/pkg/client" | ||
| ) | ||
|
|
||
| //go:embed templates/* | ||
| var templateFS embed.FS | ||
|
|
||
| var ( | ||
| homeTmpl *template.Template | ||
| tagTmpl *template.Template | ||
| ) | ||
|
|
||
| var port string | ||
|
|
||
| var ServeCmd = &cobra.Command{ | ||
| Use: "serve", | ||
| Short: "Start a local web server showing release information", | ||
| Long: `Starts a local HTTP server that serves release information as web pages`, | ||
| RunE: runServe, | ||
| } | ||
|
|
||
| func init() { | ||
| ServeCmd.Flags().StringVar(&port, "port", "8080", "Port to listen on") | ||
| } | ||
|
|
||
| func parsePageTemplate(files ...string) (*template.Template, error) { | ||
| return template.ParseFS(templateFS, files...) | ||
| } | ||
|
|
||
| func runServe(cmd *cobra.Command, args []string) error { | ||
| var err error | ||
| homeTmpl, err = parsePageTemplate("templates/base.html", "templates/home.html") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse home template: %w", err) | ||
| } | ||
| tagTmpl, err = parsePageTemplate("templates/base.html", "templates/tag.html") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse tag template: %w", err) | ||
| } | ||
|
|
||
| c, err := client.NewClient() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create client: %w", err) | ||
| } | ||
|
|
||
| staticFS, err := fs.Sub(templateFS, "templates/static") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create static file system: %w", err) | ||
| } | ||
|
|
||
| mux := http.NewServeMux() | ||
| mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS)))) | ||
| mux.HandleFunc("GET /{$}", handleHome()) | ||
| mux.HandleFunc("GET /tag", handleTag(c)) | ||
|
|
||
| addr := net.JoinHostPort("localhost", port) | ||
| server := &http.Server{ | ||
| Addr: addr, | ||
| Handler: mux, | ||
| ReadHeaderTimeout: 10 * time.Second, | ||
| } | ||
|
|
||
| ctx := cmd.Context() | ||
| shutdownDone := make(chan struct{}) | ||
| go func() { | ||
| defer close(shutdownDone) | ||
| <-ctx.Done() | ||
| shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| if err := server.Shutdown(shutdownCtx); err != nil { | ||
| log.Printf("Server shutdown error: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| log.Printf("Server listening on http://%s", addr) | ||
| err = server.ListenAndServe() | ||
| if err == http.ErrServerClosed { | ||
| <-shutdownDone | ||
| return nil | ||
| } | ||
| return err | ||
| } | ||
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,48 @@ | ||
| package serve | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "html/template" | ||
| "log" | ||
| "net/http" | ||
|
|
||
| "github.com/stackrox/relacs/pkg/client" | ||
| "github.com/stackrox/relacs/pkg/config" | ||
| "github.com/stackrox/relacs/pkg/serve" | ||
| ) | ||
|
|
||
| func renderTemplate(w http.ResponseWriter, tmpl *template.Template, data any) { | ||
| var buf bytes.Buffer | ||
| // Start rendering from the outermost template; it pulls in child-defined blocks. | ||
| if err := tmpl.ExecuteTemplate(&buf, "base.html", data); err != nil { | ||
| http.Error(w, err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| _, err := buf.WriteTo(w) | ||
| if err != nil { | ||
| log.Printf("Failed to write template to response: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func handleHome() http.HandlerFunc { | ||
| return func(w http.ResponseWriter, r *http.Request) { | ||
| renderTemplate(w, homeTmpl, nil) | ||
| } | ||
| } | ||
|
|
||
| func handleTag(c *client.Client) http.HandlerFunc { | ||
| return func(w http.ResponseWriter, r *http.Request) { | ||
| tag := r.URL.Query().Get("tag") | ||
| if tag == "" { | ||
| http.Error(w, "Missing required query parameter: tag", http.StatusBadRequest) | ||
| return | ||
| } | ||
| repo := r.URL.Query().Get("repo") | ||
| if repo == "" { | ||
| repo = config.MainGitHubRepository | ||
| } | ||
|
|
||
| data := serve.FetchTagData(r.Context(), c, repo, tag) | ||
| renderTemplate(w, tagTmpl, data) | ||
| } | ||
| } |
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,17 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>relacs{{block "title" .}}{{end}}</title> | ||
| <link rel="stylesheet" href="/static/style.css"> | ||
| </head> | ||
| <body> | ||
| <nav> | ||
| <a href="/">relacs</a> | ||
| </nav> | ||
| <div class="container"> | ||
| {{block "content" .}}{{end}} | ||
| </div> | ||
| </body> | ||
| </html> |
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,35 @@ | ||
| {{template "base.html" .}} | ||
|
|
||
| {{define "title"}} - Home{{end}} | ||
|
|
||
| {{define "content"}} | ||
| <h1 style="margin-bottom: 1rem;">Tags</h1> | ||
|
|
||
| <div class="card"> | ||
| <h2>Tag</h2> | ||
| <p style="margin-bottom: 1rem; color: var(--color-text-secondary);"> | ||
| View pipeline status, artifacts, and Conforma results for a specific tag. | ||
| </p> | ||
| <form method="GET" action="/tag"> | ||
| <div class="form-row"> | ||
| <div class="form-group"> | ||
| <label for="repo">Repository</label> | ||
| <select id="repo" name="repo"> | ||
| <option value="collector">collector</option> | ||
| <option value="fact">fact</option> | ||
| <option value="scanner">scanner</option> | ||
| <option value="stackrox" selected>stackrox</option> | ||
| </select> | ||
| </div> | ||
| <div class="form-group" style="flex: 1;"> | ||
| <label for="tag">Tag</label> | ||
| <input type="text" id="tag" name="tag" placeholder="5.0.0-rc.1" required> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label> </label> | ||
| <button type="submit">Go</button> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| {{end}} |
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,123 @@ | ||
| :root { | ||
| --color-bg: #f5f5f5; | ||
| --color-surface: #ffffff; | ||
| --color-text: #1a1a1a; | ||
| --color-text-secondary: #555; | ||
| --color-border: #ddd; | ||
| --color-passed: #16a34a; | ||
| --color-passed-bg: #dcfce7; | ||
| --color-failed: #dc2626; | ||
| --color-failed-bg: #fee2e2; | ||
| --color-warning: #ca8a04; | ||
| --color-warning-bg: #fef9c3; | ||
| --color-link: #2563eb; | ||
| --color-nav: #1e293b; | ||
| } | ||
| * { margin: 0; padding: 0; box-sizing: border-box; } | ||
| body { | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; | ||
| background: var(--color-bg); | ||
| color: var(--color-text); | ||
| line-height: 1.5; | ||
| } | ||
| nav { | ||
| background: var(--color-nav); | ||
| color: #fff; | ||
| padding: 0.75rem 1.5rem; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 1.5rem; | ||
| } | ||
| nav a { color: #fff; text-decoration: none; font-weight: 600; font-size: 1.1rem; } | ||
| nav a:hover { opacity: 0.85; } | ||
| .container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; } | ||
| a { color: var(--color-link); text-decoration: none; } | ||
| a:hover { text-decoration: underline; } | ||
| .card { | ||
| background: var(--color-surface); | ||
| border: 1px solid var(--color-border); | ||
| border-radius: 8px; | ||
| padding: 1.25rem; | ||
| margin-bottom: 1rem; | ||
| } | ||
| .card h2 { margin-bottom: 0.75rem; font-size: 1.1rem; } | ||
| .badge { | ||
| display: inline-block; | ||
| padding: 0.25rem 0.75rem; | ||
| border-radius: 9999px; | ||
| font-size: 0.85rem; | ||
| font-weight: 600; | ||
| } | ||
| .badge-passed { background: var(--color-passed-bg); color: var(--color-passed); } | ||
| .badge-failed { background: var(--color-failed-bg); color: var(--color-failed); } | ||
| .badge-warning { background: var(--color-warning-bg); color: var(--color-warning); } | ||
| .badge-mock { background: #e0e7ff; color: #4338ca; font-style: italic; } | ||
| .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; } | ||
| .kv { margin-bottom: 0.5rem; } | ||
| .kv dt { font-size: 0.8rem; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.05em; } | ||
| .kv dd { font-size: 0.95rem; word-break: break-all; } | ||
| table { width: 100%; border-collapse: collapse; font-size: 0.9rem; } | ||
| th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--color-border); } | ||
| th { background: var(--color-bg); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-secondary); } | ||
| .group-header { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| padding: 0.75rem 0; | ||
| font-weight: 600; | ||
| border-bottom: 1px solid var(--color-border); | ||
| cursor: pointer; | ||
| } | ||
| .group-header:hover { opacity: 0.8; } | ||
| .section-header { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| font-size: 1.1rem; | ||
| font-weight: 600; | ||
| cursor: pointer; | ||
| } | ||
| .section-header:hover { opacity: 0.8; } | ||
| details summary { list-style: none; } | ||
| details summary::-webkit-details-marker { display: none; } | ||
| details[open] > summary .chevron { transform: rotate(90deg); } | ||
| .chevron { transition: transform 0.15s; display: inline-block; } | ||
| .errors { background: var(--color-failed-bg); border: 1px solid var(--color-failed); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; } | ||
| .note { background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 8px; padding: 0.75rem 1rem; margin: 0.5rem 0; font-size: 0.85rem; color: var(--color-text-secondary); } | ||
| .tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--color-border); margin: 0.75rem 0; } | ||
| .tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 0.5rem 0.75rem; font-size: 0.9rem; font-weight: 500; color: var(--color-text-secondary); cursor: pointer; } | ||
| .tab:hover { color: var(--color-text); } | ||
| .tab.active { color: var(--color-text); border-bottom-color: var(--color-link); } | ||
| .retest-button { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 0 0.25rem; margin-left: auto; } | ||
| .retest-button.disabled { opacity: 0.4; cursor: not-allowed; } | ||
| .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 100; } | ||
| .modal-content { max-width: 640px; width: 90%; } | ||
| .modal-content pre { white-space: pre-wrap; word-break: break-all; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 8px; padding: 0.75rem 1rem; } | ||
| .copy-wrapper { position: relative; margin-bottom: 0.75rem; } | ||
| .copy-button { position: absolute; top: 0.5rem; right: 0.5rem; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 6px; cursor: pointer; padding: 0.25rem 0.5rem; font-size: 0.85rem; } | ||
| .copy-button:hover { opacity: 0.8; } | ||
| .errors li { margin-left: 1.25rem; color: var(--color-failed); } | ||
| input[type="text"], input[type="number"], select { | ||
| padding: 0.5rem 0.75rem; | ||
| border: 1px solid var(--color-border); | ||
| border-radius: 6px; | ||
| font-size: 0.95rem; | ||
| width: 100%; | ||
| font-family: inherit; | ||
| background: var(--color-surface); | ||
| } | ||
| button { | ||
| padding: 0.5rem 1.25rem; | ||
| background: var(--color-link); | ||
| color: #fff; | ||
| border: none; | ||
| border-radius: 6px; | ||
| font-size: 0.95rem; | ||
| cursor: pointer; | ||
| font-weight: 500; | ||
| } | ||
| button:hover { opacity: 0.9; } | ||
| .form-row { display: flex; gap: 0.75rem; align-items: end; } | ||
| .form-group { display: flex; flex-direction: column; gap: 0.25rem; } | ||
| .form-group label { font-size: 0.85rem; font-weight: 500; color: var(--color-text-secondary); } | ||
| @media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.