diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c9aeca02..826ea0687 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,7 @@ jobs: outputs: crate: ${{ steps.parse-ref.outputs.crate }} version: ${{ steps.parse-ref.outputs.version }} + runtime: ${{ steps.parse-ref.outputs.runtime }} steps: - uses: actions/checkout@v3 with: @@ -41,8 +42,11 @@ jobs: exit 1 fi + RUNTIME="$(cut -d- -f3 <<<"${CRATE}")" + echo "CRATE=${CRATE}" >> $GITHUB_OUTPUT echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + echo "RUNTIME=${RUNTIME}" >> $GITHUB_OUTPUT setVersion="$(./scripts/version.sh "${CRATE}")" if [ ! "${VERSION#v}" = "${setVersion}" ]; then @@ -55,26 +59,46 @@ jobs: - generate strategy: matrix: - os: ["ubuntu-20.04", "ubuntu-22.04"] - runs-on: ${{ matrix.os }} + arch: ["x86_64", "aarch64"] + runs-on: "ubuntu-22.04" steps: - - uses: Swatinem/rust-cache@v2 - with: - key: release-${{ needs.generate.outputs.crate }} - uses: actions/checkout@v3 - name: Setup build env run: ./scripts/setup-linux.sh - shell: bash - - name: Install rust - uses: actions-rust-lang/setup-rust-toolchain@v1 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + env: + RUST_CACHE_KEY_OS: rust-release-cache-${{ needs.generate.outputs.crate }}-${{ matrix.arch }} with: - cache: false + rustflags: '' #Disable. By default this action sets environment variable is set to -D warnings. We manage this in the Makefile + - name: Setup cross-rs + run: ./scripts/setup-cross.sh ${{ matrix.arch }}-unknown-linux-musl + - name: Setup build profile + shell: bash + run: echo "OPT_PROFILE=release" >> ${GITHUB_ENV} - name: Build - timeout-minutes: 5 - run: make build-$(cut -d- -f3 <<<"${{ needs.generate.outputs.crate }}") + timeout-minutes: 10 + run: make build-${{ needs.generate.outputs.runtime }} - name: Test - timeout-minutes: 5 - run: make test-$(cut -d- -f3 <<<"${{ needs.generate.outputs.crate }}") + if: ${{ matrix.arch == 'x86_64' }} + timeout-minutes: 10 + run: make test-${{ needs.generate.outputs.runtime }} + - name: Package artifacts + if: ${{ needs.generate.outputs.runtime != 'wasm' }} + shell: bash + run: | + make dist-${{ needs.generate.outputs.runtime }} + # Check if there's any files to archive as tar fails otherwise + if stat dist/bin/* >/dev/null 2>&1; then + tar -czf dist/containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}.tar.gz -C dist/bin . + else + tar -czf dist/containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}.tar.gz -T /dev/null + fi + - name: Upload artifacts + if: ${{ needs.generate.outputs.runtime != 'wasm' }} + uses: actions/upload-artifact@master + with: + name: containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }} + path: dist/containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}.tar.gz release: permissions: @@ -85,29 +109,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Setup buildx - run: docker buildx create --use - - name: build binaries - run: docker buildx bake --set *.cache-from=type=gha,scope=buildkit-release-${CRATE} --set *.cache-to=type=gha,scope=buildkit-release-${CRATE} tar-cross - env: - CRATE: ${{ needs.generate.outputs.crate }} - - name: upload binary as GitHub artifact - uses: actions/upload-artifact@v3 + - name: Download artifacts + if: ${{ needs.generate.outputs.runtime != 'wasm' }} + uses: actions/download-artifact@master with: - path: release/ - name: ${{ needs.generate.outputs.crate }}-${{ needs.generate.outputs.version }} + path: release - name: Create release run: | gh release create ${{ github.ref }} --generate-notes --prerelease - # skip upload if there are no files - if stat release/* >/dev/null 2>&1; then - for i in release/*; do - gh release upload ${RELEASE_NAME} $i - done - else - echo "No files to upload" - exit 0 - fi + env: + GH_TOKEN: ${{ github.token }} + RELEASE_NAME: ${{ needs.generate.outputs.crate }}/${{ needs.generate.outputs.version }} + - name: Upload release artifacts + if: ${{ needs.generate.outputs.runtime != 'wasm' }} + run: | + for i in release/*/*; do + gh release upload ${RELEASE_NAME} $i + done env: GH_TOKEN: ${{ github.token }} RELEASE_NAME: ${{ needs.generate.outputs.crate }}/${{ needs.generate.outputs.version }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 167e22180..000000000 --- a/Dockerfile +++ /dev/null @@ -1,74 +0,0 @@ -# syntax=docker/dockerfile:1 - -# Make sure to keep RUST_VERSION in sync with the version in rust-toolchain.toml -ARG BASE_IMAGE="bullseye" -ARG RUST_VERSION=1.72.0 -ARG XX_VERSION=1.2.1 -ARG CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" - -FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx -FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-${BASE_IMAGE} AS base -COPY --from=xx / / - -COPY ./scripts/dockerfile-utils.sh /usr/bin/dockerfile-utils - -# Install host dependencies -RUN dockerfile-utils install_host - -# See https://github.com/tonistiigi/xx/issues/108 -RUN sed -i -E 's/xx-clang --setup-target-triple/XX_VENDOR=\$vendor xx-clang --setup-target-triple/' $(which xx-cargo) && \ - sed -i -E 's/\$\(xx-info\)-/\$\(XX_VENDOR=\$vendor xx-info\)-/g' $(which xx-cargo) - -FROM base AS build -WORKDIR /src - -RUN --mount=type=bind,target=/src,rw,source=. \ - --mount=type=cache,target=/usr/local/cargo/git/db \ - --mount=type=cache,target=/usr/local/cargo/registry/cache \ - --mount=type=cache,target=/usr/local/cargo/registry/index \ - CARGO_NET_GIT_FETCH_WITH_CLI="true" \ - cargo fetch - -ARG TARGETPLATFORM - -RUN dockerfile-utils install_target - -ARG CRATE - -RUN --mount=type=bind,target=/src,rw,source=. \ - --mount=type=cache,target=/usr/local/cargo/git/db \ - --mount=type=cache,target=/usr/local/cargo/registry/cache \ - --mount=type=cache,target=/usr/local/cargo/registry/index \ - --mount=type=cache,target=/build,id=runwasi-cargo-build-cache-${CRATE}-${BASE_IMAGE}-${TARGETPLATFORM} < -# -# where step is one of `install_host`, `install_target` or `build_setup`. -# * install_host: installs build tools and other host environment dependencies (things that run in the host). -# * install_target: installs build dependencies like libraries (things that will run in the target). -# * build_setup: setup to customize the build process (mainly setting env-vars) -# -# This script choosses the correct recipe based on the linux distribution of the base image. -# Supported distributions are `debian` and `alpine`. - -dockerfile_utils_alpine() { - # recipes for alpine - - install_host() { - apk add g++ bash clang pkgconf git protoc jq - apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main rust-bindgen - } - - install_target() { - xx-apk add \ - gcc g++ musl-dev zlib-dev zlib-static \ - ncurses-dev ncurses-static libffi-dev \ - libseccomp-dev libseccomp-static - } - - setup_build() { - export WASMEDGE_DEP_STDCXX_LINK_TYPE="static" - export WASMEDGE_DEP_STDCXX_LIB_PATH="$(xx-info sysroot)usr/lib" - export WASMEDGE_RUST_BINDGEN_PATH="$(which bindgen)" - export LIBSECCOMP_LINK_TYPE="static" - export LIBSECCOMP_LIB_PATH="$(xx-info sysroot)usr/lib" - export RUSTFLAGS="-Cstrip=symbols -Clink-arg=-lgcc" - } - -} - -dockerfile_utils_debian() { - # recipes for debian - - install_host() { - apt-get update -y - apt-get install --no-install-recommends -y clang pkg-config dpkg-dev git jq - } - - install_target() { - xx-apt-get install -y \ - gcc g++ libc++6-dev zlib1g \ - libsystemd-dev libdbus-1-dev libseccomp-dev - } - - setup_build() { - export RUSTFLAGS="-Cstrip=symbols" - } - -} - -dockerfile_utils_$(xx-info vendor) -$1 diff --git a/scripts/setup-cross.sh b/scripts/setup-cross.sh index 65d975cfb..8d7f7bccf 100755 --- a/scripts/setup-cross.sh +++ b/scripts/setup-cross.sh @@ -1,7 +1,12 @@ #!/bin/bash cargo install cross --git https://github.com/cross-rs/cross -echo "CARGO=cross" >> ${GITHUB_ENV} -if [ ! -z "$1" ]; then - echo "TARGET=$1" >> ${GITHUB_ENV} -fi \ No newline at end of file +if [ ! -z "$CI" ]; then + + echo "CARGO=cross" >> ${GITHUB_ENV} + + if [ ! -z "$1" ]; then + echo "TARGET=$1" >> ${GITHUB_ENV} + fi + +fi