From f956c6b737ddf54036a03d9bc2b689c4cb2098cb Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Wed, 2 Oct 2024 12:55:36 +0200 Subject: [PATCH] added Dockerfile --- Makefile | 9 +++++++++ proxy-server.dockerfile | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 proxy-server.dockerfile diff --git a/Makefile b/Makefile index e90791d..a0e6f82 100644 --- a/Makefile +++ b/Makefile @@ -76,3 +76,12 @@ cover-html: ## Run tests with coverage and open the HTML report go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./... go tool cover -html=/tmp/go-sim-lb.cover.tmp unlink /tmp/go-sim-lb.cover.tmp + +.PHONY: docker-images +docker-images: ## Build the Docker images + DOCKER_BUILDKIT=1 docker build \ + --platform linux/amd64 \ + --build-arg VERSION=${VERSION} \ + --file proxy-server.dockerfile \ + --tag cvm-proxy-server \ + . diff --git a/proxy-server.dockerfile b/proxy-server.dockerfile new file mode 100644 index 0000000..2f367b9 --- /dev/null +++ b/proxy-server.dockerfile @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.23 AS builder +ARG VERSION +WORKDIR /build +ADD go.mod /build/ +RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux \ + go mod download +ADD . /build/ +RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux \ + go build \ + -trimpath \ + -ldflags "-s -X main.version=${VERSION}" \ + -v \ + -o proxy-server \ + cmd/proxy-server/main.go + +FROM alpine:latest +WORKDIR /app +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /build/proxy-server /app/proxy-server +ENV LISTEN_ADDR=":8080" +EXPOSE 8080 +CMD ["/app/proxy-server"]