Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2a52e2f
refactor: default off .env file
FabianKramm Mar 23, 2022
308c95b
refactor: update profile handling
FabianKramm Mar 23, 2022
2f5cf32
refactor: update profile handling
FabianKramm Mar 23, 2022
520047c
fix: fixed an issue where dev conversion was failing
FabianKramm Mar 23, 2022
0a5d91d
refactor: add schema comments
FabianKramm Mar 23, 2022
2381a76
Merge branch 'master' of https://github.com/loft-sh/devspace
FabianKramm Mar 23, 2022
7e140cd
refactor: add more test cases for profile loading
FabianKramm Mar 23, 2022
77c7967
Merge pull request #1960 from FabianKramm/master
FabianKramm Mar 23, 2022
c974f44
feat: enable multiple pull secrets to be used by a service account
lizardruss Mar 23, 2022
2b136a6
Merge pull request #1963 from lizardruss/merge-pull-secrets
FabianKramm Mar 24, 2022
e1128fc
docs: start dev docs
FabianKramm Mar 24, 2022
b60adbc
Merge branch 'master' of https://github.com/loft-sh/devspace into v6-…
FabianKramm Mar 24, 2022
83a90f7
refactor: rename devCommand to runPipelineCommand
FabianKramm Mar 24, 2022
237a367
fix: use fallback language instead of fatal
LukasGentele Mar 24, 2022
b363381
feat: implement commands.*.after
FabianKramm Mar 24, 2022
c7144a1
feat: implement commands.*.after
FabianKramm Mar 24, 2022
0f2ae91
init: improve output
LukasGentele Mar 24, 2022
0be6247
tests: fix e2e test
FabianKramm Mar 24, 2022
b97a0e4
Merge pull request #1965 from FabianKramm/master
FabianKramm Mar 24, 2022
d6bb3e1
refactor: improve context handling
FabianKramm Mar 24, 2022
6c095e2
refactor: improve context handling
FabianKramm Mar 24, 2022
d2c7cf5
refactor: improve logs & context handling
FabianKramm Mar 24, 2022
de31cc7
fix: improve logging
FabianKramm Mar 24, 2022
072fe79
fix: timeout for open
FabianKramm Mar 24, 2022
035a289
fix: restart devpod
FabianKramm Mar 24, 2022
b85b2d9
Merge pull request #1966 from FabianKramm/master
FabianKramm Mar 24, 2022
87df387
refactor: improve logging
FabianKramm Mar 25, 2022
cf1cb71
Merge pull request #1969 from FabianKramm/master
FabianKramm Mar 25, 2022
2bb5263
docs: add more dev options
FabianKramm Mar 25, 2022
77f02e0
test: add e2e test for ssh
lizardruss Mar 25, 2022
d45c0c1
test: add e2e test for proxy commands
lizardruss Mar 25, 2022
67f63ff
Merge pull request #1968 from lizardruss/e2e-ssh-proxy-commands
FabianKramm Mar 25, 2022
40b2e23
fix: small fixes & examples update
FabianKramm Mar 25, 2022
f8c5931
Merge pull request #1970 from FabianKramm/master
FabianKramm Mar 25, 2022
1d7004f
Merge branch 'master' of https://github.com/loft-sh/devspace into v6-…
FabianKramm Mar 28, 2022
7f24f54
docs: update dev section
FabianKramm Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/cleanup/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Deletes all locally created docker images from docker
// RunCleanupImages executes the cleanup images command logic
func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
// Set config root
ctx := context.Background()
log := f.GetLog()
configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
if err != nil {
Expand All @@ -65,13 +66,13 @@ func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Comman
}

// Create docker client
client, err := docker.NewClientWithMinikube(kubeContext, true, log)
client, err := docker.NewClientWithMinikube(ctx, kubeContext, true, log)
if err != nil {
return err
}

// Load config
configInterface, err := configLoader.Load(context.Background(), nil, cmd.ToConfigOptions(), log)
configInterface, err := configLoader.Load(ctx, nil, cmd.ToConfigOptions(), log)
if err != nil {
return err
}
Expand All @@ -82,7 +83,7 @@ func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Comman
return nil
}

