From 18034d44f2d165465a4cb1dbfe930c02e3239030 Mon Sep 17 00:00:00 2001 From: taoshengshi Date: Fri, 21 Jun 2024 01:31:30 +0800 Subject: [PATCH] build:one dockerfile for resource provider and bacalhau (#155) * build:one dockerfile for resource provider and bacalhau (refactor by comments) * udpate bacalhau from 1.3.0 to 1.3.2 * fix: dockerfile rp bacalhau (#170) * refactor: update dockerfile to build from source and use dind * refactor: update docker build and run helper scripts for resource provider * feat: if the env var is not set do not include it in bacalhau's env * fix: dockerfile * fix: stack --------- Co-authored-by: Gorka Ludlow --- docker/resource-provider/Dockerfile | 56 ++++++++++++++++++++--------- pkg/executor/bacalhau/bacalhau.go | 6 +++- stack | 9 ++--- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/docker/resource-provider/Dockerfile b/docker/resource-provider/Dockerfile index 00165105..99a5069b 100644 --- a/docker/resource-provider/Dockerfile +++ b/docker/resource-provider/Dockerfile @@ -1,28 +1,50 @@ -FROM golang:latest as base +FROM docker:dind WORKDIR /usr/src/app -ARG doppler_config=dev -ARG network=dev -ARG DOPPLER_TOKEN_BACALHAU -ARG DOPPLER_TOKEN_RESOURCE_PROVIDER +# Build args +ARG NETWORK=testnet + +# Default environment variables +ENV LOG_LEVEL=info +ENV OFFER_GPU=1 +ENV BACALHAU_API_HOST="localhost" + +# Install necessary dependencies +RUN apk update +RUN apk add wget +RUN apk add bash + +# Install Bacalhau +RUN cd /tmp && \ + wget https://github.com/bacalhau-project/bacalhau/releases/download/v1.3.2/bacalhau_v1.3.2_linux_amd64.tar.gz && \ + tar xfv bacalhau_v1.3.2_linux_amd64.tar.gz && \ + mv bacalhau /usr/local/bin/bacalhau && \ + rm bacalhau_v1.3.2_linux_amd64.tar.gz + +# Build and install Lilypad +COPY --from=golang:1.22.4-alpine /usr/local/go/ /usr/local/go/ +ENV PATH="/usr/local/go/bin:${PATH}" COPY . . -RUN go mod download && go mod verify RUN go build -v . -RUN go install - -RUN (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sh +RUN mv lilypad /usr/local/bin -# RUN wget https://github.com/bacalhau-project/bacalhau/releases/download/v1.0.3/bacalhau_v1.0.3_linux_amd64.tar.gz -# RUN tar xfv bacalhau_v1.0.3_linux_amd64.tar.gz -# RUN mv bacalhau /usr/local/bin -# # RUN sysctl -w net.core.rmem_max=7500000 -# # RUN sysctl -w net.core.wmem_max=7500000 +# Add both lilypad and bacalhau executables to PATH +ENV PATH="/usr/local/bin:${PATH}" +# Create a startup script to run both services simultaneously RUN touch run RUN echo "#!/bin/bash" >> run -#RUN echo "doppler run --token=$DOPPLER_TOKEN_BACALHAU -p bacalhau -c $doppler_config -- ./stack bacalhau-serve &" >> run -RUN echo "doppler run --token=$DOPPLER_TOKEN_RESOURCE_PROVIDER -p resource-provider -c $doppler_config -- lilypad resource-provider --network $network" >> run +RUN echo "cat run" >> run +# Launch docker daemon +RUN echo "dockerd &" >> run +RUN echo "while ! docker -v; do sleep 1; done" >> run +# Launch Bacalhau +RUN echo "/usr/local/bin/bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked &" >> run +# Launch Lilypad +RUN echo "/usr/local/bin/lilypad resource-provider --network ${NETWORK}" >> run +RUN echo "wait -n" >> run RUN chmod +x run -CMD ["/bin/bash", "./run"] +# Run startup script when container starts +CMD ["/bin/bash", "./run"] \ No newline at end of file diff --git a/pkg/executor/bacalhau/bacalhau.go b/pkg/executor/bacalhau/bacalhau.go index 217f0983..66363165 100644 --- a/pkg/executor/bacalhau/bacalhau.go +++ b/pkg/executor/bacalhau/bacalhau.go @@ -27,8 +27,12 @@ type BacalhauExecutor struct { } func NewBacalhauExecutor(options BacalhauExecutorOptions) (*BacalhauExecutor, error) { + apiHost := "" + if options.ApiHost != "DO_NOT_SET" { + apiHost = fmt.Sprintf("BACALHAU_API_HOST=%s", options.ApiHost) + } bacalhauEnv := []string{ - fmt.Sprintf("BACALHAU_API_HOST=%s", options.ApiHost), + apiHost, fmt.Sprintf("HOME=%s", os.Getenv("HOME")), } log.Debug().Msgf("bacalhauEnv: %s", bacalhauEnv) diff --git a/stack b/stack index a035cca3..cb19a54e 100755 --- a/stack +++ b/stack @@ -214,18 +214,19 @@ function resource-provider-docker-build() { docker build \ -t resource-provider \ -f ./docker/resource-provider/Dockerfile \ - --build-arg doppler_config=dev \ - --build-arg network=dev \ - --build-arg DOPPLER_TOKEN_RESOURCE_PROVIDER="$(doppler configs tokens create -p resource-provider -c dev resource_provider_docker --plain)" \ + --build-arg NETWORK=dev \ . } function resource-provider-docker-run() { docker run \ --rm \ + --privileged \ --name resource-provider \ --add-host localhost:host-gateway \ - -e DOPPLER_TOKEN_RESOURCE_PROVIDER="$(doppler configs tokens create -p resource-provider -c dev resource_provider_docker --max-age 1m --plain)" \ + --env-file <(doppler -p resource-provider -c dev secrets download --no-file --format docker) \ + -e OFFER_GPU=0 \ + -e BACALHAU_API_HOST="DO_NOT_SET" \ resource-provider }