diff --git a/Dockerfile b/Dockerfile index eccd59c8..35c9a3f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/cmd/ketchup/api.go b/cmd/ketchup/api.go index c1ddee69..45ed8831 100644 --- a/cmd/ketchup/api.go +++ b/cmd/ketchup/api.go @@ -2,6 +2,7 @@ package main import ( "database/sql" + "embed" "flag" "net/http" "os" @@ -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) @@ -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) diff --git a/static/favicon/android-chrome-192x192.png b/cmd/ketchup/static/favicon/android-chrome-192x192.png similarity index 100% rename from static/favicon/android-chrome-192x192.png rename to cmd/ketchup/static/favicon/android-chrome-192x192.png diff --git a/static/favicon/android-chrome-512x512.png b/cmd/ketchup/static/favicon/android-chrome-512x512.png similarity index 100% rename from static/favicon/android-chrome-512x512.png rename to cmd/ketchup/static/favicon/android-chrome-512x512.png diff --git a/static/favicon/apple-touch-icon.png b/cmd/ketchup/static/favicon/apple-touch-icon.png similarity index 100% rename from static/favicon/apple-touch-icon.png rename to cmd/ketchup/static/favicon/apple-touch-icon.png diff --git a/static/favicon/browserconfig.xml b/cmd/ketchup/static/favicon/browserconfig.xml similarity index 100% rename from static/favicon/browserconfig.xml rename to cmd/ketchup/static/favicon/browserconfig.xml diff --git a/static/favicon/favicon-16x16.png b/cmd/ketchup/static/favicon/favicon-16x16.png similarity index 100% rename from static/favicon/favicon-16x16.png rename to cmd/ketchup/static/favicon/favicon-16x16.png diff --git a/static/favicon/favicon-32x32.png b/cmd/ketchup/static/favicon/favicon-32x32.png similarity index 100% rename from static/favicon/favicon-32x32.png rename to cmd/ketchup/static/favicon/favicon-32x32.png diff --git a/static/favicon/favicon.ico b/cmd/ketchup/static/favicon/favicon.ico similarity index 100% rename from static/favicon/favicon.ico rename to cmd/ketchup/static/favicon/favicon.ico diff --git a/static/favicon/mstile-144x144.png b/cmd/ketchup/static/favicon/mstile-144x144.png similarity index 100% rename from static/favicon/mstile-144x144.png rename to cmd/ketchup/static/favicon/mstile-144x144.png diff --git a/static/favicon/mstile-150x150.png b/cmd/ketchup/static/favicon/mstile-150x150.png similarity index 100% rename from static/favicon/mstile-150x150.png rename to cmd/ketchup/static/favicon/mstile-150x150.png diff --git a/static/favicon/mstile-310x150.png b/cmd/ketchup/static/favicon/mstile-310x150.png similarity index 100% rename from static/favicon/mstile-310x150.png rename to cmd/ketchup/static/favicon/mstile-310x150.png diff --git a/static/favicon/mstile-310x310.png b/cmd/ketchup/static/favicon/mstile-310x310.png similarity index 100% rename from static/favicon/mstile-310x310.png rename to cmd/ketchup/static/favicon/mstile-310x310.png diff --git a/static/favicon/mstile-70x70.png b/cmd/ketchup/static/favicon/mstile-70x70.png similarity index 100% rename from static/favicon/mstile-70x70.png rename to cmd/ketchup/static/favicon/mstile-70x70.png diff --git a/static/favicon/safari-pinned-tab.svg b/cmd/ketchup/static/favicon/safari-pinned-tab.svg similarity index 100% rename from static/favicon/safari-pinned-tab.svg rename to cmd/ketchup/static/favicon/safari-pinned-tab.svg diff --git a/static/favicon/site.webmanifest b/cmd/ketchup/static/favicon/site.webmanifest similarity index 100% rename from static/favicon/site.webmanifest rename to cmd/ketchup/static/favicon/site.webmanifest diff --git a/static/robots.txt b/cmd/ketchup/static/robots.txt similarity index 100% rename from static/robots.txt rename to cmd/ketchup/static/robots.txt diff --git a/static/sitemap.xml b/cmd/ketchup/static/sitemap.xml similarity index 100% rename from static/sitemap.xml rename to cmd/ketchup/static/sitemap.xml diff --git a/templates/form_buttons.html b/cmd/ketchup/templates/form_buttons.html similarity index 100% rename from templates/form_buttons.html rename to cmd/ketchup/templates/form_buttons.html diff --git a/templates/index.html b/cmd/ketchup/templates/index.html similarity index 100% rename from templates/index.html rename to cmd/ketchup/templates/index.html diff --git a/templates/ketchup.html b/cmd/ketchup/templates/ketchup.html similarity index 97% rename from templates/ketchup.html rename to cmd/ketchup/templates/ketchup.html index 234fe9a2..959449a3 100644 --- a/templates/ketchup.html +++ b/cmd/ketchup/templates/ketchup.html @@ -217,12 +217,12 @@

{{ .Repository.Name }}

- {{ .Version }} + {{ .Version }} {{ if ne .Version (index .Repository.Versions .Pattern) }} -  -> {{ index .Repository.Versions .Pattern }} +  -> {{ index .Repository.Versions .Pattern }} {{ end }}

@@ -233,7 +233,7 @@

{{ .Repository.Name }}

{{ if ne .Version (index .Repository.Versions .Pattern) }} - + Compare icon diff --git a/templates/public.html b/cmd/ketchup/templates/public.html similarity index 100% rename from templates/public.html rename to cmd/ketchup/templates/public.html diff --git a/templates/suggest.html b/cmd/ketchup/templates/suggest.html similarity index 100% rename from templates/suggest.html rename to cmd/ketchup/templates/suggest.html diff --git a/templates/svg.html b/cmd/ketchup/templates/svg.html similarity index 100% rename from templates/svg.html rename to cmd/ketchup/templates/svg.html diff --git a/go.mod b/go.mod index f6d4c3b6..7b460ce5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e3ea112a..542e7ad8 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/model/repository.go b/pkg/model/repository.go index 5937689d..22225fbe 100644 --- a/pkg/model/repository.go +++ b/pkg/model/repository.go @@ -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 { @@ -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 diff --git a/pkg/model/repository_test.go b/pkg/model/repository_test.go index be40c678..f472f6d3 100644 --- a/pkg/model/repository_test.go +++ b/pkg/model/repository_test.go @@ -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) } }) @@ -68,6 +82,7 @@ func TestURL(t *testing.T) { func TestCompareURL(t *testing.T) { type args struct { version string + pattern string } var cases = []struct { @@ -87,6 +102,7 @@ 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", }, @@ -94,7 +110,7 @@ func TestCompareURL(t *testing.T) { 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) } })