Skip to content

Commit

Permalink
builds: multi-arch docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
zegl committed Dec 8, 2022
1 parent 94b01e0 commit 2c08121
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 37 deletions.
37 changes: 0 additions & 37 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,6 @@ archives:
files:
- LICENSE

dockers:
- goos: linux
goarch: amd64
ids:
- kube-score
image_templates:
- "zegl/kube-score:{{ .Tag }}"
- "zegl/kube-score:latest"
dockerfile: cmd/kube-score/Dockerfile

- goos: linux
goarch: amd64
ids:
- kube-score
image_templates:
- "zegl/kube-score:{{ .Tag }}-helm"
- "zegl/kube-score:latest-helm"
dockerfile: cmd/kube-score/helm.Dockerfile

- goos: linux
goarch: amd64
ids:
- kube-score
image_templates:
- "zegl/kube-score:{{ .Tag }}-helm3"
- "zegl/kube-score:latest-helm3"
dockerfile: cmd/kube-score/helm3.Dockerfile

- goos: linux
goarch: amd64
ids:
- kube-score
image_templates:
- "zegl/kube-score:{{ .Tag }}-kustomize"
- "zegl/kube-score:latest-kustomize"
dockerfile: cmd/kube-score/kustomize.Dockerfile

checksum:
name_template: 'checksums.txt'

Expand Down
72 changes: 72 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# syntax=docker/dockerfile:1

ARG ALPINE_IMAGE=alpine:3.17.0

FROM ${ALPINE_IMAGE} as args
ARG HELM_VERSION=v3.10.2
ARG KUSTOMIZE_VERSION=v4.5.7

FROM args as args-amd64
ARG HELM_SHA256SUM="2315941a13291c277dac9f65e75ead56386440d3907e0540bf157ae70f188347"
ARG KUSTOMIZE_SHA256SUM="701e3c4bfa14e4c520d481fdf7131f902531bfc002cb5062dcf31263a09c70c9"

FROM args as args-arm64
ARG HELM_SHA256SUM="57fa17b6bb040a3788116557a72579f2180ea9620b4ee8a9b7244e5901df02e4"
ARG KUSTOMIZE_SHA256SUM="65665b39297cc73c13918f05bbe8450d17556f0acd16242a339271e14861df67"

# FROM args as args-arm
# ARG HELM_SHA256SUM="25af344f46348958baa1c758cdf3b204ede3ddc483be1171ed3738d47efd0aae"

FROM --platform=$BUILDPLATFORM args-${TARGETARCH} as downloader

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETARCH

RUN apk update && apk add curl

RUN curl --location "https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz" > helm.tar.gz && \
echo "${HELM_SHA256SUM} helm.tar.gz" | sha256sum && \
tar xzvf helm.tar.gz && \
chmod +x /linux-${TARGETARCH}/helm && \
mv /linux-${TARGETARCH}/helm /usr/bin/helm

RUN curl --location "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz" > kustomize.tar.gz && \
echo "${KUSTOMIZE_SHA256SUM} kustomize.tar.gz" | sha256sum && \
tar xzvf kustomize.tar.gz && \
chmod +x kustomize && \
mv kustomize /usr/bin/kustomize

FROM golang:1.19-alpine as builder
ARG TARGETARCH
ARG TARGETPLATFORM
WORKDIR /kube-score
COPY go.mod go.sum ./
RUN go mod download
COPY . .

ARG KUBE_SCORE_VERSION
ARG KUBE_SCORE_COMMIT
ARG KUBE_SCORE_DATE

RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 \
go build \
-ldflags="-X 'main.version=${KUBE_SCORE_VERSION}-docker-${TARGETPLATFORM}' -X 'main.commit=${KUBE_SCORE_COMMIT}' -X 'main.date=${KUBE_SCORE_DATE}'" \
-o /usr/bin/kube-score \
./cmd/kube-score

FROM ${ALPINE_IMAGE} as runner
RUN apk update && \
apk upgrade && \
apk add bash ca-certificates
COPY --from=downloader /usr/bin/helm /usr/bin/helm
COPY --from=downloader /usr/bin/kustomize /usr/bin/kustomize
COPY --from=builder /usr/bin/kube-score /kube-score
COPY --from=builder /usr/bin/kube-score /usr/bin/kube-score

# Dry runs
RUN /kube-score version && helm version && kustomize version

WORKDIR /project
ENTRYPOINT ["/kube-score"]
15 changes: 15 additions & 0 deletions hack/release-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

#VERSION="$(git describe --tags --abbrev=0)"
VERSION="v1.16.0-dev"

docker buildx build \
--build-arg KUBE_SCORE_VERSION=${VERSION} \
--build-arg "KUBE_SCORE_COMMIT=$(git rev-parse HEAD)" \
--build-arg "KUBE_SCORE_DATE=$(date -Iseconds)" \
--platform linux/arm64 \
--platform linux/amd64 \
-t zegl/kube-score:${VERSION} \
--push \
--target runner \
.

0 comments on commit 2c08121

Please # to comment.