From 5753a5e21411e9635541e8d1071ef3232b2ddefa Mon Sep 17 00:00:00 2001 From: Will Ockelmann-Wagner Date: Sun, 26 May 2024 00:03:48 -0700 Subject: [PATCH] dockerfile for examples --- examples/Dockerfile | 18 ++++++++++++++++++ examples/Taskfile.yml | 5 +++++ examples/cmd/server/main.go | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 examples/Dockerfile diff --git a/examples/Dockerfile b/examples/Dockerfile new file mode 100644 index 0000000..fbbc7a7 --- /dev/null +++ b/examples/Dockerfile @@ -0,0 +1,18 @@ +FROM --platform=$BUILDPLATFORM golang:alpine as builder +WORKDIR /go/src/app + +RUN apk add git + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +ARG TARGETOS TARGETARCH +# Static build required so that we can safely copy the binary over. +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o ./bin/server -ldflags '-extldflags "-static"' ./cmd/server/main.go + +FROM scratch +COPY --from=builder /go/src/app/bin/server /server +EXPOSE 8080 +ENTRYPOINT ["/server"] diff --git a/examples/Taskfile.yml b/examples/Taskfile.yml index d05a351..4344366 100644 --- a/examples/Taskfile.yml +++ b/examples/Taskfile.yml @@ -62,3 +62,8 @@ tasks: desc: Install tools cmds: - go install github.com/a-h/templ/cmd/templ@latest + + push: + desc: Push to docker hub + cmds: + - docker buildx build --platform linux/arm64 -t willwow/thxgo:latest --push . diff --git a/examples/cmd/server/main.go b/examples/cmd/server/main.go index 0b376e4..1a975b8 100644 --- a/examples/cmd/server/main.go +++ b/examples/cmd/server/main.go @@ -14,7 +14,7 @@ func main() { //nolint:exhaustruct server := &http.Server{ - Addr: "localhost:8080", + Addr: ":8080", Handler: handler, ReadTimeout: time.Second * 10, WriteTimeout: time.Second * 10,