Chia-Network / chia-docker

Apache License 2.0
215 stars 345 forks source link

Bladebit installed #209

Closed w0lv3r1nix closed 1 year ago

w0lv3r1nix commented 1 year ago

Hey guys,

Is it possible to include the available plotters inside the image? I've tried to plot but got this message: Bladebit was not found.

Starttoaster commented 1 year ago

Hey, thanks for the suggestion! I'm interested to hear your thoughts on what plotting in chia-docker containers should look like. I put up a fairly simple PR today that accomplishes this https://github.com/Chia-Network/chia-docker/pull/213/files, what do you think?

This PR would put a bladebit executable in /bladebit/build/bladebit, which you could use to make plots if exec'd into the container. I'm hesitant though, as by itself this doesn't help a ton. A person still manually needs to exec into the container and generate a plot. Though it would seem a much taller ask to maintain an entrypoint script that contains all the plotters and supports the variety of plotter settings a farmer may be interested in. Is just installing bladebit in the container helpful/useful?

w0lv3r1nix commented 1 year ago

Hey,

The "main" idea behind was to use the chia app from truenas, because I can plot directly to the storage and I have enough ram. So I've checked and it is using this image but I couldn't install bladebit on it, for now I've created my own but on truenas its just a "docker app" running my own image, so it would be nice to use the "native" one.

I played with the dockerfile today, but didn't have time to create a PR, your looks good, but here is what I've discovered:

So my solution was to use the install-plotter.sh script from chia and to add the bladebit libraries as you did on the final image

# CHIA BUILD STEP
FROM python:3.9-bullseye AS chia_build

ARG BRANCH=latest
ARG COMMIT=""

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
        lsb-release sudo

WORKDIR /chia-blockchain

RUN echo "cloning ${BRANCH}" && \
    git clone --depth 1 --branch ${BRANCH} --recurse-submodules=mozilla-ca https://github.com/Chia-Network/chia-blockchain.git . && \
    # If COMMIT is set, check out that commit, otherwise just continue
    ( [ ! -z "$COMMIT" ] && git fetch origin $COMMIT && git checkout $COMMIT ) || true && \
    echo "running build-script" && \
    /bin/sh ./install.sh

# Get yq for chia config changes
FROM mikefarah/yq:4 AS yq

# IMAGE BUILD
FROM python:3.9-slim-bullseye

EXPOSE 8555 8444

ENV CHIA_ROOT=/home/chia/.chia/mainnet
ENV keys="generate"
ENV service="farmer"
ENV plots_dir="/plots"
ENV farmer_address=
ENV farmer_port=
ENV testnet="false"
ENV TZ="UTC"
ENV upnp="true"
ENV log_to_file="true"
ENV healthcheck="true"
ENV chia_args=
ENV full_node_peer=

# Deprecated legacy options
ENV harvester="false"
ENV farmer="false"

# Minimal list of software dependencies
#   sudo: Needed for alternative plotter install
#   tzdata: Setting the timezone
#   curl: Health-checks
#   netcat: Healthchecking the daemon
#   yq: changing config settings
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y sudo tzdata curl netcat-traditional wget build-essential cmake libgmp-dev libnuma-dev && \
    rm -rf /var/lib/apt/lists/* && \
    ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone && \
    dpkg-reconfigure -f noninteractive tzdata

RUN useradd -m chia

USER chia

COPY --from=yq --chown=chia /usr/bin/yq /usr/bin/yq
COPY --from=chia_build --chown=chia /chia-blockchain /chia-blockchain

ENV PATH=/chia-blockchain/venv/bin:$PATH
WORKDIR /chia-blockchain

COPY --chown=chia docker-start.sh /usr/local/bin/
COPY --chown=chia docker-entrypoint.sh /usr/local/bin/
COPY --chown=chia docker-healthcheck.sh /usr/local/bin/

RUN . activate && /chia-blockchain/install-plotter.sh bladebit

HEALTHCHECK --interval=1m --timeout=10s --start-period=20m \
  CMD /bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["docker-start.sh"]
Starttoaster commented 1 year ago

Hey again! So a few things:

I tried to build the bladebit on another image (build image) and just copy it over but with bullseye the cmake doesn't met the minimum requirements, so I've switched to bookworm, but with that you can't use the slim image because its missing some python stuff

We actually sorted through that problem yesterday. It turns out, the non-slim image has two versions of python installed. (3.11 and 3.9) So when we built chia in the non-slim image, it built using the latest python version installed in the image (3.11), and when copying the built chia directory over to the slim image, it only has python 3.9, which was what was causing issues. This PR solved that by using the slim image for the build as well: https://github.com/Chia-Network/chia-docker/pull/212

After the installation, if you tried to use "chia plotters bladebit" it doesn't know where the bladebit is

Yeah, my PR that installs bladebit doesn't solve for that either, you'd just call the bladebit executable directly. That install-plotter.sh script may be a better option though. I'll look at that, thanks :)

The container shouldn't run as root because you can't plot as root. ( and its a good practice )

So for things like bladebit, or the chia timelord component, we imagine most people are not using chia-docker for running timelords or plotting, so we rely on root privileges to install them in the entrypoint script at docker run time. What would be your ideal solution to that problem? (Additionally, in the instance of chia timelords, and more specifically chiavdf, this is compiled with many options specific to the CPU you're running on, so it makes the most sense to compile chiavdf at run-time for chia-docker.)

w0lv3r1nix commented 1 year ago

Hey :)

We actually sorted through that problem yesterday. It turns out, the non-slim image has two versions of python installed. (3.11 and 3.9) So when we built chia in the non-slim image, it built using the latest python version installed in the image (3.11), and when copying the built chia directory over to the slim image, it only has python 3.9, which was what was causing issues. This PR solved that by using the slim image for the build as well: https://github.com/Chia-Network/chia-docker/pull/212

Nice, I missed that one!

So for things like bladebit, or the chia timelord component, we imagine most people are not using chia-docker for running timelords or plotting, so we rely on root privileges to install them in the entrypoint script at docker run time. What would be your ideal solution to that problem?

I've created a chia user and the only "problem" that I found when running on non-root mode was the creation of the symbolic link pointing to the localtime ( because of the timezone )

ln: failed to create symbolic link '/etc/localtime': Permission denied

I think that can be fixed with a simple export of the TZ, or a echo into the .profile TZ=''; export TZ

I didn't tested it all but it looks good.

github-actions[bot] commented 1 year ago

'This issue has been flagged as stale as there has been no activity on it in 14 days. If this issue is still affecting you and in need of review, please update it to keep it open.'

github-actions[bot] commented 1 year ago

'This issue was automatically closed because it has been flagged as stale and subsequently passed 7 days with no further activity.'

GuyPaddock commented 11 months ago

Would love to see this.