1
0
Fork 0
mirror of https://github.com/imjasonh/krust synced 2026-07-08 06:45:32 +00:00
krust/.github/workflows/ci.yml
Jason Hall 1f730645c3
feat: Expand platform support to match Alpine's supported architectures
- Add support for linux/386 (i686-unknown-linux-musl)
- Add support for linux/arm/v6 (arm-unknown-linux-musleabihf)
- Add support for linux/ppc64le (powerpc64le-unknown-linux-musl)
- Add support for linux/s390x (s390x-unknown-linux-musl)
- Add support for linux/riscv64 (riscv64gc-unknown-linux-musl)
- Update platform detection to include all new platforms
- Add tests for all new platform mappings
- Update documentation with installation instructions for all targets
- Add CI job to test extended platform support
- Update development setup docs to mention cargo-zigbuild for full platform support

This allows krust to build images for all platforms supported by Alpine Linux,
making it more versatile for multi-architecture container deployments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-08 00:07:56 -04:00

241 lines
7.6 KiB
YAML

name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "--cfg ci"
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm]
rust: [stable, beta]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: x86_64-unknown-linux-musl,aarch64-unknown-linux-musl
- name: Install cross-compilation tools for both architectures
run: |
sudo apt-get update
sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu gcc-x86-64-linux-gnu
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Setup cargo config for cross-compilation
run: |
mkdir -p .cargo
cat > .cargo/config.toml << 'EOF'
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
EOF
- name: Verify cross-compilation setup (Unix)
run: |
echo "Installed targets:"
rustup target list --installed
echo "Cargo version:"
cargo --version
echo "Rustc version:"
rustc --version
echo "Available linkers:"
which x86_64-unknown-linux-musl-gcc || echo "x86_64-unknown-linux-musl-gcc not found"
which x86_64-linux-musl-gcc || echo "x86_64-linux-musl-gcc not found"
which musl-gcc || echo "musl-gcc not found"
which aarch64-linux-gnu-gcc || echo "aarch64-linux-gnu-gcc not found"
which rust-lld || echo "rust-lld not found"
echo "Cargo config:"
cat .cargo/config.toml || echo "No cargo config found"
- name: Build
run: cargo build --verbose
- name: Run unit tests
run: cargo test --verbose
- name: Run e2e tests
run: cargo test --test '*' --verbose
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Check formatting
run: cargo fmt -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Run clippy
run: cargo clippy -- -D warnings
integration:
name: Integration Test
runs-on: ubuntu-latest
needs: [test, fmt, clippy] # Only run after other tests pass
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl,aarch64-unknown-linux-musl
- name: Install musl tools
run: |
sudo apt-get update
sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu
- name: Setup cargo config for cross-compilation
run: |
mkdir -p .cargo
cat > .cargo/config.toml << 'EOF'
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
EOF
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build krust
run: cargo build --release
- name: Add krust to PATH
run: echo "${{ github.workspace }}/target/release" >> $GITHUB_PATH
- name: Test krust version
run: krust version
- name: Build and run example with krust
run: |
cd example/hello-krust
# Build and push to ttl.sh (ephemeral registry)
export KRUST_REPO=ttl.sh/${{ github.run_id }}
IMAGE_REF=$(krust build ./)
echo "Built image: $IMAGE_REF"
# Run the image
docker run --rm $IMAGE_REF
- name: Test docker run with command substitution
run: |
cd example/hello-krust
export KRUST_REPO=ttl.sh/${{ github.run_id }}-test2
docker run --rm $(krust build ./)
- name: Test build with --no-push
run: |
cd example/hello-krust
krust build --no-push --image local.test/hello:latest ./
- name: Test multi-arch build and run
run: |
cd example/hello-krust
# Build for both platforms and push
export KRUST_REPO=ttl.sh/${{ github.run_id }}-multiarch
IMAGE_REF=$(krust build --platform linux/amd64,linux/arm64 ./)
echo "Built multi-arch image: $IMAGE_REF"
# Run the image - should automatically select the right architecture
docker run --rm $IMAGE_REF
# Test extended platform support
extended-platforms:
name: Extended Platform Support
runs-on: ubuntu-latest
needs: [test] # Only run after basic tests pass
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl,i686-unknown-linux-musl,aarch64-unknown-linux-musl,armv7-unknown-linux-musleabihf
- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y musl-tools gcc-multilib
- name: Setup cargo config
run: |
mkdir -p .cargo
cat > .cargo/config.toml << 'EOF'
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
[target.i686-unknown-linux-musl]
linker = "musl-gcc"
rustflags = ["-C", "target-cpu=i686"]
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
EOF
- name: Build krust
run: cargo build --release
- name: Test multi-platform build with Alpine base
run: |
# Create a test project that uses Alpine (which supports many platforms)
mkdir -p test-alpine-platforms/src
cat > test-alpine-platforms/Cargo.toml << 'EOF'
[package]
name = "test-alpine"
version = "0.1.0"
edition = "2021"
[package.metadata.krust]
base-image = "alpine:latest"
EOF
cat > test-alpine-platforms/src/main.rs << 'EOF'
fn main() {
println!("Hello from Alpine multi-platform test!");
}
EOF
# Test that platform detection works (even if we can't build all platforms)
cd test-alpine-platforms
../target/release/krust build --no-push --image test.local/alpine-test:latest . 2>&1 | tee build.log
# Verify platform detection happened
grep -q "Detecting available platforms from base image: alpine:latest" build.log
grep -q "Found platforms:" build.log
# Takes too long to run on CI, so it's commented out for now.
# coverage:
# name: Code coverage
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Install Rust
# uses: dtolnay/rust-toolchain@stable
# - name: Install cargo-tarpaulin
# run: cargo install cargo-tarpaulin
# - name: Generate code coverage
# run: cargo tarpaulin --verbose --workspace