_, err = client.Ping(context.Background())
_, err = client.Ping(ctx)
if err != nil {
return errors.Errorf("Docker seems to be not running: %v", err)
}
Expand All @@ -91,7 +92,7 @@ func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Comman
for _, imageConfig := range config.Images {
log.Info("Deleting local image " + imageConfig.Image + "...")

response, err := client.DeleteImageByName(imageConfig.Image, log)
response, err := client.DeleteImageByName(ctx, imageConfig.Image, log)
if err != nil {
return err
}
Expand All @@ -109,7 +110,7 @@ func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Comman

// Cleanup dangling images aswell
for {
response, err := client.DeleteImageByFilter(filters.NewArgs(filters.Arg("dangling", "true")), log)
response, err := client.DeleteImageByFilter(ctx, filters.NewArgs(filters.Arg("dangling", "true")), log)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type EnterCmd struct {
Pick bool
Wait bool
Reconnect bool
Screen bool
ScreenSession string

WorkingDirectory string

Expand Down Expand Up @@ -79,6 +81,8 @@ devspace enter bash --image-selector "${runtime.images.app.image}:${runtime.imag
enterCmd.Flags().BoolVar(&cmd.Pick, "pick", true, "Select a pod / container if multiple are found")
enterCmd.Flags().BoolVar(&cmd.Wait, "wait", false, "Wait for the pod(s) to start if they are not running")
enterCmd.Flags().BoolVar(&cmd.Reconnect, "reconnect", false, "Will reconnect the terminal if an unexpected return code is encountered")
enterCmd.Flags().BoolVar(&cmd.Screen, "screen", false, "Use a screen session to connect")
enterCmd.Flags().StringVar(&cmd.ScreenSession, "screen-session", "enter", "The screen session to create or connect to")

return enterCmd
}
Expand Down Expand Up @@ -158,7 +162,7 @@ func (cmd *EnterCmd) Run(f factory.Factory, args []string) error {

// Start terminal
stdout, stderr, stdin := defaultStdStreams(cmd.Stdout, cmd.Stderr, cmd.Stdin)
exitCode, err := terminal.StartTerminalFromCMD(ctx, targetselector.NewTargetSelector(selectorOptions), command, cmd.Wait, cmd.Reconnect, stdout, stderr, stdin)
exitCode, err := terminal.StartTerminalFromCMD(ctx, targetselector.NewTargetSelector(selectorOptions), command, cmd.Wait, cmd.Reconnect, cmd.Screen, cmd.ScreenSession, stdout, stderr, stdin)
if err != nil {
return err
} else if exitCode != 0 {
Expand Down
48 changes: 25 additions & 23 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,6 @@ func (cmd *InitCmd) Run(f factory.Factory) error {
}

if selectedDeploymentOption == DeployOptionHelm {
hasOwnHelmChart := "Yes"
helmChartAnswer, err := cmd.log.Question(&survey.QuestionOptions{
Question: "Do you already have a Helm chart for this project?",
Options: []string{
"No",
hasOwnHelmChart,
},
})
if err != nil {
return err
}

if isQuickstart {
quickstartYes := "Yes"
quickstartAnswer, err := cmd.log.Question(&survey.QuestionOptions{
Expand All @@ -317,19 +305,33 @@ func (cmd *InitCmd) Run(f factory.Factory) error {
}
}

if helmChartAnswer == hasOwnHelmChart && !mustAddComponentChart {
err = configureManager.AddHelmDeployment(imageName)
if !mustAddComponentChart {
hasOwnHelmChart := "Yes"
helmChartAnswer, err := cmd.log.Question(&survey.QuestionOptions{
Question: "Do you already have a Helm chart for this project?",
Options: []string{
"No",
hasOwnHelmChart,
},
})
if err != nil {
if err.Error() != "" {
cmd.log.WriteString(logrus.InfoLevel, "\n")
cmd.log.Errorf("Error: %s", err.Error())
}
return err
}

if helmChartAnswer == hasOwnHelmChart {
err = configureManager.AddHelmDeployment(imageName)
if err != nil {
if err.Error() != "" {
cmd.log.WriteString(logrus.InfoLevel, "\n")
cmd.log.Errorf("Error: %s", err.Error())
}

// Retry questions on error
continue
// Retry questions on error
continue
}
} else {
mustAddComponentChart = true
}
} else {
mustAddComponentChart = true
}
} else if selectedDeploymentOption == DeployOptionKubectl || selectedDeploymentOption == DeployOptionKustomize {
err = configureManager.AddKubectlDeployment(imageName, selectedDeploymentOption == DeployOptionKustomize)
Expand Down Expand Up @@ -373,7 +375,7 @@ func (cmd *InitCmd) Run(f factory.Factory) error {
}
}

err = configureManager.AddImage(imageName, image, projectNamespace+"/"+projectName, cmd.Dockerfile, languageHandler)
err = configureManager.AddImage(imageName, image, projectNamespace+"/"+projectName, cmd.Dockerfile)
if err != nil {
if err.Error() != "" {
cmd.log.Errorf("Error: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion cmd/overwrite_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ func NewOverwriteCmd(f factory.Factory, globalFlags *flags.GlobalFlags, command

func (cmd *OverwriteCmd) Run(f factory.Factory, args []string) error {
devCtx := devspacecontext.NewContext(context.Background(), f.GetLog())
return ExecuteCommand(devCtx.Context, cmd.Command, cmd.Variables, args, devCtx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin)
return executeCommandWithAfter(devCtx.Context, cmd.Command, args, cmd.Variables, devCtx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin, devCtx.Log)
}
9 changes: 6 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ func NewRootCmd(f factory.Factory) *cobra.Command {
}

// parse the .env file
err := godotenv.Load()
if err != nil && !os.IsNotExist(err) {
log.Warnf("Error loading .env: %v", err)
envFile := env.GlobalGetEnv("DEVSPACE_ENV_FILE")
if envFile != "" {
err := godotenv.Load(envFile)
if err != nil && !os.IsNotExist(err) {
log.Warnf("Error loading .env: %v", err)
}
}

// apply extra flags
Expand Down
75 changes: 66 additions & 9 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/loft-sh/devspace/pkg/devspace/plugin"
"github.com/loft-sh/devspace/pkg/util/command"
"github.com/loft-sh/devspace/pkg/util/exit"
"github.com/loft-sh/devspace/pkg/util/interrupt"
"github.com/loft-sh/devspace/pkg/util/log"
"io"
"mvdan.cc/sh/v3/interp"
Expand Down Expand Up @@ -158,11 +159,56 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
}

ctx = ctx.AsDependency(dep)
return ExecuteConfigCommand(ctx.Context, ctx.Config, args[0], args[1:], ctx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin)
commandConfig, err := findCommand(ctx.Config, args[0])
if err != nil {
return err
}

return executeCommandWithAfter(ctx.Context, commandConfig, args[1:], ctx.Config.Variables(), ctx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin, ctx.Log)
}

commandConfig, err := findCommand(ctx.Config, args[0])
if err != nil {
return err
}

return executeCommandWithAfter(ctx.Context, commandConfig, args[1:], ctx.Config.Variables(), ctx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin, ctx.Log)
}

func findCommand(config config.Config, name string) (*latest.CommandConfig, error) {
// Find command
if config.Config().Commands == nil || config.Config().Commands[name] == nil {
return nil, errors.Errorf("couldn't find command '%s' in devspace config", name)
}

return config.Config().Commands[name], nil
}

func executeCommandWithAfter(ctx context.Context, command *latest.CommandConfig, args []string, variables map[string]interface{}, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader, log log.Logger) error {
originalErr := interrupt.Global.Run(func() error {
return ExecuteCommand(ctx, command, variables, args, dir, stdout, stderr, stdin)
}, func() {
if command.After != "" {
vars := variables
vars["COMMAND_INTERRUPT"] = "true"
err := executeShellCommand(ctx, command.After, vars, args, dir, stdout, stderr, stdin)
if err != nil {
log.Errorf("error executing after command: %v", err)
}
}
})
if command.After != "" {
vars := variables
if originalErr != nil {
vars["COMMAND_ERROR"] = originalErr.Error()
}
err := executeShellCommand(ctx, command.After, vars, args, dir, stdout, stderr, stdin)
if err != nil {
return errors.Wrap(err, "error executing after command")
}
}

// Execute command
return ExecuteConfigCommand(ctx.Context, ctx.Config, args[0], args[1:], ctx.WorkingDir, cmd.Stdout, cmd.Stderr, os.Stdin)
return originalErr
}

func ParseArgs(cobraCmd *cobra.Command, globalFlags *flags.GlobalFlags, log log.Logger) ([]string, error) {
Expand Down Expand Up @@ -221,14 +267,25 @@ func LoadCommandsConfig(configLoader loader.ConfigLoader, configOptions *loader.
WithConfig(commandsInterface), nil
}

// ExecuteConfigCommand executes a command from the config
func ExecuteConfigCommand(ctx context.Context, config config.Config, name string, args []string, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader) error {
if config.Config().Commands == nil || config.Config().Commands[name] == nil {
return errors.Errorf("couldn't find command '%s' in devspace config", name)
func executeShellCommand(ctx context.Context, shellCommand string, variables map[string]interface{}, args []string, dir string, stdout io.Writer, stderr io.Writer, stdin io.Reader) error {
extraEnv := map[string]string{}
for k, v := range variables {
extraEnv[k] = fmt.Sprintf("%v", v)
}

// execute the command in a shell
err := engine.ExecuteSimpleShellCommand(ctx, dir, stdout, stderr, stdin, extraEnv, shellCommand, args...)
if err != nil {
if status, ok := interp.IsExitStatus(err); ok {
return &exit.ReturnCodeError{
ExitCode: int(status),
}
}

return errors.Wrap(err, "execute command")
}

cmd := config.Config().Commands[name]
return ExecuteCommand(ctx, cmd, config.Variables(), args, dir, stdout, stderr, stdin)
return nil
}

// ExecuteCommand executes a command from the config
Expand Down
2 changes: 1 addition & 1 deletion cmd/run_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (cmd *RunPipelineCmd) Run(f factory.Factory, args []string) error {
return err
}

return runWithHooks(ctx, "devCommand", func() error {
return runWithHooks(ctx, "runPipelineCommand", func() error {
// Build and deploy images
err = cmd.runCommand(ctx, f, configOptions, args[0])
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions docs/pages/configuration/development/arch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: DevSpace Helper Architecture
sidebar_label: arch
---

`arch` specifies which DevSpace helper architecture that should be used for the container. The DevSpace helper is a small binary that is injected by DevSpace to accomplish certain tasks, such as ssh, syncing or reverse port-forwarding. Currently valid values are either no value, `amd64` or `arm64`. Depending on this value, DevSpace will inject the DevSpace helper binary with the corresponding architecture suffix.

:::note
If no arch is specified, DevSpace will try to find out what arch the node has where the container is running and inject the correct binary. If DevSpace has no permissions to retrieve node information, it will inject the `amd64` binary.
:::
45 changes: 45 additions & 0 deletions docs/pages/configuration/development/attach.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Attaching to a container
sidebar_label: attach
---

Attach can be used to [attach](https://jamesdefabia.github.io/docs/user-guide/kubectl/kubectl_attach/) to a process that is already running inside an existing container. Under the hood this is the same as calling `kubectl attach`.

For example
```yaml
deployments:
my-deployment:
helm:
values:
containers:
- image: ubuntu

dev:
my-dev:
imageSelector: ubuntu
attach: {}
```

## How does it work?

Under the hood DevSpace will replace the running pod and apply the following changes, before actually attaching to it:
- Remove `readinessProbes`, `startupProbes` & `livenessProbes`
- Add `stdin: true` and `tty: true` to the container spec

:::info
If you don't want DevSpace to replace the pod with a modified version, use `disableReplace: true`
:::

## Configuration

### `enabled`

If true or attach is an empty object, DevSpace will attach to the container.

### `disableReplace`

If true, DevSpace will not replace the pod.

### `disableTTY`

If true, DevSpace will not set `tty: true` during replacing the pod.
58 changes: 0 additions & 58 deletions docs/pages/configuration/development/auto-reloading.mdx

This file was deleted.

Loading