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 08d950b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
25 changes: 5 additions & 20 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,14 @@ 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:
Expand All @@ -59,6 +43,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
30 changes: 24 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
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


# renovate: datasource=github-releases depName=helmfile/helmfile
Expand All @@ -16,21 +32,23 @@ 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 "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 08d950b

Please sign in to comment.