Skip to content

Commit

Permalink
standardize entrypoint script name and location
Browse files Browse the repository at this point in the history
ls
  • Loading branch information
5u6r054 committed Jun 26, 2024
1 parent 59fe8a0 commit 489e602
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 19 deletions.
12 changes: 7 additions & 5 deletions docker/miner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ RUN python3 -m venv /opt/bittensor-venv && \
/opt/bittensor-venv/bin/pip install bittensor[torch] && \
/opt/bittensor-venv/bin/pip install python-dotenv

# Copy the scripts
COPY scripts/functions.sh /usr/local/bin/functions.sh
COPY scripts/create_miner.sh /usr/local/bin/create_miner.sh
# Copy the shared functions
COPY docker/functions.sh /app/functions.sh

# Copy the entrypoint script
COPY docker/miner/entrypoint.sh /app/entrypoint.sh

# Make the script executable
RUN chmod +x /usr/local/bin/create_miner.sh
RUN chmod +x /app/entrypoint.sh

# Copy the neurons and masa directories
COPY neurons /app/neurons
Expand All @@ -46,7 +48,7 @@ ENV PYTHONPATH="/opt/bittensor-venv/bin:/app:$PYTHONPATH"
ENV PATH="/opt/bittensor-venv/bin:$PATH"

