From 17779950cac79bd885928516b6396a97c55d29bf Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Mon, 28 Oct 2024 12:03:36 -0400 Subject: [PATCH] Re-testing multiarch build with glibc instead of musl --- .github/workflows/PRBuild.yml | 39 +++++---------------------- .github/workflows/Release.yml | 34 +++++++++--------------- .goreleaser.yaml | 50 ++++++++++++++++------------------- Dockerfile | 2 +- 4 files changed, 44 insertions(+), 81 deletions(-) diff --git a/.github/workflows/PRBuild.yml b/.github/workflows/PRBuild.yml index b944eb8..6a36f36 100644 --- a/.github/workflows/PRBuild.yml +++ b/.github/workflows/PRBuild.yml @@ -9,41 +9,27 @@ on: jobs: - build: + prbuild: runs-on: ubuntu-latest steps: - - name: Install musl and cross-compilation tools + - name: Install cross-compilation tools run: | sudo apt-get update - sudo apt-get install -y musl-tools musl musl-dev sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - sudo apt-get install -y gcc-x86-64-linux-gnu g++-x86-64-linux-gnu - sudo apt-get install -y qemu-user-static - sudo apt-get install -y binfmt-support - sudo update-binfmts --enable qemu-aarch64 - sudo update-binfmts --display qemu-aarch64 - sudo update-binfmts --enable qemu-arm - sudo update-binfmts --display qemu-arm - + - name: Set up Go 1.23 uses: actions/setup-go@v5 with: - go-version: 1.23 + go-version: stable - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - - name: Docker Login - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout uses: actions/checkout@v4 with: fetch-tags: 1 fetch-depth: 1 - + # Set environment variables required by GoReleaser - name: Set build environment variables run: | @@ -52,7 +38,6 @@ jobs: echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV echo "BUILD_USER=$(whoami)" >> $GITHUB_ENV echo "CGO_ENABLED=1" >> $GITHUB_ENV - echo "CC=musl-gcc" >> $GITHUB_ENV - name: Build with goreleaser uses: goreleaser/goreleaser-action@v6 @@ -61,14 +46,4 @@ jobs: with: version: '~> v2' args: build --clean --snapshot - id: goreleaser - - name: Verify binaries are static - run: | - for binary in dist/*amd64_v1/*; do - if file "$binary" | grep -q "statically linked"; then - echo "$binary is statically linked" - else - echo "$binary is not statically linked" - fi - done - \ No newline at end of file + id: goreleaser \ No newline at end of file diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 0e1905b..a906081 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -11,38 +11,24 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Install musl and cross-compilation tools + - name: Install cross-compilation tools run: | sudo apt-get update - sudo apt-get install -y musl-tools musl musl-dev - sudo apt-get install -y gcc-aarch64-linux-gnu - sudo apt-get install -y g++-aarch64-linux-gnu - sudo apt-get install -y gcc-x86-64-linux-gnu - sudo apt-get install -y g++-x86-64-linux-gnu - sudo apt-get install -y qemu-user-static - sudo apt-get install -y binfmt-support - sudo update-binfmts --enable qemu-aarch64 - sudo update-binfmts --display qemu-aarch64 - sudo update-binfmts --enable qemu-arm - sudo update-binfmts --display qemu-arm + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + - name: Set up Go 1.23 uses: actions/setup-go@v5 with: - go-version: 1.23 + go-version: stable - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: Docker Login - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout uses: actions/checkout@v4 with: fetch-tags: 1 fetch-depth: 1 - + # Set environment variables required by GoReleaser - name: Set build environment variables run: | @@ -50,7 +36,13 @@ jobs: echo "BUILD_HOST=$(hostname)" >> $GITHUB_ENV echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV echo "BUILD_USER=$(whoami)" >> $GITHUB_ENV - + echo "CGO_ENABLED=1" >> $GITHUB_ENV + - name: Docker Login + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Release with goreleaser uses: goreleaser/goreleaser-action@v6 env: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 63d8288..7c71be4 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,7 +1,3 @@ -# This is an example .goreleaser.yml file with some sensible defaults. -# Make sure to check the documentation at https://goreleaser.com -version: 2 - project_name: smd before: hooks: @@ -25,22 +21,22 @@ builds: -X main.GitState={{ .Env.GIT_STATE }} \ -X main.BuildHost={{ .Env.BUILD_HOST }} \ -X main.GoVersion={{ .Env.GO_VERSION }} \ - -X main.BuildUser={{ .Env.BUILD_USER }} \ - -extldflags '-static'" + -X main.BuildUser={{ .Env.BUILD_USER }} " goos: - linux - darwin goarch: - amd64 - arm64 - tags: - - musl env: - CGO_ENABLED=1 - asmflags: - - "GOARCH=arm64:CC=gcc-aarch64-linux-gnu" - - "GOARCH=amd64:CC=musl-gcc" - + - >- + CC={{- if eq .Os "linux" -}} + {{- if eq .Arch "amd64" -}}gcc{{- else -}}aarch64-linux-gnu-gcc{{- end -}} + {{- else if eq .Os "darwin" -}} + {{- if eq .Arch "amd64" -}}clang{{- else -}}clang -target arm64-apple-macos11{{- end -}} + {{- end }} + - id: smd-init main: ./cmd/smd-init/ binary: smd-init @@ -53,21 +49,22 @@ builds: -X main.GitState={{ .Env.GIT_STATE }} \ -X main.BuildHost={{ .Env.BUILD_HOST }} \ -X main.GoVersion={{ .Env.GO_VERSION }} \ - -X main.BuildUser={{ .Env.BUILD_USER }} \ - -extldflags '-static'" + -X main.BuildUser={{ .Env.BUILD_USER }} " goos: - linux - darwin goarch: - amd64 - arm64 - tags: - - musl env: - CGO_ENABLED=1 - asmflags: - - "GOARCH=arm64:CC=gcc-aarch64-linux-gnu" - - "GOARCH=amd64:CC=musl-gcc" + - >- + CC={{- if eq .Os "linux" -}} + {{- if eq .Arch "amd64" -}}gcc{{- else -}}aarch64-linux-gnu-gcc{{- end -}} + {{- else if eq .Os "darwin" -}} + {{- if eq .Arch "amd64" -}}clang{{- else -}}clang -target arm64-apple-macos11{{- end -}} + {{- end }} + - id: smd-loader main: ./cmd/smd-loader/ binary: smd-loader @@ -80,21 +77,21 @@ builds: -X main.GitState={{ .Env.GIT_STATE }} \ -X main.BuildHost={{ .Env.BUILD_HOST }} \ -X main.GoVersion={{ .Env.GO_VERSION }} \ - -X main.BuildUser={{ .Env.BUILD_USER }} \ - -extldflags '-static'" + -X main.BuildUser={{ .Env.BUILD_USER }} " goos: - linux - darwin goarch: - amd64 - arm64 - tags: - - musl env: - CGO_ENABLED=1 - asmflags: - - "GOARCH=arm64:CC=gcc-aarch64-linux-gnu" - - "GOARCH=amd64:CC=musl-gcc" + - >- + CC={{- if eq .Os "linux" -}} + {{- if eq .Arch "amd64" -}}gcc{{- else -}}aarch64-linux-gnu-gcc{{- end -}} + {{- else if eq .Os "darwin" -}} + {{- if eq .Arch "amd64" -}}clang{{- else -}}clang -target arm64-apple-macos11{{- end -}} + {{- end }} dockers: - image_templates: @@ -183,7 +180,6 @@ changelog: - '^docs:' - '^test:' - # The lines beneath this are called `modelines`. See `:help modeline` # Feel free to remove those if you don't want/use them. # yaml-language-server: $schema=https://goreleaser.com/static/schema.json diff --git a/Dockerfile b/Dockerfile index f9d1394..3d8bf9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.20 +FROM chainguard/wolfi-base:latest RUN apk add --no-cache tini