Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - [LAB-931] Lilypad container #802

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,28 @@ jobs:
NEXT_PUBLIC_IPFS_GATEWAY_ENDPOINT=${{ matrix.backends.gateway }}
deploy-environment: ${{ matrix.backend.env }}
secrets: inherit

########## LILYPAD container ##################################
changes-lilypad:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
changes: ${{ steps.filter.outputs.lilypad }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
lilypad:
- 'docker/images/lilypad/**'

lilypad:
needs: changes-lilypad
if: ${{ needs.changes-lilypad.outputs.changes == 'true' || github.event_name == 'workflow_dispatch' }}
uses: ./.github/workflows/docker.yml
with:
name: lilypad
context: docker/images/lilypad
secrets: inherit
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ARG BACALHAU_VERSION=1.1.4
# For bacalhau cli
FROM ghcr.io/bacalhau-project/bacalhau:v${BACALHAU_VERSION:-1.1.4} as bacalhau

FROM busybox:1.31.1-glibc
FROM public.ecr.aws/docker/library/busybox:1.32.0-glibc

COPY --from=builder /go/bin/plex /plex
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
Expand Down
274 changes: 274 additions & 0 deletions docker-compose-lilypad.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
---

services:
requester:
image: "ghcr.io/bacalhau-project/bacalhau:${BACALHAU_VERSION:-v1.2.0}"
hostname: requester
command: serve --peer none --node-type requester --private-internal-ipfs=false # --ipfs-connect '/dns4/ipfs/tcp/5001' --labels "owner=labdao" # --job-selection-probe-http "http://receptor:8080/judge"
environment:
BACALHAU_ENVIRONMENT: local
LOG_LEVEL: trace
ports:
- 1234:1234
- 1235:1235

# sidecar container for requester healthcheck
requester_health:
image: "alpine"
command: sh -c 'apk add curl && sleep infinity'
depends_on:
requester:
condition: service_started
healthcheck:
test: curl -f http://requester:1234/api/v1/healthz
interval: 10s
timeout: 10s
retries: 10
start_period: 10s

compute:
image: "ghcr.io/bacalhau-project/bacalhau:${BACALHAU_VERSION:-v1.2.0}"
hostname: compute
command: serve --peer "/dns4/requester/tcp/1234/http" --node-type compute --private-internal-ipfs=false # --ipfs-connect '/dns4/ipfs/tcp/5001' --labels "owner=labdao" # --job-selection-probe-http "http://receptor:8080/judge"
environment:
BACALHAU_ENVIRONMENT: local
LOG_LEVEL: trace
KEEP_STACK: "true"
BACALHAU_DIR: /tmp/bacalhau
ports:
- 2234:1234
- 2235:1235
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /tmp:/tmp
depends_on:
requester:
condition: service_started
requester_health:
condition: service_healthy

# sidecar container for compute healthcheck
compute_health:
image: "alpine"
command: sh -c 'apk add curl && sleep infinity'
depends_on:
compute:
condition: service_started
healthcheck:
test: curl -f http://compute:1234/api/v1/healthz
interval: 10s
timeout: 10s
retries: 10
start_period: 10s

# geth
geth:
image: "ethereum/client-go"
hostname: geth
command: --datadir /data/geth --dev --ws --ws.api web3,eth,net --ws.addr 0.0.0.0 --ws.port 8546 --ws.origins '*' --http --http.api web3,eth,net --http.addr 0.0.0.0 --http.corsdomain '*' --http.port 8545 --http.vhosts '*' --graphql
# environment:
# BACALHAU_ENVIRONMENT: production
# LOG_LEVEL: trace
volumes:
- geth:/data/geth
ports:
- 8545:8545
- 8546:8546
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8545 || exit 1
interval: 60s
timeout: 10s
retries: 10
start_period: 10s

# lilypad-setup
lilypad-setup:
image: "public.ecr.aws/docker/library/node:20"
command: >
sh -x -c '

if [ -f /app/lilypad/done ]; then exit;fi &&

apt-get -q update && apt-get -q -y install sudo &&

rm -rf /tmp/lilypad/lilypad /tmp/geth &&

wget --no-verbose https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-${GETH_VERSION:-1.13.5-916d6a44}.tar.gz -O geth.tgz &&
tar -zxvf geth.tgz &&
mv geth-linux-amd64-${GETH_VERSION:-1.13.5-916d6a44}/geth /usr/local/bin/ &&

mkdir -p /tmp/lilypad/data &&
chmod -R 777 /tmp/lilypad/data &&

cd /tmp/lilypad/ &&
git clone https://github.com/bacalhau-project/lilypad --branch ${LILYPAD_VERSION:-v2.0.0-e5c38d5} &&
cd lilypad &&

sed -i "s/localhost/geth/g" hardhat/hardhat.config.ts &&
(cd hardhat && yarn install) &&
./stack print-env > .env &&

echo "export WEB3_RPC_URL=ws://geth:8546" >> .env &&
echo "export LOG_LEVEL=info" >> .env &&
echo "export WEB3_CONTROLLER_ADDRESS=0x59b670e9fA9D0A427751Af201D676719a970857b" >> .env &&
echo "export BACALHAU_API_HOST=requester" >> .env &&

cp -rav .env /app/lilypad/.env &&
. ./.env &&

/usr/local/bin/geth --exec "eth.sendTransaction({from: eth.coinbase, to: \"$${ADMIN_ADDRESS}\", value: new web3.BigNumber(eth.getBalance(eth.coinbase)).minus(web3.toWei(1, \"ether\")) })" attach "http://geth:8545" &&
bash -x ./stack fund-services-ether &&
bash -x ./stack deploy &&
bash -x ./stack fund-services-tokens &&
bash -x ./stack balances &&
touch /app/lilypad/done &&

cp -rav /app/lilypad/.env /app/solver/.env &&
echo export WEB3_PRIVATE_KEY=$$SOLVER_PRIVATE_KEY >> /app/solver/.env &&
echo export JOB_CREATOR_ADDRESS=$$JOB_CREATOR_ADDRESS >> /app/solver/.env &&
echo export SERVICE_MEDIATORS=$$MEDIATOR_ADDRESS >> /app/solver/.env &&

cp -rav /app/lilypad/.env /app/mediator/.env &&
echo export WEB3_PRIVATE_KEY=$$MEDIATOR_PRIVATE_KEY >> /app/mediator/.env &&
echo export WEB3_DIRECTORY_ADDRESS=$$DIRECTORY_ADDRESS >> /app/mediator/.env &&
echo export SERVICE_SOLVER=$$SOLVER_ADDRESS >> /app/mediator/.env &&

cp -rav /app/lilypad/.env /app/resource-provider/.env &&
echo export WEB3_PRIVATE_KEY=$$RESOURCE_PROVIDER_PRIVATE_KEY >> /app/resource-provider/.env &&
echo export SERVICE_SOLVER=$$SOLVER_ADDRESS >> /app/resource-provider/.env &&
echo export SERVICE_MEDIATORS=$$MEDIATOR_ADDRESS >> /app/resource-provider/.env &&
echo "export LOG_LEVEL=error" >> /app/resource-provider/.env &&

cp -rav /app/lilypad/.env /app/jobcreator/.env &&
echo export WEB3_PRIVATE_KEY=$$SOLVER_PRIVATE_KEY >> /app/jobcreator/.env &&
echo export SERVICE_SOLVER=$$SOLVER_ADDRESS >> /app/jobcreator/.env &&
echo export SERVICE_MEDIATORS=$$MEDIATOR_ADDRESS >> /app/jobcreator/.env

echo export SERVICE_SOLVER=$${SOLVER_ADDRESS} >> .env &&
echo export SERVICE_MEDIATORS=$${MEDIATOR_ADDRESS} >> .env &&
echo export WEB3_PRIVATE_KEY=$${ADMIN_PRIVATE_KEY} >> .env &&
echo export WEB3_RPC_URL=ws://localhost:8546 >> .env'

environment:
USER: root
volumes:
- lilypad:/app/lilypad
- solver:/app/solver
- mediator:/app/mediator
- resource-provider:/app/resource-provider
- jobcreator:/app/jobcreator
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
- /tmp/lilypad:/tmp/lilypad
depends_on:
geth:
condition: service_healthy

# solver
lilypad-solver:
build:
context: ./docker/images/lilypad
dockerfile: ./Dockerfile
cache_from:
- quay.io/labdao/lilypad:pr-802
args:
LILYPAD_VERSION: ${LILYPAD_VERSION:-v2.0.0-e5c38d5}
BACALHAU_VERSION: ${BACALHAU_VERSION:-v1.2.0}
hostname: lilypad-solver
command: solver
environment:
SERVER_PORT: 8080
SERVER_URL: http://lilypad-solver:8080
ports:
- 8080:8080
volumes:
- solver:/app/lilypad
depends_on:
geth:
condition: service_healthy
lilypad-setup:
condition: service_completed_successfully

# mediator
lilypad-mediator:
build:
context: ./docker/images/lilypad
dockerfile: ./Dockerfile
cache_from:
- quay.io/labdao/lilypad:pr-802
args:
LILYPAD_VERSION: ${LILYPAD_VERSION:-v2.0.0-e5c38d5}
BACALHAU_VERSION: ${BACALHAU_VERSION:-v1.2.0}
hostname: lilypad-mediator
command: mediator
volumes:
- mediator:/app/lilypad
depends_on:
geth:
condition: service_healthy
lilypad-setup:
condition: service_completed_successfully
lilypad-solver:
condition: service_started

# resource-provider
lilypad-resource-provider:
build:
context: ./docker/images/lilypad
dockerfile: ./Dockerfile
cache_from:
- quay.io/labdao/lilypad:pr-802
args:
LILYPAD_VERSION: ${LILYPAD_VERSION:-v2.0.0-e5c38d5}
BACALHAU_VERSION: ${BACALHAU_VERSION:-v1.2.0}
hostname: lilypad-resource-provider
command: resource-provider
volumes:
- resource-provider:/app/lilypad
- /tmp/lilypad:/tmp/lilypad
depends_on:
geth:
condition: service_healthy
lilypad-solver:
condition: service_started
lilypad-mediator:
condition: service_started
lilypad-setup:
condition: service_completed_successfully
requester_health:
condition: service_healthy

# jobcreator
lilypad-jobcreator:
build:
context: ./docker/images/lilypad
dockerfile: ./Dockerfile
cache_from:
- quay.io/labdao/lilypad:pr-802
args:
LILYPAD_VERSION: ${LILYPAD_VERSION:-v2.0.0-e5c38d5}
BACALHAU_VERSION: ${BACALHAU_VERSION:-v1.2.0}
hostname: lilypad-jobcreator
command: jobcreator
volumes:
- jobcreator:/app/lilypad
depends_on:
geth:
condition: service_healthy
lilypad-solver:
condition: service_started
lilypad-mediator:
condition: service_started
lilypad-resource-provider:
condition: service_started
lilypad-setup:
condition: service_completed_successfully

volumes:
dbdata-backend:
lilypad:
solver:
mediator:
jobcreator:
resource-provider:
geth:
40 changes: 40 additions & 0 deletions docker/images/lilypad/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM public.ecr.aws/docker/library/golang:1.20-buster as builder

# Install deps
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
ca-certificates \
fuse

ARG LILYPAD_VERSION=v2.0.0-e5c38d5

WORKDIR /lilypad

# Clone Lilypad project
RUN git clone https://github.com/bacalhau-project/lilypad.git --branch ${LILYPAD_VERSION}

# Build
RUN cd lilypad && CGO_ENABLED=0 go build -o /go/bin/lilypad

# Bacalhau
# For bacalhau cli
FROM ghcr.io/bacalhau-project/bacalhau:${BACALHAU_VERSION:-v1.2.0} as bacalhau

#Final
FROM public.ecr.aws/docker/library/busybox:1.32.0-glibc

# COPY from builder
COPY --from=builder /go/bin/lilypad /usr/local/bin/lilypad
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

# COPY bacalhau cli
COPY --from=bacalhau --chmod=755 /usr/local/bin/bacalhau /usr/local/bin/bacalhau

COPY run.sh /run.sh

RUN chmod +x /usr/local/bin/lilypad /run.sh /usr/local/bin/bacalhau

RUN mkdir -p /var/tmp/

ENV PATH="/usr/local/bin:/usr/bin"
ENTRYPOINT ["/run.sh"]
12 changes: 12 additions & 0 deletions docker/images/lilypad/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -eoux pipefail

# Create bacalhau config
/usr/local/bin/bacalhau version

if [ -f /app/lilypad/.env ]; then
source /app/lilypad/.env
fi

exec /usr/local/bin/lilypad $@