Skip to content

Commit

Permalink
Support env vars (#16)
Browse files Browse the repository at this point in the history
* add environment variables support

* remove unused code from version
  • Loading branch information
moshebe authored Jul 22, 2020
1 parent 900daf7 commit 3459d85
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

.idea
gebug
.gebug
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "github.com/moshebe/gebug/cmd"
import (
"github.com/moshebe/gebug/cmd"
)

func main() {
err := cmd.Execute()
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ expose_ports:
- "8080"
- 8081:8081
networks: []
environment: []
`
c := Config{
Name: "my-app",
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ services:
- {{$value}}
{{- end}}
{{- end}}
{{- if .Environment}}
environment:
{{- range $key, $value := .Environment}}
- {{$value}}
{{- end}}
{{- end}}
{{- if .Networks}}
networks:
Expand Down
21 changes: 21 additions & 0 deletions pkg/config/testdata/generate_docker_compose_3.golden
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions pkg/config/testdata/generate_docker_compose_3.in
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions pkg/input/environment.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 3459d85

Please sign in to comment.