diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f1e759 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.18 as BuildStage + +# Set destination for COPY +WORKDIR /app + +# Download Go modules +COPY go.mod go.sum ./ +RUN go mod download +COPY . ./ + +# Build +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -o /kaf ./cmd/kaf + +FROM scratch + +WORKDIR / + +COPY --from=BuildStage /kaf /bin/kaf + +USER 1001 + +# Run +CMD ["/bin/kaf"] diff --git a/Makefile b/Makefile index 6ff869f..de78fa7 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,10 @@ +DOCKER_CMD ?= docker +DOCKER_REGISTRY ?= docker.io +DOCKER_ORG ?= $(USER) +DOCKER_NAME ?= kaf +DOCKER_TAG ?= latest +BUILD_TAG ?= latest + build: go build -ldflags "-w -s" ./cmd/kaf install: @@ -6,3 +13,5 @@ release: goreleaser --rm-dist run-kafka: docker-compose up -d +docker-build: + ${DOCKER_CMD} build -t ${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_NAME}:${DOCKER_TAG} .