Skip to content

Commit

Permalink
Fix: Fix build for differrent archs, make Debian default image
Browse files Browse the repository at this point in the history
  • Loading branch information
bokysan committed Oct 27, 2023
1 parent 335c7e9 commit 19dd690
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ jobs:
boky/postfix:edge-alpine
# linux/s390x: "rsyslog (no such package)"
# Latest Alpine does not have all the packages for 386 anymore. :-(
# 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"
# Pandoc, which is required for SASL build, cannot be found in these images: linux/arm/v7,linux/ppc64le
platforms: "linux/arm/v6,linux/amd64,linux/arm64"
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: |
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ jobs:
context: .
push: true
tags: |
boky/postfix:latest
boky/postfix:latest-alpine
boky/postfix:${{ env.RELEASE_VERSION }}
boky/postfix:${{ env.RELEASE_VERSION }}-alpine
boky/postfix:${{ env.RELEASE_VERSION_NO_v }}
boky/postfix:${{ env.RELEASE_VERSION_NO_v }}-alpine
# linux/s390x: "rsyslog (no such package)"
# Latest Alpine does not have all packages for 386 any more :-(
platforms: "linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le"
# Pandoc, which is required for SASL build, cannot be found in these images: linux/arm/v7,linux/ppc64le
platforms: "linux/arm/v6,linux/amd64,linux/arm64"
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: |
Expand Down Expand Up @@ -199,7 +197,10 @@ jobs:
context: .
push: true
tags: |
boky/postfix:latest
boky/postfix:latest-debian
boky/postfix:${{ env.RELEASE_VERSION }}
boky/postfix:${{ env.RELEASE_VERSION_NO_v }}
boky/postfix:${{ env.RELEASE_VERSION }}-debian
boky/postfix:${{ env.RELEASE_VERSION_NO_v }}-debian
platforms: "linux/386,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/amd64,linux/arm64,linux/mips64le,linux/ppc64le,linux/s390x"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ by ISPs, already occupied by other services, and in general should only be used

Several potentially "surprising" changes went into this issue and hence warrant a version upgrade:

- **Default image is now based on Debian.** A lot of packages needed for
latest builds are missing in certain Alpine architectures. Debian
allows us to have a greater cross-platform availability.
- Helm charts are now built with `v` and without `v` prefix.
As seen in [PR #141](https://github.com/bokysan/docker-postfix/pull/141) some tools rely on version not
having the prefix. I've seen both in the wild, so the image
Expand Down
46 changes: 41 additions & 5 deletions build-scripts/sasl-build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
#!/bin/sh
set -e

do_build() {
build_pandoc() {
CAN_INSTALL=1
if [ -f /etc/alpine-release ];
if ! apk add --upgrade pandoc; then
CAN_INSTALL=0
fi
else
if ! apt-get install -y --no-install-recommends; then
CAN_INSTALL=0
fi
fi
if [ -f /etc/alpine-release ];
apk add --upgrade cabal curl llvm
else
apt-get install -y --no-install-recommends cabal curl llvm
fi
mkdir pandoc
curl --retry 5 --max-time 300 --connect-timeout 10 -fsSL https://github.com/jgm/pandoc/archive/refs/tags/3.1.8.tar.gz | tar xvzf - --strip-components 1 -C pandoc
cd pandoc
cabal update
cabal install --only-dependencies --lib
cabal configure \
--enable-optimization=2 \
--disable-tests \
--disable-documentation \
--disable-benchmarks \
--disable-coverage \
--disable-library-stripping \
--disable-executable-stripping \
--disable-profiling \
--enable-static
cabal build
}

build_sasl2() {
git clone --depth 1 --branch ${SASL_XOAUTH2_GIT_REF} ${SASL_XOAUTH2_REPO_URL} /sasl-xoauth2
cd /sasl-xoauth2
mkdir build
Expand All @@ -19,16 +53,18 @@ do_build() {
}

if [ -f /etc/alpine-release ]; then
apk add --upgrade --virtual .build-deps git cmake clang make gcc g++ libc-dev pkgconfig curl-dev jsoncpp-dev cyrus-sasl-dev patch pandoc
do_build
apk add --upgrade --virtual .build-deps git cmake clang make gcc g++ libc-dev pkgconfig curl-dev jsoncpp-dev cyrus-sasl-dev patch
build_pandoc
build_sasl2
apk del .build-deps;
else
[ -f /etc/lsb-release ] && . /etc/lsb-release
[ -f /etc/os-release ] && . /etc/os-release
apt-get update -y -qq
LIBS="git build-essential cmake pkg-config libcurl4-openssl-dev libssl-dev libjsoncpp-dev libsasl2-dev pandoc"
LIBS="git build-essential cmake pkg-config libcurl4-openssl-dev libssl-dev libjsoncpp-dev libsasl2-dev"
apt-get install -y --no-install-recommends ${LIBS}
do_build
build_pandoc
build_sasl2
apt-get remove --purge -y ${LIBS}
apt-get autoremove --yes
apt-get clean autoclean
Expand Down
4 changes: 2 additions & 2 deletions postfix-exporter-01.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/Dockerfile b/Dockerfile
index a3327d8..c082f5b 100644
index a3327d8..1e93cb8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,10 @@
Expand Down Expand Up @@ -29,7 +29,7 @@ index a3327d8..c082f5b 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 env GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$TARGETVARIANT go build -ldflags '-extldflags "-static"' -o /bin/postfix_exporter
+RUN env GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" GOARM="$( echo "$TARGETVARIANT" grep -E -o "\d+$")" go build -ldflags '-extldflags "-static"' -o /bin/postfix_exporter

-FROM debian:latest
+FROM scratch
Expand Down

0 comments on commit 19dd690

Please sign in to comment.