Skip to content

Commit

Permalink
fix: Build in docker, improve multiarch
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusramberg committed May 21, 2024
1 parent 2c98c4a commit a475322
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,22 @@ jobs:
strategy:
matrix:
go_version: [1.21]
os: [linux ]
arch: [amd64, arm64]
include:
- os: linux
arch: amd64
goos: linux
goarch: amd64
- os: linux
arch: arm64
goos: linux
goarch: arm64
os: [linux]
platform:
- linux/amd64
- linux/arm64
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go_version }}

- name: Check out code
uses: actions/checkout@v2

- name: Build
run: |
env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -v -o helmfile-nix
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
Expand All @@ -59,6 +45,7 @@ jobs:
with:
context: .
push: true
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
Expand Down
33 changes: 26 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
FROM nixos/nix:2.22.0 AS nix
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.22.1-bullseye as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

WORKDIR /app/
ADD . .
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o helmfile-nix .


# Build the binary.
RUN go build -mod=readonly -v -o helmfile-nix .

FROM --platform=${BUILDPLATFORM:-linux/amd64} nixos/nix:2.22.0 AS nix

RUN nix build --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#nixStatic

FROM alpine:3.19@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b
FROM --platform=${BUILDPLATFORM:-linux/amd64} alpine:3.19@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b
ARG TARGETOS
ARG TARGETARCH


# renovate: datasource=github-releases depName=helmfile/helmfile
ARG HELMFILE_VERSION=v0.163.1
# renovate: datasource=github-releases depName=helm/helm
ARG HELM_VERSION=v3.14.3
ARG HELM_VERSION=v3.15.0
# renovate: datasource=github-releases depName=databus23/helm-diff
ARG HELM_DIFF_VERSION=v3.9.5
# renovate: datasource=github-releases depName=kubernetes-sigs/kustomize
ARG KUSTOMIZE_VERSION=5.3.0

COPY --from=nix ./result/ /

ADD helmfile-nix /usr/local/bin/helmfile-nix
COPY --from=builder /app/helmfile-nix /usr/local/bin/helmfile-nix

ENV INSTALL_PATH=/usr/local/bin

RUN echo "Building for ${TARGETOS}-${TARGETARCH}"

RUN apk add --update --no-cache bash curl git yq && \
chmod +x ${INSTALL_PATH}/helmfile-nix && \
# helmfile
HELMFILE_STRIPPED=$(echo "$HELMFILE_VERSION" | cut -c2-) && \
export HELMFILE_STRIPPED && \
curl -sSL "https://github.com/helmfile/helmfile/releases/download/${HELMFILE_VERSION}/helmfile_${HELMFILE_STRIPPED}_linux_amd64.tar.gz" | tar -zx -C ${INSTALL_PATH} -f - helmfile && \
curl -sSL "https://github.com/helmfile/helmfile/releases/download/${HELMFILE_VERSION}/helmfile_${HELMFILE_STRIPPED}_linux_${TARGETARCH}.tar.gz" | tar -zx -C ${INSTALL_PATH} -f - helmfile && \
chmod +x ${INSTALL_PATH}/helmfile && \
# Install kustomize
curl -sSL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_amd64.tar.gz" | tar -zx -C ${INSTALL_PATH} -f - && \
curl -sSL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz" | tar -zx -C ${INSTALL_PATH} -f - && \
# Install helm and friends
curl -sSL "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz" | tar -zx --strip-components=1 -C ${INSTALL_PATH} -f - linux-amd64/helm && \
curl -sSL "https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz" | tar -zx --strip-components=1 -C ${INSTALL_PATH} -f - linux-${TARGETARCH}/helm && \
helm plugin install https://github.com/databus23/helm-diff --version ${HELM_DIFF_VERSION}

VOLUME /nix
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pkgs.mkShell {
packages = [
goEnv
gomod2nix
pkgs.docker
pkgs.helmfile
pkgs.kubernetes-helm
];
Expand Down

0 comments on commit a475322

Please sign in to comment.