diff --git a/.gitignore b/.gitignore index a2604afb..ce63d2d1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ .idea gebug +.gebug diff --git a/cmd/init.go b/cmd/init.go index 862e50a6..935560a0 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -26,6 +26,7 @@ var initCmd = &cobra.Command{ &input.PromptRuntimeImage{Config: currentConfig}, &input.PromptDebuggerOptions{Config: currentConfig}, &input.PromptExposePort{Config: currentConfig}, + &input.PromptEnvironment{Config: currentConfig}, &input.PromptNetworks{Config: currentConfig}, }, workDir) diff --git a/cmd/version.go b/cmd/version.go index dcbe7316..1fde0919 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "github.com/spf13/cobra" ) diff --git a/main.go b/main.go index dc0f63a1..ea228850 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main -import "github.com/moshebe/gebug/cmd" +import ( + "github.com/moshebe/gebug/cmd" +) func main() { err := cmd.Execute() diff --git a/pkg/config/config.go b/pkg/config/config.go index 94e962f9..7e97a1eb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -20,6 +20,7 @@ type Config struct { DebuggerPort int `yaml:"debugger_port"` ExposePorts []string `yaml:"expose_ports"` Networks []string `yaml:"networks"` + Environment []string `yaml:"environment"` } func updateBuildCommand(buildCommand string, debuggerEnabled bool) string { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index f381db44..2dc81d4d 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -138,6 +138,7 @@ expose_ports: - "8080" - 8081:8081 networks: [] +environment: [] ` c := Config{ Name: "my-app", diff --git a/pkg/config/render.go b/pkg/config/render.go index d9f490c7..b1673c25 100644 --- a/pkg/config/render.go +++ b/pkg/config/render.go @@ -49,6 +49,12 @@ services: - {{$value}} {{- end}} {{- end}} +{{- if .Environment}} + environment: + {{- range $key, $value := .Environment}} + - {{$value}} + {{- end}} +{{- end}} {{- if .Networks}} networks: diff --git a/pkg/config/testdata/generate_docker_compose_3.golden b/pkg/config/testdata/generate_docker_compose_3.golden new file mode 100644 index 00000000..29cbe2b0 --- /dev/null +++ b/pkg/config/testdata/generate_docker_compose_3.golden @@ -0,0 +1,21 @@ +version: '3' +services: + gebug-my-app: + build: + context: .. + dockerfile: .gebug/Dockerfile + volumes: + - ../:/src:ro + ports: + - 8080 + networks: + - frontend + - backend + environment: + - foo=bar + - hello +networks: + frontend: + external: true + backend: + external: true diff --git a/pkg/config/testdata/generate_docker_compose_3.in b/pkg/config/testdata/generate_docker_compose_3.in new file mode 100644 index 00000000..d682f3aa --- /dev/null +++ b/pkg/config/testdata/generate_docker_compose_3.in @@ -0,0 +1,15 @@ +name: my-app +output_binary: /app +build_command: go build -o {{.output_binary}} +runtime_image: golang:1.14 +run_command: '{{.output_binary}}' +debugger_port: 40000 +debugger_enabled: false +expose_ports: + - 8080 +environment: + - foo=bar + - hello +networks: + - frontend + - backend \ No newline at end of file diff --git a/pkg/input/environment.go b/pkg/input/environment.go new file mode 100644 index 00000000..81885404 --- /dev/null +++ b/pkg/input/environment.go @@ -0,0 +1,18 @@ +package input + +import ( + "github.com/manifoldco/promptui" + "github.com/moshebe/gebug/pkg/config" +) + +type PromptEnvironment struct { + *config.Config +} + +func (p *PromptEnvironment) Run() error { + prompt := NewSelectWithAddAndRemove(&p.Environment, &promptui.SelectWithAdd{ + Label: "Define environment variables. Press existing choices to delete", + AddLabel: "Add environment variable (e.g: FOO[=BAR])", + }) + return prompt.Run() +}