Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/docker-localnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Publish Localnet Docker Image

on:
release:
types: [published]
workflow_dispatch:
inputs:
branch-or-tag:
description: "Branch or tag to use for the Docker image tag and ref to checkout (optional)"
required: false
default: ""
push:
branches:
- devnet-ready-with-nodes

permissions:
contents: read
packages: write
actions: read
security-events: write

jobs:
publish:
runs-on: SubtensorCI

steps:
- name: Determine Docker tag and ref
id: tag
run: |
branch_or_tag="${{ github.event.inputs.branch-or-tag || github.ref_name }}"
echo "Determined branch or tag: $branch_or_tag"
echo "tag=$branch_or_tag" >> $GITHUB_ENV
echo "ref=$branch_or_tag" >> $GITHUB_ENV

# Check if this is a tagged release (not devnet-ready/devnet/testnet)
if [[ "$branch_or_tag" != "devnet-ready" ]]; then
echo "latest_tag=true" >> $GITHUB_ENV
else
echo "latest_tag=false" >> $GITHUB_ENV
fi

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ env.ref }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: Docker-localnet
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}-localnet:${{ env.tag }}
${{ env.latest_tag == 'true' && format('ghcr.io/{0}-localnet:latest', github.repository) || '' }}
65 changes: 0 additions & 65 deletions .github/workflows/push-nodes.yml

This file was deleted.

65 changes: 65 additions & 0 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
ARG BASE_IMAGE=ubuntu:latest

FROM $BASE_IMAGE AS builder
SHELL ["/bin/bash", "-c"]

# Set noninteractive mode for apt-get
ARG DEBIAN_FRONTEND=noninteractive

LABEL ai.opentensor.image.authors="operations@opentensor.ai" \
ai.opentensor.image.vendor="Opentensor Foundation" \
ai.opentensor.image.title="opentensor/subtensor-localnet" \
ai.opentensor.image.description="Opentensor Subtensor Blockchain" \
ai.opentensor.image.documentation="https://docs.bittensor.com"

# Set up Rust environment
ENV RUST_BACKTRACE=1

RUN apt-get update
RUN apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev llvm libudev-dev

# Copy entire repository
COPY . /build
WORKDIR /build

# Install Rust
RUN set -o pipefail && curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup toolchain install
RUN rustup target add wasm32-unknown-unknown

## Build fast-blocks node
RUN ./scripts/localnet.sh --build-only
# Build non-fast-blocks
RUN ./scripts/localnet.sh False --build-only

# Verify the binaries was produced
RUN test -e /build/target/fast-blocks/release/node-subtensor
RUN test -e /build/target/non-fast-blocks/release/node-subtensor

FROM $BASE_IMAGE AS subtensor-localnet

# Copy binaries
COPY --from=builder /build/target/fast-blocks/release/node-subtensor target/fast-blocks/release/node-subtensor
RUN chmod +x target/fast-blocks/release/node-subtensor

COPY --from=builder /build/target/non-fast-blocks/release/node-subtensor target/non-fast-blocks/release/node-subtensor
RUN chmod +x target/non-fast-blocks/release/node-subtensor

COPY --from=builder /build/snapshot.json /snapshot.json

COPY --from=builder /build/scripts/localnet.sh scripts/localnet.sh
RUN chmod +x /scripts/localnet.sh

## Ubdate certificates
RUN apt-get update && apt-get install -y ca-certificates

# Do not build (just run)
ENV BUILD_BINARY=0
# Switch to local run with IP 0.0.0.0 within docker image
ENV RUN_IN_DOCKER=1
# Expose ports
EXPOSE 30334 30335 9944 9945

ENTRYPOINT ["/scripts/localnet.sh"]
CMD ["True"]
Binary file removed nodes/fast-blocks/release/node-subtensor
Binary file not shown.
Binary file removed nodes/non-fast-blocks/release/node-subtensor
Binary file not shown.
15 changes: 11 additions & 4 deletions scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ if [ "$fast_blocks" == "False" ]; then
: "${CHAIN:=local}"
: "${BUILD_BINARY:=1}"
: "${FEATURES:="pow-faucet"}"
BUILD_DIR="$BASE_DIR/nodes/non-fast-blocks"
BUILD_DIR="$BASE_DIR/target/non-fast-blocks"
else
# Block of code to execute if fast_blocks is not False
echo "fast_blocks is On"
: "${CHAIN:=local}"
: "${BUILD_BINARY:=1}"
: "${FEATURES:="pow-faucet fast-blocks"}"
BUILD_DIR="$BASE_DIR/nodes/fast-blocks"
BUILD_DIR="$BASE_DIR/target/fast-blocks"
fi

# Ensure the build directory exists
Expand All @@ -61,7 +61,7 @@ if [[ $BUILD_BINARY == "1" ]]; then
fi

echo "*** Building chainspec..."
"$BUILD_DIR/release/node-subtensor" build-spec --disable-default-bootnode --raw --chain $CHAIN >$FULL_PATH
"$BUILD_DIR/release/node-subtensor" build-spec --disable-default-bootnode --raw --chain "$CHAIN" >"$FULL_PATH"
echo "*** Chainspec built and output to file"

# Generate node keys
Expand All @@ -79,6 +79,7 @@ fi

if [ $BUILD_ONLY -eq 0 ]; then
echo "*** Starting localnet nodes..."

alice_start=(
"$BUILD_DIR/release/node-subtensor"
--base-path /tmp/alice
Expand Down Expand Up @@ -107,11 +108,17 @@ if [ $BUILD_ONLY -eq 0 ]; then
--unsafe-force-node-key-generation
)

# Provide RUN_IN_DOCKER local environment variable if run script in the docker image
if [ "${RUN_IN_DOCKER}" == "1" ]; then
alice_start+=(--unsafe-rpc-external)
bob_start+=(--unsafe-rpc-external)
fi

trap 'pkill -P $$' EXIT SIGINT SIGTERM

(
("${alice_start[@]}" 2>&1) &
("${bob_start[@]}" 2>&1)
wait
)
fi
fi
Loading