forked from Lilypad-Tech/lilypad-modicum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lilypad
97 lines (89 loc) · 3.53 KB
/
lilypad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
### NOTE - THIS SCRIPT HAS TO BE COMPATIBLE WITH OLD VERSIONS OF BASH ON MACOS
### DO NOT PUT declare -g OR {@Q} OR OTHER FANCY THINGS IN IT OR REFACTOR IT TO
### USE FUNCTIONS AND eval "$@" BECAUSE THEN PASSING VARIABLES WITH WHITESPACE
### IN STOPS WORKING
LATEST_TXT="$(curl -sSL https://raw.githubusercontent.com/bacalhau-project/lilypad-modicum/main/latest.txt)"
for X in $LATEST_TXT; do
if echo $X |grep -q git_hash; then
LATEST_GIT_HASH="$(echo $X |cut -d '|' -f 2)"
fi
if echo $X |grep -q contract_address; then
LATEST_CONTRACT_ADDRESS="$(echo $X |cut -d '|' -f 2)"
fi
if echo $X |grep -q mediator_addresses; then
LATEST_MEDIATOR_ADDRESSES="$(echo $X |cut -d '|' -f 2)"
fi
done
export GIT_HASH=${GIT_HASH:="$LATEST_GIT_HASH"}
### export VERSION=${VERSION:="${GIT_HASH}-$(uname -m |sed 's/arm64/aarch64/')"}
export VERSION=${VERSION:="${GIT_HASH}"}
export DOCKER_REGISTRY=${DOCKER_REGISTRY:="quay.io/lilypad"}
export RPC_URL=${RPC_URL:="http://testnet.lilypadnetwork.org:8545"}
export CONTRACT_ADDRESS=${CONTRACT_ADDRESS:=$LATEST_CONTRACT_ADDRESS}
export MEDIATOR_ADDRESSES=${MEDIATOR_ADDRESSES:=$LATEST_MEDIATOR_ADDRESSES}
export IMAGE_BASE=${IMAGE_BASE:="lilypad"}
export IMAGE_MODICUM_NAME=${IMAGE_MODICUM_NAME:="${IMAGE_BASE}-modicum"}
export IMAGE_MODICUM="${DOCKER_REGISTRY}/${IMAGE_MODICUM_NAME}:${VERSION}"
export IMAGE_RESOURCE_PROVIDER_NAME=${IMAGE_RESOURCE_PROVIDER_NAME:="${IMAGE_BASE}-resource-provider"}
export IMAGE_RESOURCE_PROVIDER="${DOCKER_REGISTRY}/${IMAGE_RESOURCE_PROVIDER_NAME}:${VERSION}"
export LILYPAD_NODE_FLAGS=""
if [[ $# -eq 0 ]]; then
echo "Usage: $0 <command> [args]"
echo
echo "Must set PRIVATE_KEY environment variable with your Ethereum key e.g. from metamask"
echo
echo "Commands:"
echo " run - run a client with a job e.g. lilypad run --module cowsay:v0.0.1 --params 'hello'"
echo " serve - run a server"
echo " serve-logs - tail the logs of the server (useful for sharing debugging info)"
echo " stop - stop the server and delete the container (useful for upgrades - run lilypad stop && lilypad serve)"
exit 1
elif [[ $1 == "serve" ]]; then
shift
GPU_ARG=""
GPU_VALUE=""
if [ -f "/usr/bin/nvidia-smi" ]; then
GPU_ARG="--gpus"
GPU_VALUE="all"
fi
# /tmp is for bacalhau to be able to find its own results
docker run -d --restart always --name resource-provider \
-v /tmp:/tmp \
-v /var/run/docker.sock:/var/run/docker.sock \
$GPU_ARG $GPU_VALUE \
-e PRIVATE_KEY \
-e CONTRACT_ADDRESS \
-e CONTRACT_ABI_FILE=/Modicum.json \
-e MEDIATOR_ADDRESSES \
-e RPC_URL \
$IMAGE_RESOURCE_PROVIDER
elif [[ $1 == "run" ]]; then
shift
docker run -ti --rm --name submitjob \
-e PRIVATE_KEY \
-e CONTRACT_ADDRESS \
-e CONTRACT_ABI_FILE=/Modicum.json \
-e MEDIATOR_ADDRESSES \
-e RPC_URL \
$IMAGE_MODICUM \
runLilypadCLI \
"$@"
elif [[ $1 == "serve-logs" ]]; then
trap "sleep 1; reset" EXIT
service="resource-provider"
if [[ "$service" == "solver" ]]; then
docker logs -f solver
fi
docker exec -ti $service supervisorctl tail -f bacalhau-serve stdout &
docker exec -ti $service supervisorctl tail -f bacalhau-serve stderr &
docker exec -ti $service supervisorctl tail -f ipfs stdout &
docker exec -ti $service supervisorctl tail -f ipfs stderr &
docker exec -ti $service supervisorctl tail -f $service stdout &
docker exec -ti $service supervisorctl tail -f $service stderr
exit 0
elif [[ $1 == "stop" ]]; then
docker rm -f resource-provider
fi