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.
This commit is contained in:
Bojan Čekrlić 2023-10-27 11:24:40 +02:00
parent 2082f159f8
commit 335c7e949a
4 changed files with 26 additions and 15 deletions

View file

@ -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

View file

@ -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: |

View file

@ -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 }}

View file

@ -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/