Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func New(cfg *conf.Conf) (*Application, error) {
r.Get("/", a.TaskHandler(false))
r.Get("/volumes/*", a.VolumesHandler(6, false))
r.Get("/logs", a.TaskLogsHandler(false))
r.Get("/logz", a.TaskLogzHandler(false))
})
r.Group(func(r chi.Router) {
r.Use(a.RefererMiddleware)
Expand All @@ -177,7 +176,6 @@ func New(cfg *conf.Conf) (*Application, error) {
r.Get("/", a.TaskHandler(true))
r.Get("/volumes/*", a.VolumesHandler(6, true))
r.Get("/logs", a.TaskLogsHandler(true))
r.Get("/logz", a.TaskLogzHandler(true))
})
r.Group(func(r chi.Router) {
r.Use(a.RefererMiddleware)
Expand Down
45 changes: 0 additions & 45 deletions application/logs.go

This file was deleted.

47 changes: 42 additions & 5 deletions application/task.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package application

import (
"bytes"
"context"
"encoding/json"
"fmt"
"html/template"
"net/http"
"net/url"
"os"
"time"

"github.com/docker/docker/pkg/stdcopy"
_claims "github.com/factorysh/microdensity/claims"
"github.com/factorysh/microdensity/html"
"github.com/factorysh/microdensity/task"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/google/uuid"
"github.com/robert-nix/ansihtml"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -182,8 +188,8 @@ func (a *Application) TaskIDHandler(w http.ResponseWriter, r *http.Request) {
}
}

// TaskLogsHandler get a logs for a task
func (a *Application) TaskLogsHandler(latest bool) func(http.ResponseWriter, *http.Request) {
// TaskLogzHandler get a logs for a task
func (a *Application) TaskLogzHandler(latest bool) func(http.ResponseWriter, *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {
l := a.logger.With(
Expand Down Expand Up @@ -219,7 +225,7 @@ func (a *Application) TaskLogsHandler(latest bool) func(http.ResponseWriter, *ht

// just stdout for now
// kudos @ndeloof, @rumpl, @glours
_, err = stdcopy.StdCopy(w, nil, reader)
_, err = stdcopy.StdCopy(w, w, reader)
if err != nil {
l.Error("Task log stdcopy write error", zap.Error(err))
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -232,8 +238,8 @@ func (a *Application) TaskLogsHandler(latest bool) func(http.ResponseWriter, *ht

}

// TaskLogzHandler get a logs for a task
func (a *Application) TaskLogzHandler(latest bool) func(http.ResponseWriter, *http.Request) {
// TaskLogsHandler get a logs for a task, used to get row logs from curl, not used for now
func (a *Application) TaskLogsHandler(latest bool) func(http.ResponseWriter, *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {
l := a.logger.With(
Expand Down Expand Up @@ -267,3 +273,34 @@ func (a *Application) TaskLogzHandler(latest bool) func(http.ResponseWriter, *ht
}
}
}

func (a *Application) renderLogsPageForTask(ctx context.Context, t *task.Task, w http.ResponseWriter) error {

reader, err := t.Logs(ctx, false)
if err != nil {
return err
}

var buffer bytes.Buffer
_, err = stdcopy.StdCopy(&buffer, &buffer, reader)
if err != nil {
return err
}

data, err := NewTaskPage(t, template.HTML(fmt.Sprintf("<pre>%s</pre>", ansihtml.ConvertToHTML(buffer.Bytes()))), a.GitlabURL, "Task Logs", "terminal")
if err != nil {
return err
}

p := html.Page{
Domain: a.Domain,
Detail: fmt.Sprintf("%s / %s - logs", t.Service, t.Commit),
Partial: html.Partial{
Template: taskTemplate,
Data: data,
},
}

w.WriteHeader(http.StatusOK)
return p.Render(w)
}
2 changes: 2 additions & 0 deletions application/task_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type TaskPage struct {
Project string
Commit string
Service string
Branch string
ID string
CreatedAt string
InnerDivClasses string
Expand All @@ -32,6 +33,7 @@ func NewTaskPage(t *task.Task, inner template.HTML, gitlabDomain, InnerTitle, In
Project: prettyPath,
GitlabDomain: gitlabDomain,
Commit: t.Commit,
Branch: t.Branch,
Service: t.Service,
ID: t.Id.String(),
CreatedAt: t.Creation.Format("2006-01-02 15:04:05"),
Expand Down
30 changes: 19 additions & 11 deletions application/templates/task.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<h3>Task Description</h3>
<div class="container task-description">
<h3>Task Description</h3>

<ul>
<li>Project : <a href="{{ .GitlabDomain }}/{{ .Project }}" target="_blank">{{ .Project }}</a></li>
<li>Commit : <a href="{{ .GitlabDomain }}/{{ .Project }}/-/commit/{{ .Commit }}" target="_blank">{{ .Commit }}</a></li>
<li>Created At : {{ .CreatedAt }}</li>
<li>Service : <a href="{{ .Domain }}/service/{{ .Service }}" target="_blank">{{ .Service }}</a></li>
<li>ID : {{ .ID }}</li>
</ul>
<ul>
<li>Project : <a href="{{ .GitlabDomain }}/{{ .Project }}" target="_blank">{{ .Project }}</a></li>
<li>Commit : <a href="{{ .GitlabDomain }}/{{ .Project }}/-/commit/{{ .Commit }}" target="_blank">{{ .Commit }}</a></li>
<li>Created At : {{ .CreatedAt }}</li>
<li>Service : <a href="{{ .Domain }}/service/{{ .Service }}" target="_blank">{{ .Service }}</a></li>
<li>ID : {{ .ID }}
</ul>

<h3>{{ .InnerTitle }}</h3>
<h3>Task Actions</h3>
<a class="button" href="{{ .Domain }}/service/{{ .Service }}/{{ .Project }}/-/{{ .Branch }}/{{ .Commit }}/logs">Logs</a>
<a class="button" href="{{ .Domain }}/service/{{ .Service }}/{{ .Project }}/-/{{ .Branch }}/{{ .Commit }}/volumes/data/result.html">Result</a>
</div>

<div class="container">
<h3>{{ .InnerTitle }}</h3>

<div class="{{ .InnerDivClasses }}">
{{ .Inner }}
<div class="{{ .InnerDivClasses }}">
{{ .Inner }}
</div>
</div>
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/robert-nix/ansihtml v1.0.0 // indirect
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cobra v1.3.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/robert-nix/ansihtml v1.0.0 h1:x/M0hHxcs+vCEGwfXtdWVROatZQRSXhn/akMwvPogB8=
github.com/robert-nix/ansihtml v1.0.0/go.mod h1:CJwclxYaTPc2RfcxtanEACsYuTksh4yDXcNeHHKZINE=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
Expand Down
4 changes: 4 additions & 0 deletions html/templates/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ h6 {
padding: 2rem;
}

.task-description a {
font-weight: bold;
}

.label {
font-weight: bold;
}
Expand Down