Dockerfile: reuse make, drop upx

upx is nice, but not necessary for this and duplicating Makefile is just not
good.

Note that in absence of vendoring building this can be problematic at the
moment because of private repository dependency, it'll be solved in future.
This commit is contained in:
Roman Khimov 2021-05-13 22:08:33 +03:00
parent 4577077981
commit e15159443b

View file

@ -4,36 +4,20 @@ WORKDIR /src
RUN set -x \ RUN set -x \
&& apt update \ && apt update \
&& apt install -y upx-ucl && apt install -y make
COPY . /src COPY . /src
ARG VERSION=dev ARG VERSION=dev
# https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away RUN make
# go build -mod=vendor
# The -gcflags "all=-N -l" flag helps us get a better debug experience
RUN set -x \
&& export BUILD=$(date -u +%s%N) \
&& export REPO=$(go list -m) \
&& export LDFLAGS="-X ${REPO}/misc.Version=${VERSION} -X ${REPO}/misc.Build=${BUILD}" \
&& export GOGC=off \
&& export CGO_ENABLED=0 \
&& [ -d "./vendor" ] || go mod vendor \
&& go build \
-v \
-mod=vendor \
-trimpath \
-ldflags "${LDFLAGS}" \
-o /go/bin/neofs-s3 ./cmd/gate \
&& upx -3 /go/bin/neofs-s3
# Executable image # Executable image
FROM scratch FROM scratch
WORKDIR / WORKDIR /
COPY --from=builder /go/bin/neofs-s3 /bin/neofs-s3 COPY --from=builder /src/bin/neofs-s3-gw /bin/neofs-s3-gw
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/bin/neofs-s3"] ENTRYPOINT ["/bin/neofs-s3-gw"]