From aaddc0a1f7307a5bf03320fd5e84c6f5fec576e6 Mon Sep 17 00:00:00 2001 From: Stanislav Bogatyrev Date: Tue, 5 Jul 2022 14:19:09 +0300 Subject: [PATCH] [#570] Fix docker image builds - Moving to Alpine as a base image - Fix dirty image build - Fix version format to match neofs-node Signed-off-by: Stanislav Bogatyrev --- Dockerfile => .docker/Dockerfile | 20 ++++++++------------ .docker/Dockerfile.dirty | 9 +++++++++ Makefile | 8 ++++---- 3 files changed, 21 insertions(+), 16 deletions(-) rename Dockerfile => .docker/Dockerfile (54%) create mode 100644 .docker/Dockerfile.dirty diff --git a/Dockerfile b/.docker/Dockerfile similarity index 54% rename from Dockerfile rename to .docker/Dockerfile index 55d9516c..26b97e7a 100644 --- a/Dockerfile +++ b/.docker/Dockerfile @@ -1,25 +1,21 @@ -FROM golang:1 as builder - -WORKDIR /src - -RUN set -x \ - && apt update \ - && apt install -y make - -COPY . /src +FROM golang:1.17 as builder +ARG BUILD=now ARG REPO=github.com/nspcc-dev/neofs-s3-gw ARG VERSION=dev -RUN set -x && make -o dep # run make without dep dependency +WORKDIR /src +COPY . /src + +RUN make # Executable image -FROM scratch +FROM alpine AS neofs-s3-gw +RUN apk add --no-cache bash ca-certificates WORKDIR / COPY --from=builder /src/bin/neofs-s3-gw /bin/neofs-s3-gw COPY --from=builder /src/bin/neofs-s3-authmate /bin/neofs-s3-authmate -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ ENTRYPOINT ["/bin/neofs-s3-gw"] diff --git a/.docker/Dockerfile.dirty b/.docker/Dockerfile.dirty new file mode 100644 index 00000000..22c0d020 --- /dev/null +++ b/.docker/Dockerfile.dirty @@ -0,0 +1,9 @@ +FROM alpine AS neofs-s3-gw +RUN apk add --no-cache bash ca-certificates + +WORKDIR / + +COPY /bin/neofs-s3-gw /bin/neofs-s3-gw +COPY /bin/neofs-s3-authmate /bin/neofs-s3-authmate + +ENTRYPOINT ["/bin/neofs-s3-gw"] diff --git a/Makefile b/Makefile index fc822880..88008cf4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Common variables REPO ?= $(shell go list -m) -VERSION ?= $(shell git describe --tags 2>/dev/null || cat VERSION 2>/dev/null || echo "develop") +VERSION ?= $(shell git describe --tags --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "develop") GO_VERSION ?= 1.17 LINT_VERSION ?= 1.46.2 BINDIR = bin @@ -67,13 +67,13 @@ format: @gofmt -s -w ./ # Build clean Docker image -image: dep +image: @echo "⇒ Build NeoFS S3 Gateway docker image " @docker build \ --build-arg REPO=$(REPO) \ --build-arg VERSION=$(VERSION) \ --rm \ - -f Dockerfile \ + -f .docker/Dockerfile \ -t $(HUB_IMAGE):$(HUB_TAG) . # Push Docker image to the hub @@ -88,7 +88,7 @@ dirty-image: --build-arg REPO=$(REPO) \ --build-arg VERSION=$(VERSION) \ --rm \ - -f Dockerfile.dirty \ + -f .docker/Dockerfile.dirty \ -t $(HUB_IMAGE)-dirty:$(HUB_TAG) . # Run linters