Skip to content

Commit 05bc87c

Browse files
committed
Update Dockerfile for improved directory structure and permissions
1 parent f98d792 commit 05bc87c

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

.github/workflows/publish-docker.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- testnet
88
release:
99
types: [created]
10+
workflow_dispatch: null
1011

1112
env:
1213
REGISTRY: ghcr.io
@@ -39,7 +40,6 @@ jobs:
3940
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4041

4142
- name: Build and push Docker image for testnet branch
42-
if: github.ref == 'refs/heads/testnet'
4343
id: push-testnet
4444
uses: docker/build-push-action@v5
4545
with:
@@ -52,7 +52,6 @@ jobs:
5252
labels: ${{ steps.meta.outputs.labels }}
5353

5454
- name: Generate artifact attestation for testnet
55-
if: github.ref == 'refs/heads/testnet'
5655
id: attest-testnet
5756
uses: actions/attest-build-provenance@v1
5857
with:

Dockerfile

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,64 @@ RUN apt update && \
1919
gosu \
2020
&& apt clean && rm -rf /var/lib/apt/lists/*
2121

22+
# Make directories under opt and set owner to ubuntu
23+
RUN mkdir -p /opt/.cargo /opt/.rustup /opt/.nvm /opt/.npm /opt/.snarkjs /opt/omron/neurons && \
24+
chown -R ubuntu:ubuntu /opt && \
25+
chmod -R 775 /opt/omron && \
26+
chown root:root /opt
27+
2228
# Use ubuntu user
2329
USER ubuntu
24-
WORKDIR /home/ubuntu
30+
WORKDIR /opt
2531

2632
# Install Rust
2733
ENV RUST_TOOLCHAIN=nightly-2024-09-30
34+
ENV CARGO_HOME=/opt/.cargo
35+
ENV RUSTUP_HOME=/opt/.rustup
2836
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
29-
~/.cargo/bin/rustup toolchain install ${RUST_TOOLCHAIN} && \
30-
~/.cargo/bin/rustup default ${RUST_TOOLCHAIN} && \
31-
~/.cargo/bin/rustup toolchain remove stable
32-
ENV PATH="~/.cargo/bin:${PATH}"
37+
/opt/.cargo/bin/rustup toolchain install ${RUST_TOOLCHAIN} && \
38+
/opt/.cargo/bin/rustup default ${RUST_TOOLCHAIN} && \
39+
/opt/.cargo/bin/rustup toolchain remove stable && \
40+
chmod -R 775 /opt/.cargo /opt/.rustup
41+
ENV PATH="/opt/.cargo/bin:${PATH}"
3342

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

3847
# Install node et al.
48+
ENV NVM_DIR=/opt/.nvm
3949
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash && \
40-
export NVM_DIR="/home/ubuntu/.nvm" && \
4150
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
4251
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && \
4352
nvm install 20 && \
44-
npm install --prefix /home/ubuntu/.snarkjs [email protected] && \
53+
npm install --prefix /opt/.snarkjs [email protected] && \
4554
mkdir -p ~/.local/bin && \
4655
ln -s $(which node) /home/ubuntu/.local/bin/node && \
47-
ln -s $(which npm) /home/ubuntu/.local/bin/npm
56+
ln -s $(which npm) /home/ubuntu/.local/bin/npm && \
57+
chmod -R 775 /opt/.nvm /opt/.npm /opt/.snarkjs
4858
ENV PATH="/home/ubuntu/.local/bin:${PATH}"
4959

5060
# Copy omron and install Python dependencies (make sure owner is ubuntu)
51-
COPY neurons /home/ubuntu/omron/neurons
52-
COPY pyproject.toml /home/ubuntu/omron/pyproject.toml
53-
COPY uv.lock /home/ubuntu/omron/uv.lock
54-
USER root
55-
RUN chown -R ubuntu:ubuntu /home/ubuntu/omron
56-
USER ubuntu
61+
COPY --chown=ubuntu:ubuntu --chmod=775 neurons /opt/omron/neurons
62+
COPY --chown=ubuntu:ubuntu --chmod=775 pyproject.toml /opt/omron/pyproject.toml
63+
COPY --chown=ubuntu:ubuntu --chmod=775 uv.lock /opt/omron/uv.lock
5764
RUN pipx install uv && \
58-
cd ~/omron && \
65+
cd /opt/omron && \
5966
~/.local/bin/uv sync --locked --no-dev --compile-bytecode && \
6067
~/.local/bin/uv cache clean && \
61-
echo "source ~/omron/.venv/bin/activate" >> ~/.bashrc
62-
ENV PATH="/home/ubuntu/omron/.venv/bin:${PATH}"
68+
echo "source /opt/omron/.venv/bin/activate" >> ~/.bashrc && \
69+
chmod -R 775 /opt/omron/.venv
70+
ENV PATH="/opt/omron/.venv/bin:${PATH}"
6371

6472
# Set workdir for running miner.py or validator.py and compile circuits
65-
WORKDIR /home/ubuntu/omron/neurons
73+
WORKDIR /opt/omron/neurons
6674
ENV OMRON_NO_AUTO_UPDATE=1
67-
RUN OMRON_DOCKER_BUILD=1 /home/ubuntu/omron/.venv/bin/python3 miner.py && \
68-
rm -rf ~/omron/neurons/deployment_layer/*/target/release/build && \
69-
rm -rf ~/omron/neurons/deployment_layer/*/target/release/deps && \
70-
rm -rf ~/omron/neurons/deployment_layer/*/target/release/examples && \
71-
rm -rf ~/omron/neurons/deployment_layer/*/target/release/incremental && \
75+
RUN OMRON_DOCKER_BUILD=1 /opt/omron/.venv/bin/python3 miner.py && \
76+
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/build && \
77+
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/deps && \
78+
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/examples && \
79+
rm -rf /opt/omron/neurons/deployment_layer/*/target/release/incremental && \
7280
rm -rf ~/.bittensor && \
7381
rm -rf /tmp/omron
7482
USER root
@@ -78,21 +86,21 @@ set -e
7886
if [ -n "$PUID" ]; then
7987
if [ "$PUID" = "0" ]; then
8088
echo "Running as root user"
81-
/home/ubuntu/omron/.venv/bin/python3 "$@"
89+
/opt/omron/.venv/bin/python3 "$@"
8290
else
8391
echo "Changing ubuntu user id to $PUID"
8492
usermod -u "$PUID" ubuntu
85-
gosu ubuntu /home/ubuntu/omron/.venv/bin/python3 "$@"
93+
gosu ubuntu /opt/omron/.venv/bin/python3 "$@"
8694
fi
8795
else
88-
gosu ubuntu /home/ubuntu/omron/.venv/bin/python3 "$@"
96+
gosu ubuntu /opt/omron/.venv/bin/python3 "$@"
8997
fi
9098
EOF
9199
RUN chmod +x /entrypoint.sh
92100
ENTRYPOINT ["/entrypoint.sh"]
93101
CMD ["-c", "import subprocess; \
94-
subprocess.run(['/home/ubuntu/omron/.venv/bin/python3', '/home/ubuntu/omron/neurons/miner.py', '--help']); \
95-
subprocess.run(['/home/ubuntu/omron/.venv/bin/python3', '/home/ubuntu/omron/neurons/validator.py', '--help']);" \
102+
subprocess.run(['/opt/omron/.venv/bin/python3', '/opt/omron/neurons/miner.py', '--help']); \
103+
subprocess.run(['/opt/omron/.venv/bin/python3', '/opt/omron/neurons/validator.py', '--help']);" \
96104
]
97105
# Axon server
98106
EXPOSE 8091/tcp

0 commit comments

Comments
 (0)