Skip to content

Commit

Permalink
feat: added sccache to workflow and dockerfile (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson committed Feb 9, 2024
1 parent d1e36c8 commit 5c97cde
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 29 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
81 changes: 54 additions & 27 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,75 @@
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

concurrency:
group: rust-check
cancel-in-progress: true

# 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
# 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 Rustup
- 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 Protoc
uses: arduino/setup-protoc@v1
with:
version: 3.20.1
repo-token: ${{ secrets.GITHUB_TOKEN }}

- 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 }}

- run: ${{ github.workspace }}/sccache --show-stats

- name: Run tests
run: |
cargo test
- name: Check Build for Benchmarking
run: >
pushd node &&
cargo check --features=runtime-benchmarks --release
17 changes: 16 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sp_runtime::{
};
use sp_arithmetic::per_things::Percent;

use parity_scale_codec::{
use codec::{
Decode,
Encode,
};
Expand Down

0 comments on commit 5c97cde

Please sign in to comment.