diff --git a/Dockerfile b/Dockerfile index 2439d5b2a2..35e1e20b56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,5 @@ -ARG BASE_IMAGE=ubuntu:latest - -FROM $BASE_IMAGE AS builder -SHELL ["/bin/bash", "-c"] - -# Set noninteractive mode for apt-get -ARG DEBIAN_FRONTEND=noninteractive +ARG BASE_IMAGE=rust:1.83 +FROM $BASE_IMAGE AS base_builder LABEL ai.opentensor.image.authors="operations@opentensor.ai" \ ai.opentensor.image.vendor="Opentensor Foundation" \ @@ -12,37 +7,56 @@ LABEL ai.opentensor.image.authors="operations@opentensor.ai" \ ai.opentensor.image.description="Opentensor Subtensor Blockchain" \ ai.opentensor.image.documentation="https://docs.bittensor.com" +RUN rustup update stable +RUN rustup target add wasm32-unknown-unknown --toolchain stable + + # Set up Rust environment ENV RUST_BACKTRACE=1 -RUN apt-get update && \ - apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev && \ - rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev +RUN rm -rf /var/lib/apt/lists/* # 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 - +# +# Image for building prod +# +FROM base_builder AS prod_builder # Build the project RUN cargo build -p node-subtensor --profile production --features="metadata-hash" --locked - -# Slim down image -RUN rm -rf /root/.cargo - # Verify the binary was produced RUN test -e /build/target/production/node-subtensor - EXPOSE 30333 9933 9944 +# +# Final prod image +# FROM $BASE_IMAGE AS subtensor - # Copy all chainspec files -COPY --from=builder /build/chainspecs/*.json / +COPY --from=prod_builder /build/*.json / +# Copy final binary +COPY --from=prod_builder /build/target/production/node-subtensor /usr/local/bin + + +# +# Image for building local +# +FROM base_builder AS local_builder +# Build the project +RUN cargo build --workspace --profile release --features="pow-faucet" +# Verify the binary was produced +RUN test -e /build/target/release/node-subtensor +EXPOSE 30333 9933 9944 + +# +# Final local image +# +FROM $BASE_IMAGE AS subtensor-local +# Copy all chainspec files +COPY --from=local_builder /build/*.json / # Copy final binary -COPY --from=builder /build/target/production/node-subtensor /usr/local/bin +COPY --from=local_builder /build/target/release/node-subtensor /usr/local/bin +RUN "node-subtensor" build-spec --disable-default-bootnode --raw --chain local > /localnet.json diff --git a/docker-compose.localnet.yml b/docker-compose.localnet.yml new file mode 100644 index 0000000000..30acb2fd94 --- /dev/null +++ b/docker-compose.localnet.yml @@ -0,0 +1,74 @@ +volumes: + subtensor-alice: + subtensor-bob: + +services: + common: &common + image: ghcr.io/opentensor/subtensor:latest-local + cpu_count: 4 + mem_limit: 40000000000 + memswap_limit: 80000000000 + environment: + - CARGO_HOME=/var/www/node-subtensor/.cargo + + alice: + <<: *common + container_name: subtensor-alice + build: + context: . + dockerfile: Dockerfile + target: subtensor-local + ports: + - "9944:9944" + - "30334:30334" + expose: + - 9944 + - 30334 + volumes: + - subtensor-alice:/tmp/blockchain + command: + - /bin/bash + - -c + - | + node-subtensor \ + --base-path /tmp/blockchain \ + --chain localnet.json \ + --rpc-external \ + --rpc-methods=unsafe \ + --alice \ + --port 30334 \ + --rpc-port 9944 \ + --validator \ + --rpc-cors=all \ + --allow-private-ipv4 \ + --discover-local \ + --unsafe-force-node-key-generation + + bob: + <<: *common + container_name: subtensor-bob + expose: + - 9945 + - 30335 + ports: + - "9945:9945" + - "30335:30335" + volumes: + - subtensor-bob:/tmp/blockchain + command: + - /bin/bash + - -c + - | + node-subtensor \ + --base-path /tmp/blockchain \ + --chain localnet.json \ + --bob \ + --rpc-methods=unsafe \ + --rpc-external \ + --port 30335 \ + --rpc-port 9945 \ + --validator \ + --rpc-cors=all \ + --allow-private-ipv4 \ + --discover-local \ + --unsafe-force-node-key-generation diff --git a/docs/running-subtensor-locally.md b/docs/running-subtensor-locally.md index 82bb87356d..070d4edb50 100644 --- a/docs/running-subtensor-locally.md +++ b/docs/running-subtensor-locally.md @@ -1,3 +1,32 @@ # Running subtensor node locally -See the [**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes). +For General information on running Subtensors, see +[**Subtensor Nodes** section in Bittensor Developer Documentation](https://docs.bittensor.com/subtensor-nodes). + +### Running a localnet subtensor node + +Running a localnet in docker compose is the easiest way to quickly iterate on +chain state, like building on the evm. + +1. install docker and docker compose, along with cloning this repository. + +1. build the images from source on the desired branch using + `docker compose -f docker-compose.localnet.yml build`. Note this will take + quite a while. + +1. Run the docker compose file via + `docker compose -f docker-compose.localnet.yml up -d` + +Now you should have a full local validator running. To test your connection, you +can use the following script to check `//Alice`'s balance. Alice is a sudo +account in localnet. + +```py +# pip install substrate-interface +from substrateinterface import Keypair, SubstrateInterface + +substrate = SubstrateInterface(url="ws://127.0.0.1:9945") +hotkey = Keypair.create_from_uri('//Alice') +result = substrate.query("System", "Account", [hotkey.ss58_address]) +print(result.value) +```