Skip to content

Commit

Permalink
Build correct arch for container image (helmfile#817)
Browse files Browse the repository at this point in the history
Signed-off-by: Lavi Blumberg <[email protected]>
  • Loading branch information
lavifb authored Apr 19, 2023
1 parent 75e52d7 commit 75092bf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine as builder
FROM --platform=$BUILDPLATFORM golang:1.20-alpine as builder

RUN apk add --no-cache make git
WORKDIR /workspace/helmfile
Expand All @@ -7,11 +7,12 @@ COPY go.mod go.sum /workspace/helmfile/
RUN go mod download

COPY . /workspace/helmfile
RUN make static-linux
ARG TARGETARCH
RUN make static-linux-${TARGETARCH}

# -----------------------------------------------------------------------------

FROM alpine:3.16
FROM --platform=$BUILDPLATFORM alpine:3.16

LABEL org.opencontainers.image.source https://github.com/helmfile/helmfile

Expand Down Expand Up @@ -89,6 +90,7 @@ RUN helm plugin install https://github.com/databus23/helm-diff --version v3.6.0
# Allow users other than root to use helm plugins located in root home
RUN chmod 751 ${HOME}

COPY --from=builder /workspace/helmfile/dist/helmfile_linux_amd64 /usr/local/bin/helmfile
ARG TARGETARCH
COPY --from=builder /workspace/helmfile/dist/helmfile_linux_${TARGETARCH} /usr/local/bin/helmfile

CMD ["/usr/local/bin/helmfile"]
10 changes: 6 additions & 4 deletions Dockerfile.debian-stable-slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine as builder
FROM --platform=$BUILDPLATFORM golang:1.20-alpine as builder

RUN apk add --no-cache make git
WORKDIR /workspace/helmfile
Expand All @@ -7,11 +7,12 @@ COPY go.mod go.sum /workspace/helmfile/
RUN go mod download

COPY . /workspace/helmfile
RUN make static-linux
ARG TARGETARCH
RUN make static-linux-${TARGETARCH}

# -----------------------------------------------------------------------------

FROM debian:stable-slim
FROM --platform=$BUILDPLATFORM debian:stable-slim

LABEL org.opencontainers.image.source https://github.com/helmfile/helmfile

Expand Down Expand Up @@ -94,6 +95,7 @@ RUN helm plugin install https://github.com/databus23/helm-diff --version v3.6.0
# Allow users other than root to use helm plugins located in root home
RUN chmod 751 ${HOME}

COPY --from=builder /workspace/helmfile/dist/helmfile_linux_amd64 /usr/local/bin/helmfile
ARG TARGETARCH
COPY --from=builder /workspace/helmfile/dist/helmfile_linux_${TARGETARCH} /usr/local/bin/helmfile

CMD ["/usr/local/bin/helmfile"]
10 changes: 6 additions & 4 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine as builder
FROM --platform=$BUILDPLATFORM golang:1.20-alpine as builder

RUN apk add --no-cache make git
WORKDIR /workspace/helmfile
Expand All @@ -7,11 +7,12 @@ COPY go.mod go.sum /workspace/helmfile/
RUN go mod download

COPY . /workspace/helmfile
RUN make static-linux
ARG TARGETARCH
RUN make static-linux-${TARGETARCH}

# -----------------------------------------------------------------------------

FROM ubuntu:20.04
FROM --platform=$BUILDPLATFORM ubuntu:20.04

LABEL org.opencontainers.image.source https://github.com/helmfile/helmfile

Expand Down Expand Up @@ -94,6 +95,7 @@ RUN helm plugin install https://github.com/databus23/helm-diff --version v3.6.0
# Allow users other than root to use helm plugins located in root home
RUN chmod 751 ${HOME}

COPY --from=builder /workspace/helmfile/dist/helmfile_linux_amd64 /usr/local/bin/helmfile
ARG TARGETARCH
COPY --from=builder /workspace/helmfile/dist/helmfile_linux_${TARGETARCH} /usr/local/bin/helmfile

CMD ["/usr/local/bin/helmfile"]
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ static-linux:
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOFLAGS=-mod=readonly go build -o "dist/helmfile_linux_amd64" -ldflags="$(GO_BUILD_VERSION_LDFLAGS)" ${TARGETS}
.PHONY: static-linux

static-linux-amd64:
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOFLAGS=-mod=readonly go build -o "dist/helmfile_linux_amd64" -ldflags="$(GO_BUILD_VERSION_LDFLAGS)" ${TARGETS}
.PHONY: static-linux-amd64

static-linux-arm64:
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GOFLAGS=-mod=readonly go build -o "dist/helmfile_linux_arm64" -ldflags="$(GO_BUILD_VERSION_LDFLAGS)" ${TARGETS}
.PHONY: static-linux-arm64

install:
env CGO_ENABLED=0 go install -ldflags="$(GO_BUILD_VERSION_LDFLAGS)" ${TARGETS}
.PHONY: install
Expand Down

0 comments on commit 75092bf

Please sign in to comment.