Skip to content

Commit

Permalink
add support for pre run command and custom build dir for CompileDaemon (
Browse files Browse the repository at this point in the history
  • Loading branch information
moshebe committed Jan 19, 2021
1 parent 6918859 commit eba60a8
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ var AppFs = afero.NewOsFs()
type Config struct {
Name string `yaml:"name" json:"name"`
OutputBinaryPath string `yaml:"output_binary" json:"outputBinary"`
PreRunCommands []string `yaml:"pre_run_commands,omitempty" json:"preRunCommands"`
BuildCommand string `yaml:"build_command" json:"buildCommand"`
BuildDir string `yaml:"build_dir" json:"buildDir"`
RunCommand string `yaml:"run_command" json:"runCommand"`
RuntimeImage string `yaml:"runtime_image" json:"runtimeImage"`
DebuggerEnabled bool `yaml:"debugger_enabled" json:"debuggerEnabled"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestConfig_Write(t *testing.T) {
Name: "my-app",
OutputBinaryPath: "/app",
BuildCommand: "go build -o /app -gcflags=\"all=-N-l\"",
BuildDir: "/app",
RunCommand: "/app",
RuntimeImage: "golang:1.15.2",
DebuggerPort: 40000,
Expand All @@ -130,6 +131,7 @@ func TestConfig_Write(t *testing.T) {
expected: `name: my-app
output_binary: /app
build_command: go build -o /app -gcflags="all=-N-l"
build_dir: /app
run_command: /app
runtime_image: golang:1.15.2
debugger_enabled: true
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ func (c *Config) RenderDockerfile(writer io.Writer) error {
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
{{- if .PreRunCommands}}{{range .PreRunCommands}}
RUN {{.}}{{end}}{{end}}
WORKDIR /src
COPY . .
{{if .DebuggerEnabled -}}
RUN {{.BuildCommand}}
ENTRYPOINT dlv --listen=:{{.DebuggerPort}} --headless=true --api-version=2 --accept-multiclient exec {{.OutputBinaryPath}}
{{- else -}}
ENTRYPOINT CompileDaemon -log-prefix=false -build="{{.BuildCommand}}" -command="{{.RunCommand}}"
ENTRYPOINT CompileDaemon -log-prefix=false -build="{{.BuildCommand}}"{{if .BuildDir }} -build-dir="{{.BuildDir}}"{{ end}} -command="{{.RunCommand}}"
{{- end}}`, writer)
}
1 change: 0 additions & 1 deletion pkg/config/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TestConfig_RenderDockerfile(t *testing.T) {
`FROM golang:1.15.2
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
WORKDIR /src
COPY . .
Expand Down
1 change: 0 additions & 1 deletion pkg/config/testdata/generate_dockerfile_0.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM golang:1.15.2
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv

WORKDIR /src
COPY . .

Expand Down
1 change: 0 additions & 1 deletion pkg/config/testdata/generate_dockerfile_1.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM golang:1.15.2
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv

WORKDIR /src
COPY . .

Expand Down
7 changes: 7 additions & 0 deletions pkg/config/testdata/generate_dockerfile_2.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.15.2
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
WORKDIR /src
COPY . .

ENTRYPOINT CompileDaemon -log-prefix=false -build="go build -o /app" -build-dir="/src" -command="/app"
10 changes: 10 additions & 0 deletions pkg/config/testdata/generate_dockerfile_2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
build_dir: /src
runtime_image: golang:1.15.2
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
expose_ports:
- 8080
9 changes: 9 additions & 0 deletions pkg/config/testdata/generate_dockerfile_3.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.15.2
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
RUN echo "hello" && echo "world"
RUN ls
WORKDIR /src
COPY . .

ENTRYPOINT CompileDaemon -log-prefix=false -build="go build -o /app" -build-dir="/src" -command="/app"
13 changes: 13 additions & 0 deletions pkg/config/testdata/generate_dockerfile_3.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: my-app
output_binary: /app
pre_run_commands:
- echo "hello" && echo "world"
- ls
build_command: go build -o {{.output_binary}}
build_dir: /src
runtime_image: golang:1.15.2
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
expose_ports:
- 8080

0 comments on commit eba60a8

Please sign in to comment.