From 5547b96aeff795da43fbc6e2dc8ec7b5dda7691d Mon Sep 17 00:00:00 2001 From: Hank Donnay Date: Fri, 28 Jul 2023 14:54:46 -0500 Subject: [PATCH] Dockerfile: remove sh loop This invocation is equivalent and should be slightly faster by letting all the commands link in parallel. Signed-off-by: Hank Donnay --- Dockerfile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 82d54d0566..f900a615e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,13 +14,21 @@ ARG GO_VERSION=1.20 FROM quay.io/projectquay/golang:${GO_VERSION} AS build -WORKDIR /build/ -ADD . /build/ +WORKDIR /build +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,source=go.mod,target=go.mod \ + --mount=type=bind,source=go.sum,target=go.sum \ + go mod download +COPY . . ARG CLAIR_VERSION="" -RUN for cmd in clair clairctl; do\ +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ go build \ - -trimpath -ldflags="-s -w$(test -n "$CLAIR_VERSION" && printf " -X 'github.com/quay/clair/v4/cmd.Version=%s (user)'" "${CLAIR_VERSION}")" \ - ./cmd/$cmd; done + -ldflags="-s -w$(test -n "$CLAIR_VERSION" && printf " -X 'github.com/quay/clair/v4/cmd.Version=%s (user)'" "${CLAIR_VERSION}")" \ + -o . \ + -trimpath \ + ./cmd/... FROM registry.access.redhat.com/ubi8/ubi-minimal AS final ENTRYPOINT ["/bin/clair"]