From ad42fe22e4a8cedb11c1370cc2e3647cc9e6ee89 Mon Sep 17 00:00:00 2001 From: Joshua Oladele Date: Wed, 3 Jul 2024 10:49:28 +0100 Subject: [PATCH] ci(repo): add job for publishing docker images This commit ensures we cross-build the docker images for linux's arm and amd platforms and publish them from our Github release workflow. --- .github/workflows/release.yaml | 107 +++++++++++++++++++++++++++---- docker/fuel-core-nats.Dockerfile | 1 - rust-toolchain.toml | 2 +- 3 files changed, 97 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 67b22c2..83524f5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,9 +1,6 @@ name: Release -on: - pull_request: - types: [closed] - branches: [main] +on: push jobs: build-artifacts: @@ -58,19 +55,107 @@ jobs: contents: read actions: write steps: - - uses: actions/checkout@v4.1.6 - - uses: actions/download-artifact@v4.1.7 + - name: Checkout Repository + uses: actions/checkout@v4.1.6 + + - name: Download Artifacts + uses: actions/download-artifact@v4.1.7 with: path: artifacts merge-multiple: true - - name: List artifacts + - name: List Artifacts run: ls -R artifacts - - uses: knope-dev/action@v2.1.0 + - name: Cache Artifacts + uses: actions/cache@v3 + with: + path: artifacts + key: ${{ runner.os }}-artifacts-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-artifacts- + + - name: Run Knope Action + uses: knope-dev/action@v2.1.0 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.REPO_TOKEN }} - - run: knope release + - name: Knope Release + run: knope release env: - GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} + github-token: ${{ secrets.REPO_TOKEN }} + + publish-crates: + needs: [release] + if: github.event_name == 'release' && github.event.action == 'published' + runs-on: buildjet-4vcpu-ubuntu-2204 + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Restore Artifacts Cache + uses: actions/cache@v3 + with: + path: artifacts + key: ${{ runner.os }}-artifacts-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-artifacts- + + - name: Install Rust Toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + targets: wasm32-unknown-unknown + + - name: Publish Crate + uses: FuelLabs/publish-crates@v1 + with: + publish-delay: 60000 + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + publish-docker-image: + runs-on: buildjet-4vcpu-ubuntu-2204 + permissions: + contents: read + actions: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ghcr.io/fuellabs/fuel-core-nats + tags: | + type=sha + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{raw}} + type=raw,value=sha-{{sha}}-{{date 'YYYYMMDDhhmmss'}} + flavor: | + latest=${{ github.ref == 'refs/heads/master' }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the ghcr.io registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.REPO_TOKEN }} + + - name: Build and push the image to ghcr.io + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/arm64 + file: docker/fuel-core-nats.Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=ghcr.io/fuellabs/fuel-core-nats-docker-build-cache:latest + cache-to: type=registry,ref=ghcr.io/fuellabs/fuel-core-nats-docker-build-cache:latest,mode=max diff --git a/docker/fuel-core-nats.Dockerfile b/docker/fuel-core-nats.Dockerfile index 6b12276..41ff2ff 100644 --- a/docker/fuel-core-nats.Dockerfile +++ b/docker/fuel-core-nats.Dockerfile @@ -7,7 +7,6 @@ RUN cargo install cargo-chef && rustup target add wasm32-unknown-unknown WORKDIR /build/ COPY --from=xx / / - # hadolint ignore=DL3008 RUN apt-get update && \ apt-get install -y --no-install-recommends \ diff --git a/rust-toolchain.toml b/rust-toolchain.toml index b1fc4c1..6e38545 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "1.78.0" components = ["rustfmt", "clippy", "rust-analyzer"] -targets = ["wasm32-unknown-unknown"] +targets = ["wasm32-unknown-unknown", "aarch64-unknown-linux-gnu"]