Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for pre run command and custom build dir #83

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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