diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7304c80 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +** +!agent/ +!agent/Cargo.toml +!agent/Cargo.lock +!agent/Dockerfile.release +!agent/src/ +!agent/src/** diff --git a/.gitea/workflows/release-agent.yml b/.gitea/workflows/release-agent.yml index 6b9e942..3eb9a20 100644 --- a/.gitea/workflows/release-agent.yml +++ b/.gitea/workflows/release-agent.yml @@ -15,9 +15,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 env: - CARGO_TERM_COLOR: always - RUST_TOOLCHAIN: "1.85.1" - CROSS_VERSION: "0.2.5" + BINFMT_IMAGE: "tonistiigi/binfmt:qemu-v10.2.3-68" steps: - name: Checkout tag @@ -40,7 +38,7 @@ jobs: exit 1 fi - - name: Prepare Rust and cross + - name: Prepare multi-architecture builder shell: bash run: | set -Eeuo pipefail @@ -50,29 +48,27 @@ jobs: exit 1 } done - if ! command -v rustup >/dev/null || ! command -v cargo >/dev/null; then - rustup_installer="$(mktemp "${RUNNER_TEMP:-/tmp}/rustup-init.XXXXXX")" - trap 'rm -f "$rustup_installer"' EXIT - curl --proto '=https' --tlsv1.2 --fail --silent --show-error \ - https://sh.rustup.rs \ - --output "$rustup_installer" - sh "$rustup_installer" -y --profile minimal --default-toolchain none - export PATH="${CARGO_HOME:-$HOME/.cargo}/bin:$PATH" - printf '%s\n' "${CARGO_HOME:-$HOME/.cargo}/bin" >> "$GITHUB_PATH" - fi - command -v rustup >/dev/null || { printf 'rustup installation failed\n' >&2; exit 1; } - command -v cargo >/dev/null || { printf 'cargo installation failed\n' >&2; exit 1; } - rustup toolchain install "$RUST_TOOLCHAIN" --profile minimal --no-self-update - rustup override set "$RUST_TOOLCHAIN" - cargo install cross --version "$CROSS_VERSION" --locked docker info >/dev/null + docker buildx version >/dev/null + docker run --privileged --rm "$BINFMT_IMAGE" --install arm64 + docker buildx inspect --bootstrap - name: Build static Linux binaries shell: bash run: | set -Eeuo pipefail - cross build --locked --release --manifest-path agent/Cargo.toml --target x86_64-unknown-linux-musl - cross build --locked --release --manifest-path agent/Cargo.toml --target aarch64-unknown-linux-musl + docker buildx build \ + --platform linux/amd64 \ + --file agent/Dockerfile.release \ + --target artifact \ + --output type=local,dest=build/linux-amd64 \ + . + docker buildx build \ + --platform linux/arm64 \ + --file agent/Dockerfile.release \ + --target artifact \ + --output type=local,dest=build/linux-arm64 \ + . - name: Package and verify assets shell: bash @@ -80,8 +76,8 @@ jobs: set -Eeuo pipefail ./scripts/package-agent-release.sh \ --output dist \ - --amd64 agent/target/x86_64-unknown-linux-musl/release/vps-agent \ - --arm64 agent/target/aarch64-unknown-linux-musl/release/vps-agent + --amd64 build/linux-amd64/vps-agent \ + --arm64 build/linux-arm64/vps-agent file dist/vps-agent-linux-amd64 dist/vps-agent-linux-arm64 grep -q 'statically linked' < <(file -b dist/vps-agent-linux-amd64) grep -q 'statically linked' < <(file -b dist/vps-agent-linux-arm64) diff --git a/agent/Cargo.lock b/agent/Cargo.lock index 4fb652f..042b76a 100644 --- a/agent/Cargo.lock +++ b/agent/Cargo.lock @@ -1095,7 +1095,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vps-agent" -version = "0.1.0" +version = "0.1.4" dependencies = [ "anyhow", "axum", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index c7d631c..fc8c4cd 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vps-agent" -version = "0.1.4" +version = "0.1.5" edition = "2021" rust-version = "1.80" license = "Apache-2.0" diff --git a/agent/Dockerfile.release b/agent/Dockerfile.release new file mode 100644 index 0000000..30ea1c8 --- /dev/null +++ b/agent/Dockerfile.release @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1.7 +FROM --platform=$TARGETPLATFORM rust:1.85.1-alpine3.21 AS build + +RUN apk add --no-cache musl-dev +WORKDIR /src + +COPY agent/Cargo.toml agent/Cargo.lock ./ +COPY agent/src ./src + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/src/target \ + cargo build --locked --release && \ + install -D -m 0755 /src/target/release/vps-agent /out/vps-agent + +FROM scratch AS artifact +COPY --from=build /out/vps-agent /vps-agent diff --git a/docs/gitea-release.md b/docs/gitea-release.md index 6d7ab2c..493675d 100644 --- a/docs/gitea-release.md +++ b/docs/gitea-release.md @@ -12,14 +12,16 @@ Register an amd64 Gitea Actions runner whose `ubuntu-latest` label resolves to a Linux environment with: - `bash`, `curl`, `jq`, `file`, `sha256sum`, Git, and CA certificates; -- Docker with permission for the runner user to access its daemon; -- outbound access to the Rust registries and the container registry used by - `cross`. +- Docker with Buildx and permission for the runner user to access its daemon; +- permission to start the pinned `tonistiigi/binfmt` helper as privileged so it + can register the arm64 emulator; +- outbound access to Docker Hub and the Rust package registry. -When Rustup or Cargo is absent, the job bootstraps Rustup using its official TLS -installer. It then installs the pinned Rust 1.85.1 toolchain and `cross` 0.2.5. -`cross` uses Docker to build both musl targets; no amd64 or arm64 build host is -required. Do not expose the Docker daemon over an unauthenticated TCP socket. +Rust and Cargo are not required on the runner. Buildx runs the pinned official +`rust:1.85.1-alpine3.21` image natively for amd64 and through QEMU for arm64. +Both resulting binaries are statically linked against musl. No amd64 or arm64 +build host is required. Do not expose the Docker daemon over an unauthenticated +TCP socket. The simplest setup is a dedicated runner VM with an `ubuntu-latest:host` label. If jobs run inside a container instead, that container needs the Docker CLI and