Skip to content

Commit

Permalink
Change user inside docker container from root -> ubuntu (id 1000:1000) (
Browse files Browse the repository at this point in the history
#46)

* Change user inside docker container from root -> ubuntu (id 1000:1000)

* Add permission check for models directory in init_config
  • Loading branch information
elesiuta authored Jan 17, 2025
1 parent 2232d9e commit fd7d3db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
59 changes: 33 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,59 @@ RUN apt update && \
protobuf-compiler \
&& apt clean && rm -rf /var/lib/apt/lists/*

# Use ubuntu user
USER ubuntu
WORKDIR /home/ubuntu

# Install Rust
ENV RUST_TOOLCHAIN=nightly-2024-09-30
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
/root/.cargo/bin/rustup toolchain install ${RUST_TOOLCHAIN} && \
/root/.cargo/bin/rustup default ${RUST_TOOLCHAIN} && \
/root/.cargo/bin/rustup toolchain remove stable
ENV PATH="/root/.cargo/bin:${PATH}"
~/.cargo/bin/rustup toolchain install ${RUST_TOOLCHAIN} && \
~/.cargo/bin/rustup default ${RUST_TOOLCHAIN} && \
~/.cargo/bin/rustup toolchain remove stable
ENV PATH="~/.cargo/bin:${PATH}"

# Install Jolt
#ENV JOLT_VERSION=dd9e5c4bcf36ffeb75a576351807f8d86c33ec66
#RUN cargo +${RUST_TOOLCHAIN} install --git https://github.com/a16z/jolt --rev ${JOLT_VERSION} --force --bins jolt

# Install node et al.
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash && \
export NVM_DIR="/root/.nvm" && \
export NVM_DIR="/home/ubuntu/.nvm" && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && \
nvm install 20 && \
npm install --prefix /root/.snarkjs [email protected] && \
ln -s $(which node) /usr/bin/node && \
ln -s $(which npm) /usr/bin/npm
npm install --prefix /home/ubuntu/.snarkjs [email protected] && \
mkdir -p ~/.local/bin && \
ln -s $(which node) /home/ubuntu/.local/bin/node && \
ln -s $(which npm) /home/ubuntu/.local/bin/npm
ENV PATH="/home/ubuntu/.local/bin:${PATH}"

# Copy omron and install Python dependencies
COPY neurons /opt/omron/neurons
COPY pyproject.toml /opt/omron/pyproject.toml
COPY uv.lock /opt/omron/uv.lock
# Copy omron and install Python dependencies (make sure owner is ubuntu)
RUN mkdir -p /home/ubuntu/omron/neurons
COPY neurons /home/ubuntu/omron/neurons
COPY pyproject.toml /home/ubuntu/omron/pyproject.toml
COPY uv.lock /home/ubuntu/omron/uv.lock
RUN pipx install uv && \
cd /opt/omron && \
/root/.local/bin/uv sync --locked && \
/root/.local/bin/uv cache clean && \
echo "source /opt/omron/.venv/bin/activate" >> ~/.bashrc
ENV PATH="/opt/omron/.venv/bin:${PATH}"
cd ~/omron && \
~/.local/bin/uv sync --locked && \
~/.local/bin/uv cache clean && \
echo "source ~/omron/.venv/bin/activate" >> ~/.bashrc
ENV PATH="/home/ubuntu/omron/.venv/bin:${PATH}"

# Set workdir for running miner.py or validator.py and compile circuits
WORKDIR /opt/omron/neurons
WORKDIR /home/ubuntu/omron/neurons
ENV OMRON_NO_AUTO_UPDATE=1
RUN OMRON_DOCKER_BUILD=1 python3 miner.py && \
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/build && \
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/deps && \
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/examples && \
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/incremental && \
rm -rf /root/.bittensor
ENTRYPOINT ["/opt/omron/.venv/bin/python3"]
rm -rf ~/omron/neurons/deployment_layer/*/target/release/build && \
rm -rf ~/omron/neurons/deployment_layer/*/target/release/deps && \
rm -rf ~/omron/neurons/deployment_layer/*/target/release/examples && \
rm -rf ~/omron/neurons/deployment_layer/*/target/release/incremental && \
rm -rf ~/.bittensor
ENTRYPOINT ["/home/ubuntu/omron/.venv/bin/python3"]
CMD ["-c", "import subprocess; \
subprocess.run(['/opt/omron/.venv/bin/python3', '/opt/omron/neurons/miner.py', '--help']); \
subprocess.run(['/opt/omron/.venv/bin/python3', '/opt/omron/neurons/validator.py', '--help']);" \
subprocess.run(['/home/ubuntu/omron/.venv/bin/python3', '/home/ubuntu/omron/neurons/miner.py', '--help']); \
subprocess.run(['/home/ubuntu/omron/.venv/bin/python3', '/home/ubuntu/omron/neurons/validator.py', '--help']);" \
]
# Axon server
EXPOSE 8091/tcp
Expand Down
7 changes: 7 additions & 0 deletions neurons/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,17 @@ def init_config(role: Optional[str]):
bt.logging(config=config, logging_dir=config.logging.logging_dir)
bt.logging.enable_info()

# Make sure we have access to the models directory
if not os.access(config.full_path, os.W_OK):
bt.logging.error(
f"Cannot write to {config.full_path}. Please make sure you have the correct permissions."
)

if config.wandb_key:
wandb_logger.safe_login(api_key=config.wandb_key)
bt.logging.success("Logged into WandB")


def _miner_config():
"""
Add CLI arguments specific to the miner.
Expand Down

0 comments on commit fd7d3db

Please sign in to comment.