# Set the entry point to run the script
ENTRYPOINT ["/usr/local/bin/create_miner.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]

# Add a command to keep the container running
CMD ["tail", "-f", "/dev/null"]
45 changes: 45 additions & 0 deletions docker/miner/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Activate the virtual environment
source /opt/bittensor-venv/bin/activate

# Use environment variables for passwords
COLDKEY_PASSWORD=${COLDKEY_PASSWORD:-'default_coldkey_password'}
HOTKEY_PASSWORD=${HOTKEY_PASSWORD:-'default_hotkey_password'}

# Import the shared functions
source functions.sh

# Create and fund miner wallets
#
# Create a new coldkey with the specified password
echo -e "$COLDKEY_PASSWORD\n$COLDKEY_PASSWORD" | btcli wallet new_coldkey --wallet.name miner --wallet.password

# Create a new hotkey with the specified password
echo -e "$HOTKEY_PASSWORD\n$HOTKEY_PASSWORD" | btcli wallet new_hotkey --wallet.name miner --wallet.hotkey miner_hotkey --wallet.password

# Use the faucet for the miner wallet
run_faucet miner || { echo "Faucet failed for miner wallet"; exit 1; }

echo "Wallets for miner created, and faucet used successfully."

# Wait for subnet 1 to be created
echo "Waiting for subnet 1 to be created..."
while ! check_subnet_exists; do
echo "Subnet 1 not found. Waiting 15 seconds before checking again..."
sleep 15
done
echo "Subnet 1 has been created. Proceeding with registration."

# Attempt to register the validator and start it
if register_node miner; then
echo "Miner registration successful. Starting the miner..."
# Start the miner
python /app/neurons/miner.py --netuid 1 --subtensor.chain_endpoint ws://subtensor_machine:9946 --wallet.name miner --wallet.hotkey miner_hotkey --axon.port 8091
else
echo "Miner registration failed. Not starting the validator."
fi

deactivate

tail -f /dev/null
8 changes: 4 additions & 4 deletions docker/subnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ RUN python3 -m venv /opt/bittensor-venv && \
/opt/bittensor-venv/bin/pip install bittensor[torch]

# Copy the subnet creation script
COPY scripts/functions.sh /usr/local/bin/functions.sh
COPY scripts/create_subnet.sh /usr/local/bin/create_subnet.sh
COPY docker/functions.sh /app/functions.sh
COPY docker/subnet/entrypoint.sh /app/entrypoint.sh

# Make the script executable
RUN chmod +x /usr/local/bin/create_subnet.sh
RUN chmod +x /app/entrypoint.sh

# Set the entry point to run the script
ENTRYPOINT ["/usr/local/bin/create_subnet.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]

# Set the PATH to include the virtual environment
ENV PATH="/opt/bittensor-venv/bin:$PATH"
Expand Down
41 changes: 41 additions & 0 deletions docker/subnet/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Import shared functions
source functions.sh

# Create and fund owner wallets
#
# Create a new coldkey with the specified password
echo -e "$COLDKEY_PASSWORD\n$COLDKEY_PASSWORD" | btcli wallet new_coldkey --wallet.name owner --wallet.password

# Create a new hotkey with the specified password
echo -e "$HOTKEY_PASSWORD\n$HOTKEY_PASSWORD" | btcli wallet new_hotkey --wallet.name owner --wallet.hotkey miner_hotkey --wallet.password

# Use the faucet for the owner wallet multiple times to get enough tTAO to register a subnet
for i in {1..4}; do
run_faucet owner || { echo "Faucet $i failed for owner wallet"; exit 1; }
done

echo -e "Owner faucet has run 4 times, now has 1200 τTAO"

# Register / Create a Subnet using expect to handle the interactive prompt and password
expect << EOF
log_user 1
spawn btcli subnet create --wallet.name owner --subtensor.chain_endpoint ws://subtensor_machine:9945
expect {
"Do you want to register a subnet for" {
send "y\r"
exp_continue
}
"Enter password to unlock key:" {
send "$COLDKEY_PASSWORD\r"
exp_continue
}
eof
}
EOF
sleep 10
btcli subnet list --subtensor.chain_endpoint ws://subtensor_machine:9945


tail -f /dev/null
10 changes: 5 additions & 5 deletions docker/subtensor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
RUN git clone https://github.com/opentensor/subtensor.git

# Copy the localnet.sh script into the subtensor/scripts directory
COPY scripts/localnet.sh /subtensor/scripts/localnet.sh
COPY docker/entrypoint.sh /app/entrypoint.sh

# Set the working directory
WORKDIR /subtensor
Expand All @@ -41,8 +41,8 @@ RUN git checkout main && \
/bin/bash -c "source $HOME/.cargo/env && \
cargo build --release --features runtime-benchmarks,pow-faucet"

# Make localnet.sh executable
RUN chmod +x /subtensor/scripts/localnet.sh
# Make entrypoint executable
RUN chmod +x /app/entrypoint.sh

# Set the entry point to run localnet.sh
ENTRYPOINT ["/subtensor/scripts/localnet.sh"]
# Set the entry point
ENTRYPOINT ["/app/entrypoint.sh"]
54 changes: 54 additions & 0 deletions docker/subtensor/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

: "${CHAIN:=local}"
: "${BUILD_BINARY:=1}"
: "${SPEC_PATH:=specs/}"
: "${FEATURES:=pow-faucet}"

FULL_PATH="$SPEC_PATH$CHAIN.json"

if [ ! -d "$SPEC_PATH" ]; then
echo "*** Creating directory ${SPEC_PATH}..."
mkdir $SPEC_PATH
fi

if [[ $BUILD_BINARY == "1" ]]; then
echo "*** Building substrate binary..."
cargo build --release --features "$FEATURES"
echo "*** Binary compiled"
fi

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

echo "*** Starting localnet nodes..."
alice_start=(
./target/release/node-subtensor
--base-path /tmp/alice
--chain="$FULL_PATH"
--alice
--port 30334
--rpc-port 9946
--validator
--rpc-cors=all
--allow-private-ipv4
--unsafe-rpc-external
--discover-local
)

bob_start=(
./target/release/node-subtensor
--base-path /tmp/bob
--chain="$FULL_PATH"
--bob
--port 30335
--rpc-port 9945
--validator
--allow-private-ipv4
--unsafe-rpc-external
--rpc-cors=all
--discover-local
)

(trap 'kill 0' SIGINT; ("${alice_start[@]}" 2>&1) & ("${bob_start[@]}" 2>&1))
10 changes: 5 additions & 5 deletions docker/validator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ RUN python3 -m venv /opt/bittensor-venv && \
/opt/bittensor-venv/bin/pip install python-dotenv

# Copy the validator creation script
COPY scripts/functions.sh /usr/local/bin/functions.sh
COPY scripts/create_validator.sh /usr/local/bin/create_validator.sh
COPY docker/functions.sh /app/functions.sh
COPY docker/validator/entrypoint.sh /app/entrypoint.sh

# Copy the neurons and masa directories
COPY neurons /app/neurons
Expand All @@ -42,11 +42,11 @@ WORKDIR /app
ENV PYTHONPATH="/opt/bittensor-venv/bin:/app:$PYTHONPATH"
ENV PATH="/opt/bittensor-venv/bin:$PATH"

# Make the script executable
RUN chmod +x /usr/local/bin/create_validator.sh
# Make the entrypoint script executable
RUN chmod +x /app/entrypoint.sh

# Set the entry point to run the script
ENTRYPOINT ["/usr/local/bin/create_validator.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]

# Add a command to keep the container running
CMD ["tail", "-f", "/dev/null"]
39 changes: 39 additions & 0 deletions docker/validator/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Activate the virtual environment
source /opt/bittensor-venv/bin/activate

# Use environment variables for passwords
COLDKEY_PASSWORD=${COLDKEY_PASSWORD:-'default_coldkey_password'}
HOTKEY_PASSWORD=${HOTKEY_PASSWORD:-'default_hotkey_password'}

# Import shared functions
source functions.sh

# Create and fund validator wallets
echo -e "$COLDKEY_PASSWORD\n$COLDKEY_PASSWORD" | btcli wallet new_coldkey --wallet.name validator --wallet.password
echo -e "$HOTKEY_PASSWORD\n$HOTKEY_PASSWORD" | btcli wallet new_hotkey --wallet.name validator --wallet.hotkey validator_hotkey --wallet.password

# Use the faucet for the validator wallet
run_faucet validator || { echo "Faucet failed for validator wallet"; exit 1; }
echo "Wallets for validator created, and faucet used successfully."

# Wait for subnet 1 to be created
echo "Waiting for subnet 1 to be created..."
while ! check_subnet_exists; do
echo "Subnet 1 not found. Waiting 15 seconds before checking again..."
sleep 15
done
echo "Subnet 1 has been created. Proceeding with registration."

# Attempt to register the validator and start it
if register_node validator; then
echo "Validator registration successful. Starting the validator..."
# Start the validator
python /app/neurons/validator.py --netuid 1 --subtensor.chain_endpoint ws://subtensor_machine:9946 --wallet.name validator --wallet.hotkey validator_hotkey --axon.port 8092
else
echo "Validator registration failed. Not starting the validator."
fi

# Keep the container running
tail -f /dev/null

0 comments on commit 489e602

Please sign in to comment.