From dad52d251dfbf236d9c955d80e643bc269937233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Mon, 16 Jul 2018 17:20:38 +0200 Subject: [PATCH] server: provide asset-path argument (#111) This allows to install the assets into /usr/share/reg for packaging --- README.md | 1 + server.go | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b9c3dfe1..e14b9524 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,7 @@ Flags: -u, --username username for the registry (default: ) --cert path to ssl cert (default: ) --clair url to clair instance (default: ) + --asset-path Path to assets and templates (default: ) -d enable debug logging (default: false) -k, --insecure do not verify tls certificates (default: false) -f, --force-non-ssl force allow use of non-ssl (default: false) diff --git a/server.go b/server.go index cccdcc54..1ad4fc5c 100644 --- a/server.go +++ b/server.go @@ -36,6 +36,7 @@ func (cmd *serverCommand) Register(fs *flag.FlagSet) { fs.StringVar(&cmd.cert, "cert", "", "path to ssl cert") fs.StringVar(&cmd.key, "key", "", "path to ssl key") fs.StringVar(&cmd.port, "port", "8080", "port for server to run on") + fs.StringVar(&cmd.assetPath, "asset-path", "", "Path to assets and templates") fs.BoolVar(&cmd.once, "once", false, "generate an output once and then exit") } @@ -47,9 +48,10 @@ type serverCommand struct { once bool - cert string - key string - port string + cert string + key string + port string + assetPath string } func (cmd *serverCommand) Run(ctx context.Context, args []string) error { @@ -77,15 +79,17 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error { } else { rc.cl = nil } - - // Get the path to the static directory. - wd, err := os.Getwd() - if err != nil { - return err + // Get the path to the asset directory. + assetDir := cmd.assetPath + if len(cmd.assetPath) <= 0 { + assetDir, err = os.Getwd() + if err != nil { + return err + } } - staticDir := filepath.Join(wd, "static") - templateDir := filepath.Join(staticDir, "../templates") + staticDir := filepath.Join(assetDir, "static") + templateDir := filepath.Join(assetDir, "templates") // Make sure all the paths exist. tmplPaths := []string{ staticDir,