Skip to content

Setup Docker BuildX for cross-platform image building #113

Setup Docker BuildX for cross-platform image building

Setup Docker BuildX for cross-platform image building #113

Workflow file for this run

name: CI
on: [push, pull_request]
jobs:
linux_x86_64:
name: Linux (x86-64)
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update Rust
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Install MUSL Toolchain
run: rustup target add x86_64-unknown-linux-musl
- name: Install MUSL dependencies
run: sudo apt-get install musl-tools
- name: Enable Rust Caching
uses: Swatinem/rust-cache@v2
- name: Release Build
run: cargo build --release --all --target x86_64-unknown-linux-musl
- name: Execute Tests
run: cargo test --release --all --target x86_64-unknown-linux-musl
- name: Run Clippy
run: cargo clippy --release --all --target x86_64-unknown-linux-musl --all-targets --all-features --locked -- -D warnings
- name: Check Formatting
run: cargo fmt --all -- --check
- uses: actions/upload-artifact@v4
with:
name: linux-x86_64
path: target/x86_64-unknown-linux-musl/release/dmarc-report-viewer
linux_aarch64:
name: Linux (aarch64)
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update Rust
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Install Cargo Binary Install
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Install Cargo Cross
run: cargo binstall cross --no-confirm
- name: Enable Rust Caching
uses: Swatinem/rust-cache@v2
- name: Release Build
run: cross build --release --all --target aarch64-unknown-linux-musl
- name: Execute Tests
run: cross test --release --all --target aarch64-unknown-linux-musl
- uses: actions/upload-artifact@v4
with:
name: linux-aarch64
path: target/aarch64-unknown-linux-musl/release/dmarc-report-viewer
windows_x86_64:
name: Windows (x86-64)
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install NASM
uses: ilammy/setup-nasm@v1
- name: Update Rust
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Enable Rust Caching
uses: Swatinem/rust-cache@v2
- name: Release Build
run: cargo build --release --all
- name: Execute Tests
run: cargo test --release --all
- uses: actions/upload-artifact@v4
with:
name: windows-x86_64
path: target/release/dmarc-report-viewer.exe
mac_x86_64:
name: Mac (x86-64)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update Rust
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Install x64 target
run: rustup target add x86_64-apple-darwin
- name: Enable Rust Caching
uses: Swatinem/rust-cache@v2
- name: Release Build
run: cargo build --release --all --target x86_64-apple-darwin
- name: Execute Tests
run: cargo test --release --all --target x86_64-apple-darwin
- uses: actions/upload-artifact@v4
with:
name: mac-x86_64
path: target/x86_64-apple-darwin/release/dmarc-report-viewer
mac_aarch64:
name: Mac (aarch64)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update Rust
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Enable Rust Caching
uses: Swatinem/rust-cache@v2
- name: Release Build
run: cargo build --release --all --target aarch64-apple-darwin
- name: Execute Tests
run: cargo test --release --all --target aarch64-apple-darwin
- uses: actions/upload-artifact@v4
with:
name: mac-aarch64
path: target/aarch64-apple-darwin/release/dmarc-report-viewer
# docker_linux_x86_64:
# name: Docker (Linux, x86-64)
# runs-on: ubuntu-24.04
# permissions:
# contents: read
# packages: write
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Build Docker Image
# run: docker build . --build-arg GITHUB_SHA --build-arg GITHUB_REF_NAME --pull --tag dmarc-report-viewer
# - name: Test Docker Image
# run: docker run --rm dmarc-report-viewer ./dmarc-report-viewer --help
# - name: Publish Latest Docker Image
# if: ${{github.ref == 'refs/heads/master'}}
# run: |
# echo ${{secrets.GITHUB_TOKEN}} | docker login ghcr.io -u ${{github.actor}} --password-stdin
# docker tag dmarc-report-viewer ghcr.io/${{github.actor}}/dmarc-report-viewer:develop
# docker push ghcr.io/${{github.actor}}/dmarc-report-viewer:develop
# - name: Publish Tagged Docker Image
# if: startsWith(github.ref, 'refs/tags/')
# run: |
# echo ${{secrets.GITHUB_TOKEN}} | docker login ghcr.io -u ${{github.actor}} --password-stdin
# docker tag dmarc-report-viewer ghcr.io/${{github.actor}}/dmarc-report-viewer:latest
# docker push ghcr.io/${{github.actor}}/dmarc-report-viewer:latest
# docker tag dmarc-report-viewer ghcr.io/${{github.actor}}/dmarc-report-viewer:${{github.ref_name}}
# docker push ghcr.io/${{github.actor}}/dmarc-report-viewer:${{github.ref_name}}
# - name: Save Docker Image
# run: docker save -o dmarc-report-viewer.tar dmarc-report-viewer
# - uses: actions/upload-artifact@v4
# with:
# name: docker-linux-x86_64
# path: dmarc-report-viewer.tar
docker_linux:
name: Docker (Linux, x86-64, aarch64)
needs: [linux_x86_64, linux_aarch64]
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Copy Binary Artifacts
run: |
mv linux-x86_64 .github/docker/linux-amd64
mv linux-aarch64 .github/docker/linux-arm64
tree .github/
ls -la .github/docker/linux-amd64
ls -la .github/docker/linux-arm64
chmod +x .github/docker/linux-amd64/dmarc-report-viewer
chmod +x .github/docker/linux-arm64/dmarc-report-viewer
ls -la .github/docker/linux-amd64
ls -la .github/docker/linux-arm64
- name: Build Docker Images
run: |
cd .github/docker/
echo ${{secrets.GITHUB_TOKEN}} | docker login ghcr.io -u ${{github.actor}} --password-stdin
docker builder create --name builder --driver docker-container --bootstrap
docker buildx build --builder builder --platform=linux/amd64,linux/arm64 --push --build-arg GITHUB_SHA --build-arg GITHUB_REF_NAME --pull --tag ghcr.io/${{github.actor}}/dmarc-report-viewer:buildx .
- name: Test Docker Image
run: docker run --rm ghcr.io/${{github.actor}}/dmarc-report-viewer:buildx ./dmarc-report-viewer --help
release:
name: Release
if: startsWith(github.ref, 'refs/tags/')
needs: [linux_x86_64, linux_aarch64, windows_x86_64, mac_x86_64, mac_aarch64, docker_linux]
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Pack Artifacts for Release
run: |
zip -r windows-x86_64.zip windows-x86_64
zip -r linux-x86_64.zip linux-x86_64
zip -r linux-aarch64.zip linux-aarch64
zip -r mac-x86_64.zip mac-x86_64
zip -r mac-aarch64.zip mac-aarch64
- name: Publish Release
uses: softprops/action-gh-release@v2
with:
body: Release created automatically from git tag ${{github.ref_name}}, see CHANGELOG.md for more details.
files: |
CHANGELOG.md
LICENSE
windows-x86_64.zip
linux-x86_64.zip
linux-aarch64.zip
mac-x86_64.zip
mac-aarch64.zip