start of generating assets

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-09-10 11:56:34 -04:00
parent 2e3c2122d7
commit 695602b303
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
5 changed files with 308 additions and 4 deletions

1
.gitignore vendored
View file

@ -46,7 +46,6 @@ reg
testreg
.certs
cross/
internal/
server/static/index.html
server/static/repo/

View file

@ -0,0 +1,27 @@
// +build ignore
package main
import (
"net/http"
"os"
"path/filepath"
"github.com/shurcooL/vfsgen"
"github.com/sirupsen/logrus"
)
func main() {
wd, err := os.Getwd()
if err != nil {
logrus.Fatal(err)
}
assets := http.Dir(filepath.Join(wd, "server/static"))
if err := vfsgen.Generate(assets, vfsgen.Options{
Filename: filepath.Join(wd, "internal/binutils", "static.go"),
PackageName: "binutils",
VariableName: "Assets",
}); err != nil {
logrus.Fatal(err)
}
}

277
internal/binutils/static.go Normal file

File diff suppressed because one or more lines are too long

View file

@ -30,6 +30,7 @@ var (
debug bool
)
//go:generate go run internal/binutils/generate.go
func main() {
// Create a new cli program.
p := cli.NewProgram()

View file

@ -12,6 +12,7 @@ import (
"time"
"github.com/genuinetools/reg/clair"
"github.com/genuinetools/reg/internal/binutils"
"github.com/gorilla/mux"
wordwrap "github.com/mitchellh/go-wordwrap"
"github.com/sirupsen/logrus"
@ -95,7 +96,6 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
templateDir := filepath.Join(assetDir, "templates")
// Make sure all the paths exist.
tmplPaths := []string{
staticDir,
filepath.Join(templateDir, "vulns.html"),
filepath.Join(templateDir, "repositories.html"),
filepath.Join(templateDir, "tags.html"),
@ -132,7 +132,7 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
},
}
rc.tmpl = template.Must(template.New("").Funcs(funcMap).ParseGlob(templateDir + "/*.html"))
rc.tmpl = template.Must(template.New("").Funcs(funcMap).Parse(templateDir + "/*.html"))
// Create the initial index.
logrus.Info("creating initial static index")
@ -176,7 +176,7 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
}
// Serve the static assets.
staticHandler := http.FileServer(http.Dir(staticDir))
staticHandler := http.FileServer(binutils.Assets)
mux.PathPrefix("/static/").Handler(http.StripPrefix("/static/", staticHandler))
mux.Handle("/", staticHandler)