Skip to content

Commit

Permalink
build:one dockerfile for resource provider and bacalhau (#155)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
taoshengshi and AquiGorka authored Jun 20, 2024
1 parent 9164626 commit 18034d4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
56 changes: 39 additions & 17 deletions docker/resource-provider/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 5 additions & 1 deletion pkg/executor/bacalhau/bacalhau.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions stack
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 18034d4

Please sign in to comment.