Skip to content

Commit

Permalink
feat: Moving templates and static to embed
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <bob@vibioh.fr>
  • Loading branch information
ViBiOh committed Feb 23, 2021
1 parent 8ff7fbc commit adac0f9
Show file tree
Hide file tree
Showing 28 changed files with 34 additions and 17 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ ENV ZONEINFO /zoneinfo.zip
COPY zoneinfo.zip /zoneinfo.zip
COPY ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

COPY templates/ /templates
COPY static/ /static

HEALTHCHECK --retries=5 CMD [ "/ketchup", "-url", "http://localhost:1080/health" ]
ENTRYPOINT [ "/ketchup" ]

Expand Down
6 changes: 5 additions & 1 deletion cmd/ketchup/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"database/sql"
"embed"
"flag"
"net/http"
"os"
Expand Down Expand Up @@ -41,6 +42,9 @@ const (
signupPath = "/signup"
)

//go:embed templates static
var content embed.FS

func initAuth(db *sql.DB) (authService.App, authMiddleware.App) {
authProvider := authStore.New(db)
identProvider := authIdent.New(authProvider)
Expand Down Expand Up @@ -92,7 +96,7 @@ func main() {
logger.Fatal(err)
defer mailerApp.Close()

publicRendererApp, err := renderer.New(rendererConfig, ketchup.FuncMap)
publicRendererApp, err := renderer.New(rendererConfig, content, ketchup.FuncMap)
logger.Fatal(err)

schedulerApp := scheduler.New(schedulerConfig, repositoryServiceApp, ketchupServiceApp, mailerApp)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions templates/ketchup.html → cmd/ketchup/templates/ketchup.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ <h2 class="header small ellipsis">{{ .Repository.Name }}</h2>

<p class="no-margin padding">
<span>
<a class="{{ if ne .Version (index .Repository.Versions .Pattern) }}danger{{ else }}success{{ end }}" href="{{ .Repository.URL }}">{{ .Version }}</a>
<a class="{{ if ne .Version (index .Repository.Versions .Pattern) }}danger{{ else }}success{{ end }}" href="{{ .Repository.URL .Pattern }}">{{ .Version }}</a>
</span>

{{ if ne .Version (index .Repository.Versions .Pattern) }}
<span>
&nbsp;->&nbsp;<a class="success" href="{{ .Repository.URL }}">{{ index .Repository.Versions .Pattern }}</a>
&nbsp;->&nbsp;<a class="success" href="{{ .Repository.URL .Pattern }}">{{ index .Repository.Versions .Pattern }}</a>
</span>
{{ end }}
</p>
Expand All @@ -233,7 +233,7 @@ <h2 class="header small ellipsis">{{ .Repository.Name }}</h2>

<div>
{{ if ne .Version (index .Repository.Versions .Pattern) }}
<a href="{{ .Repository.CompareURL .Version }}" class="button button-icon" title="Compare">
<a href="{{ .Repository.CompareURL .Version .Pattern }}" class="button button-icon" title="Compare">
<img class="icon" src="/svg/eyes?fill=silver" alt="Compare icon">
</a>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/ViBiOh/auth/v2 v2.6.7
github.com/ViBiOh/httputils/v4 v4.0.0
github.com/ViBiOh/httputils/v4 v4.2.0
github.com/ViBiOh/mailer v1.15.0
github.com/lib/pq v1.9.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ github.com/ViBiOh/auth/v2 v2.6.7 h1:TS6bNHCvozTmpgU0ttq7fji7cCNIbXvjPHwKfepoo2E=
github.com/ViBiOh/auth/v2 v2.6.7/go.mod h1:yiSggirLxzFEN25dHrQ3NHyZsgTXFFZ12qbWMLNsbaI=
github.com/ViBiOh/httputils/v3 v3.37.1 h1:TQU5DC20RttMASVzK88DYNonADdnJko/ri220d067VI=
github.com/ViBiOh/httputils/v3 v3.37.1/go.mod h1:ySOLanXZ/Ll0UGnBFZjLd0aTtf3eVQe56yurhkDeR1Q=
github.com/ViBiOh/httputils/v4 v4.0.0 h1:FW7YanNVCcDaKCQ7UAramPv2ovuW2OZndYs8ftHEFb8=
github.com/ViBiOh/httputils/v4 v4.0.0/go.mod h1:+mwW3YVDPI9y1Fx1ZXbehJPqWDFtlDLsNL5otGeBSBw=
github.com/ViBiOh/httputils/v4 v4.2.0 h1:Gam5Q9sb2Dw4EDDEpYEBIMOpqTRw9sp+Zb30aPF6UP4=
github.com/ViBiOh/httputils/v4 v4.2.0/go.mod h1:+mwW3YVDPI9y1Fx1ZXbehJPqWDFtlDLsNL5otGeBSBw=
github.com/ViBiOh/mailer v1.15.0 h1:OkDimn47BP48+eg+quP/LwphXRkX3b/XgK3HQKH5LOM=
github.com/ViBiOh/mailer v1.15.0/go.mod h1:Y9FNFl9zmI0H1TUZR6V5nELRoHKojW+VU+DOag6onlA=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
Expand Down Expand Up @@ -266,7 +267,6 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271 h1:WhxRHzgeVGETMlmVfqhRn8RIeeNoPr2Czh33I4Zdccw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down
10 changes: 5 additions & 5 deletions pkg/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r Repository) AddVersion(pattern, version string) Repository {
}

// URL format the URL of given repository with current version
func (r Repository) URL() string {
func (r Repository) URL(pattern string) string {
if r.Kind == Helm {
parts := strings.SplitN(r.Name, "@", 2)
if len(parts) > 1 {
Expand All @@ -71,16 +71,16 @@ func (r Repository) URL() string {
return r.Name
}

return fmt.Sprintf("%s/%s/releases/tag/%s", githubURL, r.Name, r.Versions[DefaultPattern])
return fmt.Sprintf("%s/%s/releases/tag/%s", githubURL, r.Name, r.Versions[pattern])
}

// CompareURL format the URL of given repository compared against given version
func (r Repository) CompareURL(version string) string {
func (r Repository) CompareURL(version string, pattern string) string {
if r.Kind == Helm {
return r.URL()
return r.URL(pattern)
}

return fmt.Sprintf("%s/%s/compare/%s...%s", githubURL, r.Name, r.Versions[DefaultPattern], version)
return fmt.Sprintf("%s/%s/compare/%s...%s", githubURL, r.Name, r.Versions[pattern], version)
}

// ParseRepositoryKind parse raw string into a RepositoryKind
Expand Down
20 changes: 18 additions & 2 deletions pkg/model/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,45 @@ func TestString(t *testing.T) {
}

func TestURL(t *testing.T) {
type args struct {
pattern string
}

var cases = []struct {
intention string
instance Repository
args args
want string
}{
{
"helm",
NewRepository(0, Helm, "app@https://charts.vibioh.fr"),
args{
pattern: DefaultPattern,
},
"https://charts.vibioh.fr",
},
{
"invalid",
NewRepository(0, Helm, "charts.fr"),
args{
pattern: DefaultPattern,
},
"charts.fr",
},
{
"github",
NewRepository(0, Github, "vibioh/ketchup").AddVersion(DefaultPattern, "1.0.0"),
args{
pattern: DefaultPattern,
},
"https://github.com/vibioh/ketchup/releases/tag/1.0.0",
},
}

for _, tc := range cases {
t.Run(tc.intention, func(t *testing.T) {
if got := tc.instance.URL(); got != tc.want {
if got := tc.instance.URL(tc.args.pattern); got != tc.want {
t.Errorf("URL() = `%s`, want `%s`", got, tc.want)
}
})
Expand All @@ -68,6 +82,7 @@ func TestURL(t *testing.T) {
func TestCompareURL(t *testing.T) {
type args struct {
version string
pattern string
}

var cases = []struct {
Expand All @@ -87,14 +102,15 @@ func TestCompareURL(t *testing.T) {
NewRepository(0, Github, "vibioh/ketchup").AddVersion(DefaultPattern, "1.1.0"),
args{
version: "1.0.0",
pattern: DefaultPattern,
},
"https://github.com/vibioh/ketchup/compare/1.1.0...1.0.0",
},
}

for _, tc := range cases {
t.Run(tc.intention, func(t *testing.T) {
if got := tc.instance.CompareURL(tc.args.version); got != tc.want {
if got := tc.instance.CompareURL(tc.args.version, tc.args.pattern); got != tc.want {
t.Errorf("URL() = `%s`, want `%s`", got, tc.want)
}
})
Expand Down

0 comments on commit adac0f9

Please sign in to comment.