Skip to content

Commit

Permalink
adjusted dockerfile so that build args can be provided to switch the … (
Browse files Browse the repository at this point in the history
#8420)

* 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 <christopher.donlan@gtri.gatech.edu>
  • Loading branch information
chrisdonlan and Donlan, Christopher authored Dec 19, 2024
1 parent b60c6c7 commit b8da7b3
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b8da7b3

Please sign in to comment.