From 335c7e949aee6ae4a8b7eb1883557253bcb886d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bojan=20=C4=8Cekrli=C4=87?= Date: Fri, 27 Oct 2023 11:24:40 +0200 Subject: [PATCH] Fix: Fix building of Postfix exporter with newer version of Go and other architectures Build should be faster now as well, as it's being built on the build platform and not through QEMU. --- .../build-postfix-exporter/action.yaml | 2 +- .github/workflows/master.yml | 3 ++- helm/mail/templates/statefulset.yaml | 11 ++------ postfix-exporter-01.patch | 25 ++++++++++++++++--- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/actions/build-postfix-exporter/action.yaml b/.github/actions/build-postfix-exporter/action.yaml index 791f82d..eb6b376 100644 --- a/.github/actions/build-postfix-exporter/action.yaml +++ b/.github/actions/build-postfix-exporter/action.yaml @@ -47,7 +47,7 @@ runs: context: postfix_exporter push: true tags: '${{ inputs.tags }}' - platforms: "linux/386,linux/arm/v5,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64,linux/arm64,linux/ppc64le,linux/s390x" + platforms: "linux/386,linux/arm/v5,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/mips64le,linux/riscv64" cache-from: type=local,src=/tmp/.buildx-cache/postfix-exporter,mode=max,compression=estargz cache-to: type=local,dest=/tmp/.buildx-cache-new/postfix-exporter diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index f037240..2691253 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -94,7 +94,8 @@ jobs: boky/postfix:edge-alpine # linux/s390x: "rsyslog (no such package)" # Latest Alpine does not have all the packages for 386 anymore. :-( - platforms: "linux/arm/v6,linux/arm/v7,linux/amd64,linux/arm64,linux/ppc64le" + # Latest Alpine does not have 'pandoc' in 'linux/arm/v7', which means SASL module cannot be built + platforms: "linux/arm/v6,linux/amd64,linux/arm64,linux/ppc64le" cache-from: type=local,src=/tmp/.buildx-cache/alpine,mode=max,compression=estargz cache-to: type=local,dest=/tmp/.buildx-cache-new/alpine build-args: | diff --git a/helm/mail/templates/statefulset.yaml b/helm/mail/templates/statefulset.yaml index 7756b87..dbc9b1b 100644 --- a/helm/mail/templates/statefulset.yaml +++ b/helm/mail/templates/statefulset.yaml @@ -158,20 +158,13 @@ spec: - name: {{ $fullName | quote }} mountPath: {{ regexFind "^/?.*/" .Values.metrics.maillog | quote }} subPath: logs - startupProbe: - exec: - command: - - sh - - -c - - >- - [ -f {{ .Values.metrics.maillog | quote }} ] && grep -qi "starting the Postfix mail system" {{ .Values.metrics.maillog | quote }} - failureThreshold: 30 - periodSeconds: 10 readinessProbe: httpGet: path: {{ .Values.metrics.path | quote }} port: {{ .Values.metrics.port }} initialDelaySeconds: 5 + failureThreshold: 30 + periodSeconds: 10 {{- end }} {{- if .Values.extraContainers }} {{- tpl .Values.extraContainers $root | nindent 8 }} diff --git a/postfix-exporter-01.patch b/postfix-exporter-01.patch index 0c8e75e..6548e0c 100644 --- a/postfix-exporter-01.patch +++ b/postfix-exporter-01.patch @@ -1,12 +1,25 @@ diff --git a/Dockerfile b/Dockerfile -index a3327d8..ce8e22c 100644 +index a3327d8..c082f5b 100644 --- a/Dockerfile +++ b/Dockerfile -@@ -14,7 +14,15 @@ COPY . . +@@ -1,4 +1,10 @@ +-FROM golang:1.16 AS builder ++# syntax=docker/dockerfile:1.2 ++FROM --platform=$BUILDPLATFORM golang:1.21 AS builder ++ARG TARGETPLATFORM ++ARG TARGETOS ++ARG TARGETARCH ++ARG TARGETVARIANT ++ + WORKDIR /src + + # avoid downloading the dependencies on succesive builds +@@ -14,10 +20,18 @@ COPY . . # Force the go compiler to use modules ENV GO111MODULE=on -RUN go test +-RUN go build -o /bin/postfix_exporter +# go test fails (sometimes) because it relies on an external dependency: +# +# warning: SASL authentication failure: cannot connect to saslauthd server: Permission denied @@ -16,6 +29,10 @@ index a3327d8..ce8e22c 100644 +# Since we are checking out a specific SHA hash and we know this tests have worked previously, we are quite certain that the code will work. +# Hence disabling the test here. +# RUN go test - RUN go build -o /bin/postfix_exporter ++RUN env GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$TARGETVARIANT go build -ldflags '-extldflags "-static"' -o /bin/postfix_exporter - FROM debian:latest +-FROM debian:latest ++FROM scratch + EXPOSE 9154 + WORKDIR / + COPY --from=builder /bin/postfix_exporter /bin/