From 72698a43e350c85db41a237b372b0b53a46772e8 Mon Sep 17 00:00:00 2001 From: "Donlan, Christopher" Date: Fri, 13 Dec 2024 16:04:20 -0500 Subject: [PATCH 1/2] adjusted dockerfile so that build args can be provided to switch the build from musl-amd64 to amd64 --- Dockerfile | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9edd9b62e2..36c5627323b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,43 @@ # 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 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 +FROM build AS build-lakefs ARG VERSION TARGETOS TARGETARCH 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 +FROM build AS build-lakectl ARG VERSION TARGETOS TARGETARCH 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 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 From a642839b84b43f59f137b3e6f89d0c1915b6714f Mon Sep 17 00:00:00 2001 From: "Donlan, Christopher" Date: Mon, 16 Dec 2024 15:36:56 -0500 Subject: [PATCH 2/2] [adjust-arch-w-build-args] adjusted scope of args --- Dockerfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36c5627323b..9fde2b5bc5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,16 +3,18 @@ ARG VERSION=dev ARG BUILD_REPO=golang ARG BUILD_TAG=1.22.6-alpine3.20 -ARG BUILD_PACKAGES=build-base ca-certificates +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 +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 $ADD_PACKAGES $BUILD_PACKAGES COPY go.mod go.sum ./ @@ -20,20 +22,21 @@ RUN --mount=type=cache,target=/go/pkg go mod download COPY . ./ FROM build AS build-lakefs -ARG VERSION TARGETOS TARGETARCH +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 +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 $IMAGE_REPO:$IMAGE_TAG AS lakectl +ARG ADD_PACKAGES IMAGE_PACKAGES WORKDIR /app ENV PATH=/app:$PATH COPY --from=build-lakectl /build/lakectl /app/