Skip to content

Commit

Permalink
CI: combine cross with docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Sep 30, 2023
1 parent 6d31624 commit 0d0fc4c
Showing 1 changed file with 29 additions and 45 deletions.
74 changes: 29 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,6 @@ jobs:
name: build-${{ matrix.target }}
path: target_releases/*

cross-build:
name: Cross-build for other platforms
runs-on: ubuntu-latest
env:
TARGETS: "aarch64-unknown-linux-musl x86_64-unknown-linux-musl"
# TODO: aarch64-unknown-linux-gnu
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Install cross
run: |
cargo install cross
# Install latest cross version from git (disabled as it is probably less stable)
# cargo install cross --git https://github.com/cross-rs/cross
cross --version
- name: Build targets
run: |
for target in $TARGETS; do
echo -e "\n----------------------------------------------"
echo "Building $target"
export "CARGO_TARGET_$(echo $target | tr 'a-z-' 'A-Z_')_RUSTFLAGS"='-C strip=debuginfo'
cross build --release --target $target --package martin-mbtiles
cross build --release --target $target --package martin --features=vendored-openssl
mkdir -p target_releases/$target
mv target/$target/release/mbtiles target_releases/$target
mv target/$target/release/martin target_releases/$target
done
- name: Save build artifacts to build-${{ matrix.target }}
uses: actions/upload-artifact@v3
with:
name: cross-build
path: target_releases/*

test:
name: Test ${{ matrix.target }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -336,7 +300,7 @@ jobs:
retention-days: 5

docker:
name: Build docker images
name: Build and test docker images
runs-on: ubuntu-latest
needs: [ cross-build ]
env:
Expand All @@ -345,6 +309,8 @@ jobs:
PGHOST: localhost
PGUSER: postgres
PGPASSWORD: postgres
TARGETS: "aarch64-unknown-linux-musl x86_64-unknown-linux-musl"
# TODO: aarch64-unknown-linux-gnu
services:
postgres:
image: postgis/postgis:15-3.3
Expand All @@ -371,6 +337,12 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Install cross
run: |
cargo install cross
# Install latest cross version from git (disabled as it is probably less stable)
# cargo install cross --git https://github.com/cross-rs/cross
cross --version
- name: Setup database
run: tests/fixtures/initdb.sh
env:
Expand All @@ -388,20 +360,32 @@ jobs:
install: true
platforms: linux/amd64,linux/arm64

- run: rm -rf target_releases2
- name: Download cross-build artifacts
uses: actions/download-artifact@v3
- name: Build targets
run: |
for target in $TARGETS; do
echo -e "\n----------------------------------------------"
echo "Building $target"
export "CARGO_TARGET_$(echo $target | tr 'a-z-' 'A-Z_')_RUSTFLAGS"='-C strip=debuginfo'
cross build --release --target $target --package martin-mbtiles
cross build --release --target $target --package martin --features=vendored-openssl
mkdir -p target_releases/$target
mv target/$target/release/mbtiles target_releases/$target
mv target/$target/release/martin target_releases/$target
done
- name: Save build artifacts to build-${{ matrix.target }}
uses: actions/upload-artifact@v3
with:
name: cross-build
path: target_releases_tmp
- name: Reorganize build artifacts
path: target_releases/*
- name: Reorganize artifacts for docker build
run: |
chmod -R +x target_releases_tmp/
mkdir -p target_releases/linux/arm64
mv target_releases_tmp/aarch64-unknown-linux-musl/* target_releases/linux/arm64/
mkdir -p target_releases/linux/amd64
mv target_releases_tmp/x86_64-unknown-linux-musl/* target_releases/linux/amd64/
rm -rf target_releases_tmp
- name: Build linux/arm64 Docker image
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -474,7 +458,7 @@ jobs:
package:
name: Package ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs: [ test, test-legacy, docker, cross-build ]
needs: [ test, test-legacy, docker ]
strategy:
fail-fast: true
matrix:
Expand Down

0 comments on commit 0d0fc4c

Please sign in to comment.