From ec02269b282e71e5f4334094d76b7b43a4db880b Mon Sep 17 00:00:00 2001 From: kaibocai Date: Fri, 5 Jan 2024 13:11:43 -0600 Subject: [PATCH 1/7] add docker file --- Dockerfile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d2eedca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.21 + +COPY . /root +WORKDIR /root + +# Download Go modules +COPY go.mod go.sum ./ +RUN go mod download + +# Build +RUN CGO_ENABLED=0 GOOS=linux go build -o /durabletask-go + +# To bind to a TCP port, runtime parameters must be supplied to the docker command. +# But we can (optionally) document in the Dockerfile what ports +# the application is going to listen on by default. +# https://docs.docker.com/engine/reference/builder/#expose +EXPOSE 4001 + +# Run +ENTRYPOINT [ "/durabletask-go" ] \ No newline at end of file From 594a9cfde92e077bbbab9c1740db15979b09fe62 Mon Sep 17 00:00:00 2001 From: kaibocai Date: Fri, 5 Jan 2024 17:22:56 -0600 Subject: [PATCH 2/7] update docker file --- Dockerfile | 3 ++- main.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d2eedca..e1871db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,4 +19,5 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o /durabletask-go EXPOSE 4001 # Run -ENTRYPOINT [ "/durabletask-go" ] \ No newline at end of file +ENTRYPOINT [ "/durabletask-go" ] +CMD [ "--ip", "0.0.0.0" ] \ No newline at end of file diff --git a/main.go b/main.go index 5c71b6a..b508ed3 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( var ( port = flag.Int("port", 4001, "The server port") + ip = flag.String("ip", "localhost", "The server IP") dbFilePath = flag.String("db", "", "The path to the sqlite file to use (or create if not exists)") ctx = context.Background() ) @@ -29,7 +30,7 @@ func main() { log.Fatalf("failed to start worker: %v", err) } - lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port)) + lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *ip, *port)) if err != nil { log.Fatalf("failed to listen: %v", err) } From 81d9547fd3d227f1a6b94cda0bed0c57202a0408 Mon Sep 17 00:00:00 2001 From: kaibocai Date: Fri, 5 Jan 2024 17:25:57 -0600 Subject: [PATCH 3/7] clean up --- Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e1871db..858ac17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,10 +12,6 @@ RUN go mod download # Build RUN CGO_ENABLED=0 GOOS=linux go build -o /durabletask-go -# To bind to a TCP port, runtime parameters must be supplied to the docker command. -# But we can (optionally) document in the Dockerfile what ports -# the application is going to listen on by default. -# https://docs.docker.com/engine/reference/builder/#expose EXPOSE 4001 # Run From baf6e435049feee3cde870003234ff3abe5aa6e4 Mon Sep 17 00:00:00 2001 From: kaibocai Date: Fri, 5 Jan 2024 17:29:55 -0600 Subject: [PATCH 4/7] more clean up --- Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 858ac17..0e4eb90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,6 @@ FROM golang:1.21 COPY . /root WORKDIR /root -# Download Go modules -COPY go.mod go.sum ./ -RUN go mod download - # Build RUN CGO_ENABLED=0 GOOS=linux go build -o /durabletask-go From b735bfe12996768f34f0f6f2a219421ae678e6bf Mon Sep 17 00:00:00 2001 From: kaibocai Date: Wed, 10 Jan 2024 08:08:04 -0600 Subject: [PATCH 5/7] minor updates --- Dockerfile | 2 +- main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0e4eb90..56c8003 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,4 @@ EXPOSE 4001 # Run ENTRYPOINT [ "/durabletask-go" ] -CMD [ "--ip", "0.0.0.0" ] \ No newline at end of file +CMD [ "--host", "0.0.0.0", "--port", "4001" ] \ No newline at end of file diff --git a/main.go b/main.go index b508ed3..682efeb 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( var ( port = flag.Int("port", 4001, "The server port") - ip = flag.String("ip", "localhost", "The server IP") + host = flag.String("host", "localhost", "The server host") dbFilePath = flag.String("db", "", "The path to the sqlite file to use (or create if not exists)") ctx = context.Background() ) @@ -30,7 +30,7 @@ func main() { log.Fatalf("failed to start worker: %v", err) } - lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *ip, *port)) + lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *host, *port)) if err != nil { log.Fatalf("failed to listen: %v", err) } From 58b2f1609d83f6431b5356b58e515e784f4c1da7 Mon Sep 17 00:00:00 2001 From: kaibocai Date: Wed, 10 Jan 2024 14:12:21 -0600 Subject: [PATCH 6/7] update dockerfile to use multistage build --- Dockerfile | 5 ++++- main.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 56c8003..9a30201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM golang:1.21 +FROM golang:1.21 as build COPY . /root WORKDIR /root @@ -8,6 +8,9 @@ WORKDIR /root # Build RUN CGO_ENABLED=0 GOOS=linux go build -o /durabletask-go +FROM gcr.io/distroless/static-debian11 +COPY --from=build /durabletask-go / + EXPOSE 4001 # Run diff --git a/main.go b/main.go index 682efeb..f816ec1 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( var ( port = flag.Int("port", 4001, "The server port") - host = flag.String("host", "localhost", "The server host") + host = flag.String("host", "localhost", "The host to bind to") dbFilePath = flag.String("db", "", "The path to the sqlite file to use (or create if not exists)") ctx = context.Background() ) From 2bfd62ec95ba96294a843077b805ab20a68843b0 Mon Sep 17 00:00:00 2001 From: kaibocai Date: Wed, 10 Jan 2024 19:23:05 -0600 Subject: [PATCH 7/7] update to nonroot user --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9a30201..6110173 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /root # Build RUN CGO_ENABLED=0 GOOS=linux go build -o /durabletask-go -FROM gcr.io/distroless/static-debian11 +FROM gcr.io/distroless/static-debian12:nonroot COPY --from=build /durabletask-go / EXPOSE 4001