Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes to kool cloud setup #484

Merged
merged 7 commits into from Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions commands/cloud_deploy.go
Expand Up @@ -6,6 +6,7 @@ import (
"kool-dev/kool/core/environment"
"kool-dev/kool/services/cloud"
"kool-dev/kool/services/cloud/api"
"kool-dev/kool/services/cloud/setup"
"kool-dev/kool/services/tgz"
"os"
"path/filepath"
Expand All @@ -17,8 +18,7 @@ import (
)

const (
koolDeployEnv = "kool.deploy.env"
koolDeployFile = "kool.cloud.yml"
koolDeployEnv = "kool.deploy.env"
)

// KoolCloudDeployFlags holds the flags for the kool cloud deploy command
Expand All @@ -37,9 +37,10 @@ type KoolCloudDeployFlags struct {
type KoolDeploy struct {
DefaultKoolService

flags *KoolCloudDeployFlags
env environment.EnvStorage
git builder.Command
setupParser setup.CloudSetupParser
flags *KoolCloudDeployFlags
env environment.EnvStorage
git builder.Command
}

// NewDeployCommand initializes new kool deploy Cobra command
Expand All @@ -65,10 +66,12 @@ func NewDeployCommand(deploy *KoolDeploy) (cmd *cobra.Command) {
// NewKoolDeploy creates a new pointer with default KoolDeploy service
// dependencies.
func NewKoolDeploy() *KoolDeploy {
env := environment.NewEnvStorage()
return &KoolDeploy{
*newDefaultKoolService(),
setup.NewDefaultCloudSetupParser(env.Get("PWD")),
&KoolCloudDeployFlags{},
environment.NewEnvStorage(),
env,
builder.NewCommand("git"),
}
}
Expand Down Expand Up @@ -275,13 +278,13 @@ func (d *KoolDeploy) handleDeployEnv(files []string) []string {
}

func (d *KoolDeploy) validate() (err error) {
if err = cloud.ValidateKoolDeployFile(d.env.Get("PWD"), koolDeployFile); err != nil {
if err = cloud.ValidateKoolDeployFile(d.env.Get("PWD"), setup.KoolDeployFile); err != nil {
return
}

// if no domain is set, we try to get it from the environment
if d.flags.DeployDomain == "" && d.env.Get("KOOL_DEPLOY_DOMAIN") == "" {
err = fmt.Errorf("Missing deploy domain. Please set it via --domain or KOOL_DEPLOY_DOMAIN environment variable.")
err = fmt.Errorf("missing deploy domain - please set it via --domain or KOOL_DEPLOY_DOMAIN environment variable")
return
} else if d.flags.DeployDomain != "" {
// shares the flag via environment variable
Expand All @@ -290,7 +293,7 @@ func (d *KoolDeploy) validate() (err error) {

// if no token is set, we try to get it from the environment
if d.flags.Token == "" && d.env.Get("KOOL_API_TOKEN") == "" {
err = fmt.Errorf("Missing Kool Cloud API token. Please set it via --token or KOOL_API_TOKEN environment variable.")
err = fmt.Errorf("missing Kool Cloud API token - please set it via --token or KOOL_API_TOKEN environment variable")
return
} else if d.flags.Token != "" {
d.env.Set("KOOL_API_TOKEN", d.flags.Token)
Expand Down
2 changes: 2 additions & 0 deletions commands/cloud_deploy_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"kool-dev/kool/core/builder"
"kool-dev/kool/core/environment"
"kool-dev/kool/services/cloud/setup"
"os"
"path/filepath"
"strings"
Expand All @@ -25,6 +26,7 @@ func TestNewKoolDeploy(t *testing.T) {
func fakeKoolDeploy() *KoolDeploy {
return &KoolDeploy{
*(newDefaultKoolService().Fake()),
setup.NewDefaultCloudSetupParser(""),
&KoolCloudDeployFlags{
DeployDomain: "foo",
Token: "bar",
Expand Down