From b8da7b3708f1940d2cc480253f3b5446d035a923 Mon Sep 17 00:00:00 2001 From: Christopher Donlan Date: Thu, 19 Dec 2024 14:08:18 -0500 Subject: [PATCH] =?UTF-8?q?adjusted=20dockerfile=20so=20that=20build=20arg?= =?UTF-8?q?s=20can=20be=20provided=20to=20switch=20the=20=E2=80=A6=20(#842?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adjusted dockerfile so that build args can be provided to switch the build from musl-amd64 to amd64 * [adjust-arch-w-build-args] adjusted scope of args --------- Co-authored-by: Donlan, Christopher --- Dockerfile | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9edd9b62e2..9fde2b5bc5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,46 @@ # syntax=docker/dockerfile:1 ARG VERSION=dev -FROM --platform=$BUILDPLATFORM golang:1.22.6-alpine3.20 AS build +ARG BUILD_REPO=golang +ARG BUILD_TAG=1.22.6-alpine3.20 +ARG BUILD_PACKAGES="build-base ca-certificates" + +ARG IMAGE_REPO=alpine +ARG IMAGE_TAG=3.18 +ARG IMAGE_PACKAGES=ca-certificates + +ARG ADD_PACKAGES="apk add -U --no-cache" + + +FROM --platform=$BUILDPLATFORM $BUILD_REPO:$BUILD_TAG AS build +ARG ADD_PACKAGES BUILD_PACKAGES + WORKDIR /build -RUN apk add --no-cache build-base ca-certificates +RUN $ADD_PACKAGES $BUILD_PACKAGES COPY go.mod go.sum ./ RUN --mount=type=cache,target=/go/pkg go mod download COPY . ./ -FROM build as build-lakefs -ARG VERSION TARGETOS TARGETARCH +FROM build AS build-lakefs +ARG VERSION TARGETOS TARGETARCH ADD_PACKAGES BUILD_PACKAGES RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ GOOS=$TARGETOS GOARCH=$TARGETARCH \ go build -ldflags "-X github.com/treeverse/lakefs/pkg/version.Version=${VERSION}" -o lakefs ./cmd/lakefs -FROM build as build-lakectl -ARG VERSION TARGETOS TARGETARCH +FROM build AS build-lakectl +ARG VERSION TARGETOS TARGETARCH ADD_PACKAGES BUILD_PACKAGES RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ GOOS=$TARGETOS GOARCH=$TARGETARCH \ go build -ldflags "-X github.com/treeverse/lakefs/pkg/version.Version=${VERSION}" -o lakectl ./cmd/lakectl -FROM alpine:3.18 AS lakectl +FROM $IMAGE_REPO:$IMAGE_TAG AS lakectl +ARG ADD_PACKAGES IMAGE_PACKAGES WORKDIR /app -ENV PATH /app:$PATH +ENV PATH=/app:$PATH COPY --from=build-lakectl /build/lakectl /app/ -RUN apk add -U --no-cache ca-certificates +RUN $ADD_PACKAGES $IMAGE_PACKAGES RUN addgroup -S lakefs && adduser -S lakefs -G lakefs USER lakefs WORKDIR /home/lakefs