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
29
commits into
tm/redo-conforma-commands
Choose a base branch
from
tm/relacs-serve
base: tm/redo-conforma-commands
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
29 commits
Select commit
Hold shift + click to select a range
48fd5ff
list-conforma-*: add --scenario flag for acs-conforma-prod-like
tommartensen 80a0887
add relacs serve command with tag page
tommartensen 4b4a6ec
return error if no pipelinerun groups are found
tommartensen 30b8498
add repository selector to relacs serve
tommartensen bf8544d
serve: adapt to the new ListConformaViolations signature
tommartensen 948550f
serve: group conforma violations by component version with arch filter
tommartensen 7a23917
serve: note that conforma violations are for the dev policy only
tommartensen d807efe
serve: render conforma violations for all repositories
tommartensen 19e8373
serve: render the conforma policy note for all repositories
tommartensen 180eb6e
serve: link the custom snapshot in the conforma policy note
tommartensen b29db1a
serve: reword the conforma policy note
tommartensen 13093bd
serve: pass the conforma scenario explicitly
tommartensen 459c758
conforma: carry URL and reason for skipped and in-progress runs
tommartensen 6cb1f56
serve: add Conforma Release Preview widget and combined tag status
tommartensen 02cd00f
serve: point the conforma policy note at the Release Preview widget
tommartensen c2a8193
serve: sort pipeline run groups into release milestones
tommartensen 3afc517
serve: rename the pipeline milestones
tommartensen 08dddaf
serve: drop the conforma policy note from the status box
tommartensen 62c4f39
serve: display the component label as the pipeline run group name
tommartensen 856c104
serve: add retest instructions modal to the pipeline milestones
tommartensen ca0d2b0
serve: right-align the pipeline milestone retest button
tommartensen dea5c05
serve: show running status for pipeline groups and widget
tommartensen 71f05f0
serve: compute the pipeline running status before the error return
tommartensen 98adbf9
serve: offer retest instructions per failed component group
tommartensen 59fd9d7
serve: fix arch filter default and treat running conforma as waiting
tommartensen ac0d0e2
serve: show waiting badge on the Conforma Dev widget
tommartensen 1695001
serve: copy button for the retest instructions
tommartensen e4dfc5d
serve: one retest comment per failed pipeline in the milestone modal
tommartensen 66c153d
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
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}} |
Oops, something went wrong.
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.