-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build relases on gh-actions & support linux arm64 (#2629)
* feat: port zola release build to gh actions & support linux arm64 Signed-off-by: Henrik Gerdes <[email protected]> * fix: add buildx support for multi-arch docker images Signed-off-by: Henrik Gerdes <[email protected]> * fix: pin gh release action to sha & allow pre-releases Signed-off-by: Henrik Gerdes <[email protected]> * fix: use env in gh action for linux arm build Signed-off-by: Henrik Gerdes <[email protected]> * chore: switch to dtolnay/rust-toolchain action for rust setup Signed-off-by: Henrik Gerdes <[email protected]> * fix: windows archive step Signed-off-by: Henrik Gerdes <[email protected]> --------- Signed-off-by: Henrik Gerdes <[email protected]>
- Loading branch information
Showing
5 changed files
with
248 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Build & Test | ||
|
||
on: | ||
push: | ||
branches: ["*"] | ||
|
||
env: | ||
# Cross-compilation for aarch64 requires a different linker | ||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
Tests: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
target: | ||
- x86_64-unknown-linux-gnu | ||
- aarch64-unknown-linux-gnu | ||
- x86_64-pc-windows-msvc | ||
- x86_64-apple-darwin | ||
- aarch64-apple-darwin | ||
rustup_toolchain: [stable] | ||
include: | ||
- os: windows-2022 | ||
target: x86_64-pc-windows-msvc | ||
- os: ubuntu-20.04 | ||
target: x86_64-unknown-linux-gnu | ||
- os: ubuntu-20.04 | ||
target: aarch64-unknown-linux-gnu | ||
- os: macos-13 | ||
target: x86_64-apple-darwin | ||
- os: macos-14 | ||
target: aarch64-apple-darwin | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ matrix.rustup_toolchain }} | ||
|
||
- name: Install Rust crosscompile tools | ||
if: ${{ contains(matrix.target, 'aarch64-unknown-linux-gnu') }} | ||
run: | | ||
sudo apt-get update -y | ||
sudo apt-get install -y make g++ libssl-dev gcc-aarch64-linux-gnu | ||
rustup target add aarch64-unknown-linux-gnu | ||
- name: Cargo build (Native TLS) | ||
run: | | ||
cargo build --all --no-default-features --features=native-tls | ||
cargo clean | ||
- name: Cargo build (Rust TLS) | ||
run: cargo build --all | ||
|
||
- name: Cargo test | ||
run: cargo test --all | ||
|
||
- name: Cargo fmt | ||
run: cargo fmt --check |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: ["v*.*.*"] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
# Cross-compilation for aarch64 requires a different linker | ||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
Release-Build: | ||
runs-on: ${{ matrix.os }} | ||
permissions: | ||
contents: read | ||
attestations: write | ||
id-token: write | ||
strategy: | ||
matrix: | ||
target: | ||
- x86_64-unknown-linux-gnu | ||
- aarch64-unknown-linux-gnu | ||
- x86_64-pc-windows-msvc | ||
- x86_64-apple-darwin | ||
- aarch64-apple-darwin | ||
rustup_toolchain: [stable] | ||
include: | ||
- os: windows-2022 | ||
target: x86_64-pc-windows-msvc | ||
- os: ubuntu-20.04 | ||
target: x86_64-unknown-linux-gnu | ||
- os: ubuntu-20.04 | ||
target: aarch64-unknown-linux-gnu | ||
- os: macos-13 | ||
target: x86_64-apple-darwin | ||
- os: macos-14 | ||
target: aarch64-apple-darwin | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ matrix.rustup_toolchain }} | ||
|
||
- name: Install Rust crosscompile tools | ||
if: ${{ contains(matrix.target, 'aarch64-unknown-linux-gnu') }} | ||
run: | | ||
sudo apt-get update -y | ||
sudo apt-get install -y make g++ libssl-dev gcc-aarch64-linux-gnu | ||
rustup target add aarch64-unknown-linux-gnu | ||
- name: Cargo build | ||
run: cargo build --release --target ${{ matrix.target }} | ||
|
||
- name: Archive (UNIX) | ||
run: | | ||
mkdir -p artifacts | ||
cp -av target/${{ matrix.target }}/release/zola . | ||
tar -czf ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz zola | ||
if: ${{ ! startsWith(matrix.os, 'windows') }} | ||
|
||
- name: Archive (Windows) | ||
run: | | ||
mkdir -p artifacts | ||
cp target/${{ matrix.target }}/release/zola.exe . | ||
Compress-Archive zola.exe ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.target }}.zip | ||
if: ${{ startsWith(matrix.os, 'windows') }} | ||
|
||
- name: Attest Build Provenance | ||
uses: actions/attest-build-provenance@v1 | ||
continue-on-error: true | ||
with: | ||
subject-path: ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.target }}.* | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.target }} | ||
path: ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.target }}.* | ||
if-no-files-found: error | ||
retention-days: 7 | ||
|
||
Release: | ||
needs: [Release-Build] | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Ensure artifacts dir exists | ||
run: mkdir -p artifacts | ||
|
||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: artifacts | ||
merge-multiple: true | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 | ||
with: | ||
name: ${{ github.ref_name }} | ||
tag_name: ${{ github.ref_name }} | ||
generate_release_notes: true | ||
fail_on_unmatched_files: true | ||
body: | | ||
Welcome to this new release of Zola ${{ github.ref_name }}! | ||
All artifacts are signed with this repos identity using Sigstore. | ||
You can verify the signatures using the `GitHub` CLI. | ||
```shell | ||
gh attestation verify --owner ${{ github.repository_owner }} <my-artifact> | ||
``` | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
prerelease: ${{ contains(github.ref, '-pre') }} | ||
files: artifacts/* | ||
|
||
Release-Container-Image: | ||
needs: [Release] | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
flavor: latest=false | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
push: true | ||
build-args: | | ||
USE_GH_RELEASE=true | ||
ZOLA_RELEASE_VERSION=${{ github.ref_name }} | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
FROM rust:slim-bookworm AS builder | ||
|
||
ARG USE_GH_RELEASE=false | ||
ARG ZOLA_RELEASE_VERSION=latest | ||
RUN apt-get update -y && \ | ||
apt-get install -y make g++ libssl-dev && \ | ||
rustup target add x86_64-unknown-linux-gnu | ||
apt-get install -y pkg-config make g++ libssl-dev curl jq tar gzip | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
RUN cargo build --release --target x86_64-unknown-linux-gnu | ||
|
||
RUN if [ "${USE_GH_RELEASE}" = "true" ]; then \ | ||
if [ "${ZOLA_RELEASE_VERSION}" = "latest" ]; then \ | ||
export ZOLA_VERSION=$(curl -sL https://api.github.com/repos/getzola/zola/releases/latest | jq -r .name); \ | ||
else \ | ||
export ZOLA_VERSION="${ZOLA_RELEASE_VERSION}"; \ | ||
fi && \ | ||
curl -sL --fail --output zola.tar.gz https://github.com/getzola/zola/releases/download/${ZOLA_VERSION}/zola-${ZOLA_VERSION}-$(uname -m)-unknown-linux-gnu.tar.gz && \ | ||
tar -xzvf zola.tar.gz zola; \ | ||
else \ | ||
cargo build --release && \ | ||
cp target/$(uname -m)-unknown-linux-gnu/release/zola zola; \ | ||
fi && ./zola --version | ||
|
||
FROM gcr.io/distroless/cc-debian12 | ||
COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/zola /bin/zola | ||
COPY --from=builder /app/zola /bin/zola | ||
ENTRYPOINT [ "/bin/zola" ] |