From 464bbe049f04a082d092c99bdd0bbe85528a2b34 Mon Sep 17 00:00:00 2001 From: Sergii Mikhtoniuk Date: Thu, 8 Feb 2024 11:53:03 -0800 Subject: [PATCH] wip --- .github/workflows/release.yaml | 6 ++- .github/workflows/test.yaml | 80 ++++++++++++++++++++++++++++++++++ .github/workflows/test2.yaml | 42 ++++++++++++++++++ Makefile | 5 ++- 4 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 .github/workflows/test2.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6f976b7..b700c26 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,8 +11,10 @@ jobs: include: - runs-on: ubuntu-latest target: x86_64-unknown-linux-musl - # - runs-on: macos-14 - # target: aarch64-apple-darwin + image-arch: linux/amd64 + - runs-on: macos-14 + target: aarch64-apple-darwin + image-arch: linux/arm/v8 name: Build runs-on: ${{ matrix.runs-on }} steps: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..5ad2784 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,80 @@ +name: test_macos +on: + workflow_dispatch: {} +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - runs-on: ubuntu-latest + target: x86_64-unknown-linux-musl + image-platform: linux/amd64 + + - runs-on: ubuntu-latest + target: aarch64-unknown-linux-musl + image-platform: linux/arm/v8 + + # Cross-compiles from Intel Mac to arm64 + # We can compile natively for arm64 using macos-14 runner, + # but M1 processors of macos-14 runner don't support docker. + # See: https://github.com/marketplace/actions/setup-docker-on-macos#arm64-processors-m1-m2-m3-series-used-on-macos-14-images-are-unsupported + # See: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources + - runs-on: macos-12 + target: aarch64-apple-darwin + image-platform: linux/arm/v8 + name: Build + runs-on: ${{ matrix.runs-on }} + steps: + - name: Setup variables + run: | + TAG=v0.0.0 + VERSION=${TAG#v} + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "IMAGE=ghcr.io/kamu-data/engine-datafusion:$VERSION" >> $GITHUB_ENV + + - name: Install docker (macOS) + if: contains(matrix.runs-on, 'macos-') + # See: https://blog.netnerds.net/2022/11/docker-macos-github-actions/ + run: | + brew install docker docker-buildx + + mkdir -p ~/.docker/cli-plugins + ln -sfn /usr/local/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx + + colima start + + - name: Install musl (linux) + if: contains(matrix.target, '-musl') + # See: https://blog.urth.org/2023/03/05/cross-compiling-rust-projects-in-github-actions/ + run: | + sudo apt-get update --yes + sudo apt-get install --yes musl-tools + + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@v1 + with: + target: ${{ matrix.target }} + override: true + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build binary + run: | + # cargo build --release --target ${{ matrix.target }} + + - name: Build image + run: | + docker buildx build \ + --platform ${{ matrix.image-platform }} \ + --build-arg target_arch=${{ matrix.target }} \ + --build-arg version=${{ env.VERSION }} \ + -t ${{ env.IMAGE }} \ + -f image/Dockerfile \ + . diff --git a/.github/workflows/test2.yaml b/.github/workflows/test2.yaml new file mode 100644 index 0000000..a8a24d9 --- /dev/null +++ b/.github/workflows/test2.yaml @@ -0,0 +1,42 @@ +name: test_macos2 +on: + push: {} +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - runs-on: ubuntu-latest + target: x86_64-unknown-linux-musl + image-platform: linux/amd64 + - runs-on: ubuntu-latest + target: aarch64-unknown-linux-musl + image-platform: linux/arm/v8 + name: Build + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@v1 + with: + target: ${{ matrix.target }} + override: true + + - name: Install cross + run: cargo install cross --locked + + - name: Build binary + run: | + make build TARGET_ARCH=${{ matrix.target }} + + - name: Build image + run: | + make image PLATFORM=${{ matrix.image-platform }} TARGET_ARCH=${{ matrix.target }} + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 63cf526..feb422a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +PLATFORM = linux/amd64 TARGET_ARCH = x86_64-unknown-linux-musl ENGINE_VERSION = $(shell cargo metadata --format-version 1 | jq -r '.packages[] | select( .name == "kamu-engine-datafusion") | .version') ENGINE_IMAGE_TAG = $(ENGINE_VERSION) @@ -27,15 +28,15 @@ test: # Build ############################################################################### -# Do not use except for local testing - release images are built via CI .PHONY: build build: RUSTFLAGS="" cross build --release --target $(TARGET_ARCH) .PHONY: image -image: build +image: docker build \ + --platform $(PLATFORM) \ --build-arg target_arch=$(TARGET_ARCH) \ --build-arg version=$(ENGINE_VERSION) \ -t $(ENGINE_IMAGE) \