Skip to content

Commit

Permalink
chore: add sccache to docker and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson committed Feb 29, 2024
1 parent 45ac58c commit 19434a3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 47 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 }}
15 changes: 15 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ jobs:
version: 3.20.1
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install sccache and dependencies
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: |
curl https://github.com/mozilla/sccache/releases/download/v0.7.7/sccache-v0.7.7-x86_64-unknown-linux-musl.tar.gz \
-Lo sccache-v0.7.7-x86_64-unknown-linux-musl.tar.gz
tar -xzf sccache-v0.7.7-x86_64-unknown-linux-musl.tar.gz --strip-components=1 sccache-v0.7.7-x86_64-unknown-linux-musl/sccache
./sccache --start-server
echo "RUSTC_WRAPPER=${{ github.workspace }}/sccache" >> "$GITHUB_ENV"
- name: Check Clippy errors
uses: actions-rs/clippy-check@v1
env:
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/docker-build-n-push.yml

This file was deleted.

50 changes: 40 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
FROM rust:1.75-bookworm as build-env
FROM debian:12-slim AS builder

ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG SCCACHE_BUCKET
ARG SCCACHE_ENDPOINT
ENV SCCACHE_REGION=auto

RUN apt-get update
RUN apt-get install -y clang protobuf-compiler
WORKDIR /app
COPY . /app
RUN cargo build --release
COPY . .

# Dependencies using during the build stage.
RUN apt update && apt install -y --no-install-recommends \
ca-certificates \
curl \
build-essential \
protobuf-compiler \
libclang-dev \
git

ENV PATH=/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Installs rust with a minimal footprint and adds the WASM chain.
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- -y --profile=minimal --default-toolchain=nightly-2024-02-01

RUN if [ -n "$SCCACHE_BUCKET" ]; then \
curl https://github.com/mozilla/sccache/releases/download/v0.7.7/sccache-v0.7.7-x86_64-unknown-linux-musl.tar.gz \
-Lo sccache-v0.7.7-x86_64-unknown-linux-musl.tar.gz && \
tar -xzf sccache-v0.7.7-x86_64-unknown-linux-musl.tar.gz --strip-components=1 \
sccache-v0.7.7-x86_64-unknown-linux-musl/sccache && \
./sccache --start-server && \
export RUSTC_WRAPPER="/app/sccache"; \
fi && \
cargo build -p node-subspace --release --locked

RUN if [ -n "$SCCACHE_BUCKET" ]; then \
./sccache --show-stats; \
fi

# FROM gcr.io/distroless/cc
FROM debian:bookworm-slim
FROM debian:12-slim

RUN apt-get update && \
apt-get install -y zlib1g && \
RUN apt update && apt install -y zlib1g && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*

COPY --from=build-env /app/target/release/node-subspace /usr/local/bin
COPY --from=builder /app/target/release/node-subspace /usr/local/bin

WORKDIR /subspace

ENV RUST_BACKTRACE=1
CMD ["node-subspace"]
21 changes: 21 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ pub fn run() -> sc_cli::Result<()> {
}
})
}
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use crate::service::ExecutorDispatch;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
// we don't need any of the components of new_partial, just a runtime, or a task
// manager to do `async_run`.
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
Ok((
cmd.run::<Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
>>(),
task_manager,
))
})
}
Some(Subcommand::TryRuntime) => {
Err("TryRuntime is available through its own CLI now: <https://github.com/paritytech/try-runtime-cli>".into())
}
Expand Down

0 comments on commit 19434a3

Please sign in to comment.