mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
fix(cli): respect --config option in setup command
This commit is contained in:
parent
c7b352dba3
commit
4afe568db6
@ -26,12 +26,12 @@ func doRunnerSetup() int {
|
|||||||
|
|
||||||
setup.InteractiveRunnerSetup(config)
|
setup.InteractiveRunnerSetup(config)
|
||||||
|
|
||||||
configPath := setup.SaveConfig(config)
|
resultConfigPath := setup.SaveConfig(config, "config-runner.json", configPath)
|
||||||
|
|
||||||
util.ConfigInit(configPath, false)
|
util.ConfigInit(resultConfigPath, false)
|
||||||
|
|
||||||
fmt.Printf(" Re-launch this program pointing to the configuration file\n\n./semaphore server --config %v\n\n", configPath)
|
fmt.Printf(" Re-launch this program pointing to the configuration file\n\n./semaphore runner --config %v\n\n", resultConfigPath)
|
||||||
fmt.Printf(" To run as daemon:\n\nnohup ./semaphore server --config %v &\n\n", configPath)
|
fmt.Printf(" To run as daemon:\n\nnohup ./semaphore runner --config %v &\n\n", resultConfigPath)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,9 @@ func doSetup() int {
|
|||||||
config.GenerateSecrets()
|
config.GenerateSecrets()
|
||||||
setup.InteractiveSetup(config)
|
setup.InteractiveSetup(config)
|
||||||
|
|
||||||
configPath := setup.SaveConfig(config)
|
resultConfigPath := setup.SaveConfig(config, "config.json", configPath)
|
||||||
|
|
||||||
util.ConfigInit(configPath, false)
|
util.ConfigInit(resultConfigPath, false)
|
||||||
|
|
||||||
fmt.Println(" Pinging db..")
|
fmt.Println(" Pinging db..")
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ func doSetup() int {
|
|||||||
fmt.Printf("\n You are all setup %v!\n", user.Name)
|
fmt.Printf("\n You are all setup %v!\n", user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(" Re-launch this program pointing to the configuration file\n\n./semaphore server --config %v\n\n", configPath)
|
fmt.Printf(" Re-launch this program pointing to the configuration file\n\n./semaphore server --config %v\n\n", resultConfigPath)
|
||||||
fmt.Printf(" To run as daemon:\n\nnohup ./semaphore server --config %v &\n\n", configPath)
|
fmt.Printf(" To run as daemon:\n\nnohup ./semaphore server --config %v &\n\n", resultConfigPath)
|
||||||
fmt.Printf(" You can login with %v or %v.\n", user.Email, user.Username)
|
fmt.Printf(" You can login with %v or %v.\n", user.Email, user.Username)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -25,6 +25,8 @@ func InteractiveRunnerSetup(conf *util.ConfigType) {
|
|||||||
|
|
||||||
askValue("Semaphore server URL", "", &conf.WebHost)
|
askValue("Semaphore server URL", "", &conf.WebHost)
|
||||||
|
|
||||||
|
conf.Runner = &util.RunnerConfig{}
|
||||||
|
|
||||||
askValue("Path to the file where runner token will be stored", "", &conf.Runner.TokenFile)
|
askValue("Path to the file where runner token will be stored", "", &conf.Runner.TokenFile)
|
||||||
|
|
||||||
haveToken := false
|
haveToken := false
|
||||||
@ -153,20 +155,31 @@ type IConfig interface {
|
|||||||
ToJSON() ([]byte, error)
|
ToJSON() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveConfig(config IConfig) (configPath string) {
|
func SaveConfig(config IConfig, defaultFilename string, requiredConfigPath string) (configPath string) {
|
||||||
configDirectory, err := os.Getwd()
|
|
||||||
if err != nil {
|
if requiredConfigPath == "" {
|
||||||
configDirectory, err = os.UserConfigDir()
|
configDirectory, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Final fallback
|
configDirectory, err = os.UserConfigDir()
|
||||||
configDirectory = "/etc/semaphore"
|
if err != nil {
|
||||||
|
// Final fallback
|
||||||
|
configDirectory = "/etc/semaphore"
|
||||||
|
}
|
||||||
|
configDirectory = filepath.Join(configDirectory, "semaphore")
|
||||||
}
|
}
|
||||||
configDirectory = filepath.Join(configDirectory, "semaphore")
|
|
||||||
|
configPath = filepath.Join(configDirectory, defaultFilename)
|
||||||
|
askValue("Config output file", configPath, &configPath)
|
||||||
|
} else {
|
||||||
|
configPath = requiredConfigPath
|
||||||
}
|
}
|
||||||
askValue("Config output directory", configDirectory, &configDirectory)
|
|
||||||
|
configDirectory := filepath.Dir(configPath)
|
||||||
|
|
||||||
fmt.Printf("Running: mkdir -p %v..\n", configDirectory)
|
fmt.Printf("Running: mkdir -p %v..\n", configDirectory)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
if _, err = os.Stat(configDirectory); err != nil {
|
if _, err = os.Stat(configDirectory); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(configDirectory, 0755)
|
err = os.MkdirAll(configDirectory, 0755)
|
||||||
@ -183,7 +196,6 @@ func SaveConfig(config IConfig) (configPath string) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configPath = filepath.Join(configDirectory, "config.json")
|
|
||||||
if err = os.WriteFile(configPath, bytes, 0644); err != nil {
|
if err = os.WriteFile(configPath, bytes, 0644); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ func ConfigInit(configPath string, noConfigFile bool) {
|
|||||||
if Config.Runner != nil && Config.Runner.TokenFile != "" {
|
if Config.Runner != nil && Config.Runner.TokenFile != "" {
|
||||||
runnerTokenBytes, err := os.ReadFile(Config.Runner.TokenFile)
|
runnerTokenBytes, err := os.ReadFile(Config.Runner.TokenFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
Config.Runner.Token = string(runnerTokenBytes)
|
Config.Runner.Token = strings.TrimSpace(string(runnerTokenBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user