Skip to content

Commit

Permalink
Merge pull request #2429 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: commands predefined variable parsing
  • Loading branch information
FabianKramm authored Nov 16, 2022
2 parents 659fc12 + 0e145f5 commit 12530f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
25 changes: 7 additions & 18 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,17 @@ echo 'Anyone using this project can invoke it via "devspace run migrate-db"'`,
// Add pipeline: dev
config.Pipelines["dev"] = &latest.Pipeline{
Run: `run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
create_deployments --all # 2. Deploy Helm charts and manifests specfied as "deployments"
start_dev ` + imageName + ` # 3. Start dev mode "` + imageName + `" (see "dev" section)`,
ensure_pull_secrets --all # 2. Ensure pull secrets
create_deployments --all # 3. Deploy Helm charts and manifests specfied as "deployments"
start_dev ` + imageName + ` # 4. Start dev mode "` + imageName + `" (see "dev" section)`,
}

// Add pipeline: dev
config.Pipelines["deploy"] = &latest.Pipeline{
Run: `run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
build_images --all -t $(git describe --always) # 2. Build, tag (git commit hash) and push all images (see "images")
create_deployments --all # 3. Deploy Helm charts and manifests specfied as "deployments"`,
ensure_pull_secrets --all # 2. Ensure pull secrets
build_images --all -t $(git describe --always) # 3. Build, tag (git commit hash) and push all images (see "images")
create_deployments --all # 4. Deploy Helm charts and manifests specfied as "deployments"`,
}

// Save config
Expand Down Expand Up @@ -661,19 +663,6 @@ func annotateConfig(configPath string) error {
# tag: v1.0.0
# ui:
# path: ./ui # Path-based dependencies (for monorepos)
`)...)

annotatedConfig = append(annotatedConfig, []byte(`
# Customize local registry settings
# localRegistry:
# enabled: true # Always use local registry, remove to only use the local registry when required
# name: registry
# namespace: ${devspace.namespace} # Uses the current kube context's namespace (can be removed)
# image: registry:2.8.1
# port: 5000
# persistence:
# enabled: false
# size: 5Gi
`)...)

err = os.WriteFile(configPath, annotatedConfig, os.ModePerm)
Expand Down Expand Up @@ -784,7 +773,7 @@ func (cmd *InitCmd) addDevConfig(config *latest.Config, imageName, image string,
Command: "helm",
},
{
Command: "git",
GitCredentials: true,
},
}...)

Expand Down
20 changes: 11 additions & 9 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {

// Set config root
configOptions := cmd.ToConfigOptions()
configOptions.Vars = append([]string{
"devspace.namespace=" + cmd.Namespace,
"DEVSPACE_NAMESPACE=" + cmd.Namespace,
"devspace.context=" + cmd.KubeContext,
"DEVSPACE_CONTEXT=" + cmd.KubeContext,
}, configOptions.Vars...)
configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
if err != nil {
return err
Expand All @@ -127,7 +121,7 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
}

// load the config
ctx, err := LoadCommandsConfig(configLoader, configOptions, f.GetLog())
ctx, err := cmd.LoadCommandsConfig(f, configLoader, configOptions, f.GetLog())
if err != nil {
return err
}
Expand Down Expand Up @@ -241,21 +235,29 @@ func ParseArgs(cobraCmd *cobra.Command, globalFlags *flags.GlobalFlags, log log.
}

// LoadCommandsConfig loads the commands config
func LoadCommandsConfig(configLoader loader.ConfigLoader, configOptions *loader.ConfigOptions, log log.Logger) (devspacecontext.Context, error) {
func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.ConfigLoader, configOptions *loader.ConfigOptions, log log.Logger) (devspacecontext.Context, error) {
// load generated
localCache, err := configLoader.LoadLocalCache()
if err != nil {
return nil, err
}

// try to load client
client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
if err != nil {
log.Debugf("Unable to create new kubectl client: %v", err)
client = nil
}

// Parse commands
commandsInterface, err := configLoader.LoadWithParser(context.Background(), localCache, nil, loader.NewCommandsParser(), configOptions, log)
commandsInterface, err := configLoader.LoadWithParser(context.Background(), localCache, client, loader.NewCommandsParser(), configOptions, log)
if err != nil {
return nil, err
}

// create context
return devspacecontext.NewContext(context.Background(), commandsInterface.Variables(), log).
WithKubeClient(client).
WithConfig(commandsInterface), nil
}

Expand Down

0 comments on commit 12530f9

Please sign in to comment.