diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 000000000..fd57678cc --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,38 @@ +name: Build and push Docker image + +on: + push: + branches: main + +jobs: + build-n-push: + permissions: write-all + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - id: commit + uses: prompt/actions-commit-hash@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker Login + uses: docker/login-action@v3.0.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + build-args: | + AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" + AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" + SCCACHE_BUCKET="agicommies-subspace-cache" + SCCACHE_ENDPOINT="${{ vars.SCCACHE_ENDPOINT }}" + SCCACHE_REGION="auto" + push: true + tags: ghcr.io/agicommies/subspace:${{ steps.commit.outputs.short }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 02ef91097..68dbeafad 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,48 +1,63 @@ name: Check Set-Up & Build -# Controls when the action will run. on: - # Triggers the workflow on push or pull request events but only for the master branch push: branches: [main] pull_request: branches: [main] - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: check: - # The type of runner that the job will run on - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 - - name: Set-Up - run: sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler - - - name: Install Rustup + # Cache cargo's registry + - name: Rust registry cache + uses: Swatinem/rust-cache@v2 + with: + prefix-key: registry-main-cache + cache-targets: false + cache-on-failure: true + cache-all-crates: false + save-if: ${{ github.ref_name == 'main' }} + + - name: Install Rust run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - source ~/.cargo/env - rustup default stable - rustup update nightly - rustup update stable - rustup target add wasm32-unknown-unknown --toolchain nightly - - - name: Check Build + rustup set profile minimal + rustup show + + - name: Ensure the code is formatted + id: fmt + uses: actions-rs/cargo@v1 + continue-on-error: true + with: + command: fmt + args: -- --check + + - name: Install sccache + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + SCCACHE_BUCKET: "agicommies-subspace-cache" + SCCACHE_ENDPOINT: ${{ vars.SCCACHE_ENDPOINT }} + SCCACHE_REGION: auto run: | - SKIP_WASM_BUILD=1 cargo check --release + curl https://github.com/mozilla/sccache/releases/download/v0.7.6/sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz \ + -Lo sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz + tar -xzf sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz --strip-components=1 sccache-v0.7.6-x86_64-unknown-linux-musl/sccache + ./sccache --start-server + echo "RUSTC_WRAPPER=${{ github.workspace }}/sccache" >> "$GITHUB_ENV" + + - name: Ensure Clippy is happy + id: clippy + uses: actions-rs/clippy-check@v1 + continue-on-error: true + with: + args: --color=always --all-features --timings -- -D warnings + token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests run: | cargo test - - - name: Check Build for Benchmarking - run: > - pushd node && - cargo check --features=runtime-benchmarks --release diff --git a/Dockerfile b/Dockerfile index 7b5a9a9d5..e678bc5b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,12 @@ WORKDIR /subspace # Disables any interactive prompts. ARG DEBIAN_FRONTEND=noninteractive +ARG AWS_ACCESS_KEY_ID +ARG AWS_SECRET_ACCESS_KEY +ARG SCCACHE_BUCKET +ARG SCCACHE_ENDPOINT +ENV SCCACHE_REGION=auto + COPY . . # Dependencies using during the build stage. @@ -24,7 +30,16 @@ ENV PATH=/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbi RUN curl https://sh.rustup.rs -sSf | \ sh -s -- -y --profile=minimal --default-toolchain=nightly-2024-02-01 -RUN cargo build -p node-subspace --release --locked +RUN if [ -n "$SCCACHE_BUCKET" ]; then \ + curl https://github.com/mozilla/sccache/releases/download/v0.7.6/sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz \ + -Lo sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz && \ + tar -xzf sccache-v0.7.6-x86_64-unknown-linux-musl.tar.gz --strip-components=1 \ + sccache-v0.7.6-x86_64-unknown-linux-musl/sccache && \ + ./sccache --start-server && \ + export RUSTC_WRAPPER="/subspace/sccache"; \ + fi && \ + cargo build -p node-subspace --release --locked && \ + ./sccache --show-stats FROM debian:12-slim diff --git a/pallets/subspace/rpc/runtime-api/src/lib.rs b/pallets/subspace/rpc/runtime-api/src/lib.rs index 02d01d700..17a43e6ce 100644 --- a/pallets/subspace/rpc/runtime-api/src/lib.rs +++ b/pallets/subspace/rpc/runtime-api/src/lib.rs @@ -10,7 +10,7 @@ use sp_runtime::{ }; use sp_arithmetic::per_things::Percent; -use parity_scale_codec::{ +use codec::{ Decode, Encode, };