diff --git a/.github/workflows/docker-localnet.yml b/.github/workflows/docker-localnet.yml new file mode 100644 index 0000000000..c485985e26 --- /dev/null +++ b/.github/workflows/docker-localnet.yml @@ -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) || '' }} diff --git a/.github/workflows/push-nodes.yml b/.github/workflows/push-nodes.yml deleted file mode 100644 index 86d8d954b5..0000000000 --- a/.github/workflows/push-nodes.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: PR Build and Merge - -on: - pull_request: - branches: - - devnet-ready-with-nodes - -jobs: - build-and-merge: - permissions: - pull-requests: write - runs-on: ubuntu-latest -# if: github.event.pull_request.merged - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: ${{ github.head_ref }} - - - name: Install dependencies - run: | - sudo apt-get update && - sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler jq - - - name: Install Rust stable - uses: actions-rs/toolchain@v1.0.6 - with: - toolchain: stable - components: rustfmt - profile: minimal - - - name: Add wasm32-unknown-unknown target - run: | - rustup target add wasm32-unknown-unknown --toolchain stable-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain stable-x86_64-unknown-linux-gnu - - - name: Run localnet.sh False --build-only - run: | - chmod +x scripts/localnet.sh - ./scripts/localnet.sh False --build-only - - - name: Run localnet.sh --build-only - run: | - chmod +x scripts/localnet.sh - ./scripts/localnet.sh --build-only - -# - name: Create a files -# working-directory: ${{ github.workspace }} -# run: | -# mkdir -p ${{ github.workspace }}/nodes/fast-blocks/release -# mkdir -p ${{ github.workspace }}/nodes/non-fast-blocks/release -# echo "fast-blocks" > ${{ github.workspace }}/nodes/fast-blocks/release/node-subtensor -# echo "non-fast-blocks" > ${{ github.workspace }}/nodes/non-fast-blocks/release/node-subtensor - - - name: Upload fast-blocks - uses: actions/upload-artifact@v4 - with: - name: fast-blocks - path: ${{ github.workspace }}/nodes/fast-blocks/release/node-subtensor - - - name: Upload non-fast-blocks - uses: actions/upload-artifact@v4 - with: - name: non-fast-blocks - path: ${{ github.workspace }}/nodes/non-fast-blocks/release/node-subtensor \ No newline at end of file diff --git a/Dockerfile-localnet b/Dockerfile-localnet new file mode 100644 index 0000000000..0efaf5b47a --- /dev/null +++ b/Dockerfile-localnet @@ -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"] diff --git a/nodes/fast-blocks/release/node-subtensor b/nodes/fast-blocks/release/node-subtensor deleted file mode 100755 index 3a8dabbf73..0000000000 Binary files a/nodes/fast-blocks/release/node-subtensor and /dev/null differ diff --git a/nodes/non-fast-blocks/release/node-subtensor b/nodes/non-fast-blocks/release/node-subtensor deleted file mode 100755 index 3a8dabbf73..0000000000 Binary files a/nodes/non-fast-blocks/release/node-subtensor and /dev/null differ diff --git a/scripts/localnet.sh b/scripts/localnet.sh index a52ddbe664..4de17f1521 100755 --- a/scripts/localnet.sh +++ b/scripts/localnet.sh @@ -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 @@ -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 @@ -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 @@ -107,6 +108,12 @@ 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 ( @@ -114,4 +121,4 @@ if [ $BUILD_ONLY -eq 0 ]; then ("${bob_start[@]}" 2>&1) wait ) -fi \ No newline at end of file +fi