mirror of
https://github.com/foomo/squadron.git
synced 2026-10-06 23:56:54 +00:00
Add init command and apply small fixes
This commit is contained in:
@@ -25,7 +25,7 @@ func Build(service, tag, dir string, flagVerbose bool) (string, error) {
|
||||
}
|
||||
output, err := svc.RunBuild(log, dir, tag, flagVerbose)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not build service: %v output:\n%v", svc.Name, output)
|
||||
return "", outputErrorf(output, err, "could not build service: %v", svc.Name)
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/foomo/configurd"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init [NAME]",
|
||||
Short: "Initialize an example application with configurd",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
_, err := Init(args[0], flagDir, flagVerbose)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func Init(name, dir string, flagVerbose bool) (string, error) {
|
||||
output, err := configurd.Init(log, path.Join(dir, name), flagVerbose)
|
||||
if err != nil {
|
||||
return "", outputErrorf(output, err, "could not initialize an example configuraiton")
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
@@ -48,12 +48,7 @@ func install(group, namespace, tag, workDir, outputDir string, build, verbose bo
|
||||
}
|
||||
output, err := cnf.Install(log, sis, workDir, outputDir, tag, verbose)
|
||||
if err != nil {
|
||||
// return "", fmt.Errorf("could not install group: %v output:\n%v \nerror: \n%v", group, output, err)
|
||||
return "", errorf(output, err, "could not install group: %v", group)
|
||||
return "", outputErrorf(output, err, "could not install group: %v", group)
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func errorf(output string, err error, format string, args ...interface{}) error {
|
||||
return fmt.Errorf("%v, error: %v", fmt.Sprintf(format, args...), err)
|
||||
}
|
||||
|
||||
+11
-1
@@ -1,6 +1,7 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@@ -21,6 +22,11 @@ var (
|
||||
}
|
||||
if flagDir != "" {
|
||||
flagDir = path.Join(wdir, flagDir)
|
||||
} else {
|
||||
flagDir = wdir
|
||||
}
|
||||
if cmd.Name() == "help" || cmd.Name() == "init" {
|
||||
return
|
||||
}
|
||||
cnf, err = configurd.New(log, flagDir)
|
||||
if err != nil {
|
||||
@@ -39,9 +45,13 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&flagTag, "tag", "t", "latest", "Specifies the image tag")
|
||||
rootCmd.PersistentFlags().StringVarP(&flagDir, "dir", "d", "", "Specifies working directory")
|
||||
rootCmd.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "Specifies should command output be displayed")
|
||||
rootCmd.AddCommand(buildCmd, installCmd, uninstallCmd)
|
||||
rootCmd.AddCommand(buildCmd, installCmd, uninstallCmd, initCmd)
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func outputErrorf(output string, err error, format string, args ...interface{}) error {
|
||||
return fmt.Errorf("%v, error: %v", fmt.Sprintf(format, args...), err)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func uninstall(group, namespace string, flagVerbose bool) (string, error) {
|
||||
}
|
||||
output, err := cnf.Uninstall(log, sis, flagVerbose)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not uninstall service group: %v output:\n%v", group, output)
|
||||
return "", outputErrorf(output, err, "could not uninstall service group: %v", group)
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
+23
-3
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -19,6 +20,7 @@ const (
|
||||
defaultChartDir = "configurd/charts"
|
||||
defaultOutputDir = "configurd/.workdir"
|
||||
defaultOverridesFile = "overrides.yaml"
|
||||
defaultInitUrl = "https://github.com/foomo/configurd.git/branches/feature/helm-charts-deployments/example"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -49,8 +51,8 @@ type Logger interface {
|
||||
Fatalf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
func relativePath(absoltePath, basePath string) string {
|
||||
return strings.Replace(absoltePath, basePath+"/", "", -1)
|
||||
func relativePath(path, basePath string) string {
|
||||
return strings.Replace(path, basePath+"/", "", -1)
|
||||
}
|
||||
|
||||
func New(log Logger, basePath string) (Configurd, error) {
|
||||
@@ -185,7 +187,7 @@ func (c Configurd) Service(name string) (Service, error) {
|
||||
func (c Configurd) GetServiceItems(namespace, group string) []ServiceItem {
|
||||
var sis []ServiceItem
|
||||
for _, si := range c.serviceItems() {
|
||||
if si.namespace == namespace && (si.group == group || group == "") {
|
||||
if si.namespace == namespace && si.group == group {
|
||||
sis = append(sis, si)
|
||||
}
|
||||
}
|
||||
@@ -220,3 +222,21 @@ func logOutput(log Logger, verbose bool, format string, args ...interface{}) {
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func Init(log Logger, dir string, flagVerbose bool) (string, error) {
|
||||
// log.Printf("Creating dir: %q", dir)
|
||||
|
||||
// if err := os.MkdirAll(dir, 0744); err != nil {
|
||||
// return "", fmt.Errorf("could not create a directory: %w", err)
|
||||
// }
|
||||
|
||||
log.Printf("Downloading example configuration into dir: %q", dir)
|
||||
cmd := exec.Command("svn", "export", defaultInitUrl, dir)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
output := strings.Replace(string(out), "\n", "\n\t", -1)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not download a configurd example, output: \n%v", output)
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
@@ -20,11 +20,12 @@ service:
|
||||
env: []
|
||||
|
||||
ingress:
|
||||
enabled: true
|
||||
enabled: false
|
||||
annotations: {}
|
||||
# kubernetes.io/ingress.class: nginx
|
||||
# kubernetes.io/tls-acme: "true"
|
||||
paths: []
|
||||
paths:
|
||||
- "/"
|
||||
hosts:
|
||||
- chart-example.local
|
||||
tls: []
|
||||
|
||||
@@ -4,8 +4,26 @@ group:
|
||||
overrides:
|
||||
args:
|
||||
- "--greeting=hehe"
|
||||
service:
|
||||
targetPort: 80
|
||||
port: 80
|
||||
ingress:
|
||||
enabled: true
|
||||
paths:
|
||||
- /services/hello
|
||||
hosts:
|
||||
- localhost
|
||||
hi-service:
|
||||
overrides:
|
||||
args:
|
||||
- "--greeting=hai"
|
||||
service:
|
||||
targetPort: 80
|
||||
port: 80
|
||||
ingress:
|
||||
enabled: true
|
||||
paths:
|
||||
- /services/hi
|
||||
hosts:
|
||||
- localhost
|
||||
jobs:
|
||||
Reference in New Issue
Block a user