server: provide asset-path argument (#111)

This allows to install the assets into /usr/share/reg for packaging
This commit is contained in:
Manuel Rüger 2018-07-16 17:20:38 +02:00 committed by Jess Frazelle
parent bde58ebc52
commit dad52d251d
2 changed files with 15 additions and 10 deletions

View file

@ -224,6 +224,7 @@ Flags:
-u, --username username for the registry (default: <none>) -u, --username username for the registry (default: <none>)
--cert path to ssl cert (default: <none>) --cert path to ssl cert (default: <none>)
--clair url to clair instance (default: <none>) --clair url to clair instance (default: <none>)
--asset-path Path to assets and templates (default: <none>)
-d enable debug logging (default: false) -d enable debug logging (default: false)
-k, --insecure do not verify tls certificates (default: false) -k, --insecure do not verify tls certificates (default: false)
-f, --force-non-ssl force allow use of non-ssl (default: false) -f, --force-non-ssl force allow use of non-ssl (default: false)

View file

@ -36,6 +36,7 @@ func (cmd *serverCommand) Register(fs *flag.FlagSet) {
fs.StringVar(&cmd.cert, "cert", "", "path to ssl cert") fs.StringVar(&cmd.cert, "cert", "", "path to ssl cert")
fs.StringVar(&cmd.key, "key", "", "path to ssl key") fs.StringVar(&cmd.key, "key", "", "path to ssl key")
fs.StringVar(&cmd.port, "port", "8080", "port for server to run on") 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") fs.BoolVar(&cmd.once, "once", false, "generate an output once and then exit")
} }
@ -47,9 +48,10 @@ type serverCommand struct {
once bool once bool
cert string cert string
key string key string
port string port string
assetPath string
} }
func (cmd *serverCommand) Run(ctx context.Context, args []string) error { 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 { } else {
rc.cl = nil rc.cl = nil
} }
// Get the path to the asset directory.
// Get the path to the static directory. assetDir := cmd.assetPath
wd, err := os.Getwd() if len(cmd.assetPath) <= 0 {
if err != nil { assetDir, err = os.Getwd()
return err 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. // Make sure all the paths exist.
tmplPaths := []string{ tmplPaths := []string{
staticDir, staticDir,