diff --git a/.github/workflows/build.yaml b/.github/workflows/action-build.yaml similarity index 80% rename from .github/workflows/build.yaml rename to .github/workflows/action-build.yaml index 753948ec..ade15f9e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/action-build.yaml @@ -21,31 +21,30 @@ jobs: ARCH: ${{ matrix.config.arch }} steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 + - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - workspaces: | - "containerd-shim-* -> target" + cache-key: rust-cache-${{ matrix.config.os }}-${{ matrix.config.arch}} - name: Setup build env run: | make setup - - name: build spin shim + - name: Build spin shim run: | VERBOSE=1 make build - - name: unit tests spin shim + - name: Run unit tests spin shim run: | VERBOSE=1 make unit-tests - - name: lowercase the runner OS name + - name: Lowercase the runner OS name shell: bash run: | OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]') echo "RUNNER_OS=$OS" >> $GITHUB_ENV - - name: package release assets + - name: Package release assets run: | mkdir _dist cp target/${{ matrix.config.arch }}-unknown-linux-musl/release/containerd-shim-spin-v2 _dist/ cd _dist tar czf containerd-shim-spin-v2-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz containerd-shim-spin-v2 - - name: upload shim artifacts + - name: Upload shim artifacts uses: actions/upload-artifact@v4 with: name: containerd-shim-spin-v2-${{ env.RUNNER_OS }}-${{ matrix.config.arch }} diff --git a/.github/workflows/action-check.yml b/.github/workflows/action-check.yml new file mode 100644 index 00000000..8ee3bb5f --- /dev/null +++ b/.github/workflows/action-check.yml @@ -0,0 +1,25 @@ +name: Run Check + +on: + workflow_call: +env: + CARGO_TERM_COLOR: always + +jobs: + check: + name: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt, clippy + - name: Install nightly rustfmt + run: + rustup toolchain install nightly --component rustfmt + - name: Setup build env + run: | + make setup + - name: Run fmt + run: | + make fmt \ No newline at end of file diff --git a/.github/workflows/docker-build-push.yaml b/.github/workflows/action-docker-build-push.yaml similarity index 91% rename from .github/workflows/docker-build-push.yaml rename to .github/workflows/action-docker-build-push.yaml index 05dfd552..1d911d5e 100644 --- a/.github/workflows/docker-build-push.yaml +++ b/.github/workflows/action-docker-build-push.yaml @@ -6,6 +6,7 @@ on: description: 'Is this a test run?' type: boolean required: true + jobs: build_and_push: permissions: @@ -32,21 +33,21 @@ jobs: echo "RUNNER_OS=$OS" >> $GITHUB_ENV - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: setup buildx + - name: Setup buildx uses: docker/setup-buildx-action@v3 - - name: login to GitHub container registry + - name: Login to GitHub container registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: enable containerd image store + - name: Enable containerd image store run: | echo '{ "features": { "containerd-snapshotter": true } }' | sudo tee /etc/docker/daemon.json sudo systemctl restart docker - - name: test + - name: Build and load (test run) uses: docker/build-push-action@v5 if: ${{ inputs.test }} with: @@ -54,7 +55,7 @@ jobs: load: true tags: containerd-shim-spin/${{ matrix.image.imageName }}:test platforms: wasi/wasm - - name: build and push + - name: Build and push uses: docker/build-push-action@v5 if: ${{ !inputs.test }} with: diff --git a/.github/workflows/node-installer.yaml b/.github/workflows/action-node-installer.yaml similarity index 90% rename from .github/workflows/node-installer.yaml rename to .github/workflows/action-node-installer.yaml index dbc7c0c2..9d603eee 100644 --- a/.github/workflows/node-installer.yaml +++ b/.github/workflows/action-node-installer.yaml @@ -35,10 +35,10 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: setup buildx + - name: Setup buildx uses: docker/setup-buildx-action@v3 - - name: login to GitHub container registry + - name: Login to GitHub container registry uses: docker/login-action@v3 with: registry: ghcr.io @@ -47,14 +47,14 @@ jobs: # Build and push node-installer image # TODO: remove once https://github.com/spinkube/runtime-class-manager handles this - - name: untar musl artifacts into ./node-installer/.tmp/linux/(amd64|arm64) dir + - name: Extract musl artifacts into ./node-installer/.tmp/linux/(amd64|arm64) dir run: | mkdir -p ./node-installer/.tmp/linux/amd64 mkdir -p ./node-installer/.tmp/linux/arm64 for f in ./_artifacts/*/*-x86_64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/amd64; done for f in ./_artifacts/*/*-aarch64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/arm64; done - - name: build and push node-installer image + - name: Build and push node-installer image uses: docker/build-push-action@v5 with: push: true @@ -63,7 +63,7 @@ jobs: context: node-installer platforms: linux/amd64,linux/arm64 - - name: clear + - name: Clear if: always() run: | rm -f ${HOME}/.docker/config.json diff --git a/.github/workflows/action-test.yml b/.github/workflows/action-test.yml new file mode 100644 index 00000000..4526ac80 --- /dev/null +++ b/.github/workflows/action-test.yml @@ -0,0 +1,54 @@ +name: Run Check + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + env: + ARCH: x86_64 + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + - uses: azure/setup-kubectl@v4 + - uses: fermyon/actions/spin/setup@v1 + with: + version: "v2.7.0" + + - name: Setup build env + run: | + make setup + + - name: Extract containerd-shim-spin-linux-${{ env.ARCH }} + run: | + mkdir -p ./bin + for f in containerd-shim-spin-*-linux-${{ env.ARCH }}/containerd-shim-spin-*-linux-${{ env.ARCH }}.tar.gz + do tar -xzf "$f" -C ./bin + done + + - name: Install k3d + run: make install-k3d + + - name: Run integration tests + run: BIN_DIR="./bin" IS_CI=true make integration-tests + + - name: Collect debug logs + if: failure() + run: make tests/collect-debug-logs + + - name: Upload debug logs + if: failure() + uses: actions/upload-artifact@v4 + with: + name: debug-logs + path: debug-logs/ + retention-days: 5 + + - name: Output runner storage on failure + if: failure() + run: df -h + + - name: Clean up k3d + if: always() + run: make tests/clean diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ac37eb2d..8c504855 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,29 +12,16 @@ env: CARGO_TERM_COLOR: always jobs: rustfmt: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 - with: - workspaces: | - "containerd-shim-* -> target" - - run: - rustup toolchain install nightly --component rustfmt - - name: Setup build env - run: | - make setup - - name: fmt - run: | - make fmt + uses: ./.github/workflows/action-check.yml + build: + uses: ./.github/workflows/action-build.yaml build-wasm-images: - uses: ./.github/workflows/docker-build-push.yaml + uses: ./.github/workflows/action-docker-build-push.yaml + needs: build with: test: true - build: - uses: ./.github/workflows/build.yaml publish-node-installer-image: - uses: ./.github/workflows/node-installer.yaml + uses: ./.github/workflows/action-node-installer.yaml needs: build # This action requires use of the GITHUB_TOKEN to publish the image # By default, PRs from forks don't have access, so we only run when the PR branch is on origin. @@ -43,48 +30,4 @@ jobs: ref: ${{ github.ref }} test: needs: build - runs-on: ubuntu-latest - env: - ARCH: x86_64 - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - - uses: azure/setup-kubectl@v4 - - uses: fermyon/actions/spin/setup@v1 - with: - version: "v2.7.0" - - - name: Setup build env - run: | - make setup - - - name: Extract containerd-shim-spin-linux-${{ env.ARCH }} - run: | - mkdir -p ./bin - for f in containerd-shim-spin-*-linux-${{ env.ARCH }}/containerd-shim-spin-*-linux-${{ env.ARCH }}.tar.gz - do tar -xzf "$f" -C ./bin - done - - - name: install k3d - run: make install-k3d - - - name: run integration tests - run: BIN_DIR="./bin" IS_CI=true make integration-tests - - - name: run collect debug logs - if: failure() - run: make tests/collect-debug-logs - - - name: upload debug logs - if: failure() - uses: actions/upload-artifact@v4 - with: - name: debug-logs - path: debug-logs/ - retention-days: 5 - - name: Output runner storage on failure - if: failure() - run: df -h - - name: clean up k3d - if: always() - run: make tests/clean + uses: ./.github/workflows/action-test.yml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b3accd8d..79f27f52 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,15 +7,15 @@ on: - "v[0-9]+.[0-9]+.*" jobs: build: - uses: ./.github/workflows/build.yaml + uses: ./.github/workflows/action-build.yaml build-and-push-wasm-images: - uses: ./.github/workflows/docker-build-push.yaml + uses: ./.github/workflows/action-docker-build-push.yaml with: test: false publish-node-installer-image: - uses: ./.github/workflows/node-installer.yaml + uses: ./.github/workflows/action-node-installer.yaml needs: build with: ref: ${{ github.ref }} @@ -41,14 +41,14 @@ jobs: with: path: _artifacts - - name: copy release workload assets into _dist + - name: Copy release workload assets into _dist if: startsWith(github.ref, 'refs/tags/v') run: | mkdir -p _dist cp ./deployments/workloads/runtime.yaml _dist/runtime.yaml cp ./deployments/workloads/workload.yaml _dist/workload.yaml - - name: create release + - name: Create release if: startsWith(github.ref, 'refs/tags/v') env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -63,10 +63,10 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: setup buildx + - name: Setup buildx uses: docker/setup-buildx-action@v3 - - name: login to GitHub container registry + - name: Login to GitHub container registry uses: docker/login-action@v3 with: registry: ghcr.io @@ -74,14 +74,14 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} # Build and push k3d shim image - - name: untar musl artifacts into ./deployments/k3d/.tmp/linux/(amd64|arm64) dir + - name: Extract musl artifacts into ./deployments/k3d/.tmp/linux/(amd64|arm64) dir run: | mkdir -p ./deployments/k3d/.tmp/linux/amd64 mkdir -p ./deployments/k3d/.tmp/linux/arm64 for f in ./_artifacts/*/*-x86_64.tar.gz; do tar -xf $f --directory ./deployments/k3d/.tmp/linux/amd64; done for f in ./_artifacts/*/*-aarch64.tar.gz; do tar -xf $f --directory ./deployments/k3d/.tmp/linux/arm64; done - - name: build and push k3d shim image + - name: Build and push k3d shim image uses: docker/build-push-action@v5 with: push: true @@ -92,7 +92,7 @@ jobs: build-args: | STAGE=release - - name: clear + - name: Clear if: always() run: | rm -f ${HOME}/.docker/config.json