From 089ae58901e3980693db03bcc3dccd1b9693f3d3 Mon Sep 17 00:00:00 2001 From: Ryoichi Ando Date: Thu, 26 Dec 2024 13:38:41 +0900 Subject: [PATCH] CI files update --- .github/workflows/vast-all.yml | 1 - .github/workflows/vast-single.yml | 1 - .github/workflows/vast/provision.sh | 114 +++++++++++++++------------- 3 files changed, 63 insertions(+), 53 deletions(-) diff --git a/.github/workflows/vast-all.yml b/.github/workflows/vast-all.yml index dea0828..a1e7380 100644 --- a/.github/workflows/vast-all.yml +++ b/.github/workflows/vast-all.yml @@ -9,7 +9,6 @@ on: inputs: runner: type: string - default: self-hosted required: true description: 'Runner Name' diff --git a/.github/workflows/vast-single.yml b/.github/workflows/vast-single.yml index e270606..da4cec0 100644 --- a/.github/workflows/vast-single.yml +++ b/.github/workflows/vast-single.yml @@ -9,7 +9,6 @@ on: inputs: runner: type: string - default: self-hosted required: true description: 'Runner Name' scene: diff --git a/.github/workflows/vast/provision.sh b/.github/workflows/vast/provision.sh index dfd24b5..c46d95f 100644 --- a/.github/workflows/vast/provision.sh +++ b/.github/workflows/vast/provision.sh @@ -2,43 +2,54 @@ # Author: Ryoichi Ando (ryoichi.ando@zozo.com) # License: Apache v2.0 -# Check if $1 is not set (empty) -if [ -z "$1" ]; then - echo "Error: Argument not provided" - exit 1 -fi +# set working directory +WORKDIR=/tmp/vast-ci -# set api key -VAST_API_KEY=$1 +if [ -d "$WORKDIR" ]; then + echo "$WORKDIR already exists." + cd $WORKDIR + source $WORKDIR/venv/bin/activate +else + echo "Setting up..." -# create a working directory -WORKDIR=/tmp/vast-ci -rm -rf $WORKDIR -mkdir -p $WORKDIR -cd $WORKDIR + # Check if $1 is not set (empty) + if [ -z "$1" ]; then + echo "Error: Argument not provided" + exit 1 + fi + + # set api key + VAST_API_KEY=$1 -# create virtual env -echo "create virtual env" -python3 -m venv $WORKDIR/venv + # create a working directory + rm -rf $WORKDIR + mkdir -p $WORKDIR + cd $WORKDIR -# activate virtual env -source $WORKDIR/venv/bin/activate + # create virtual env + echo "create virtual env" + python3 -m venv $WORKDIR/venv -# install requests -echo "install requests" -pip3 install requests + # activate virtual env + source $WORKDIR/venv/bin/activate -# download the vast CLI -echo "download vast CLI" -wget https://raw.githubusercontent.com/vast-ai/vast-python/master/vast.py -O vast -chmod +x vast + # install requests + echo "install requests" + pip3 install requests -# set api key -./vast set api-key $VAST_API_KEY + # download the vast CLI + echo "download vast CLI" + wget https://raw.githubusercontent.com/vast-ai/vast-python/master/vast.py -O vast + chmod +x vast -# generate a new SSH key -echo "generate a new SSH key" -ssh-keygen -q -t ed25519 -N '' -f $WORKDIR/id_ed25519 + # set api key + ./vast set api-key $VAST_API_KEY + + # generate a new SSH key + echo "generate a new SSH key" + ssh-keygen -q -t ed25519 -N '' -f $WORKDIR/id_ed25519 + +fi # your local public ssh key SSH_PUB_KEY=$WORKDIR/id_ed25519.pub @@ -60,23 +71,23 @@ MAX_RETRIES=10 # https://vast.ai/docs/cli/commands query="" -query+="reliability > 0.99 " # high reliability -query+="num_gpus=1 " # single gpu -query+="gpu_name=$GPU_NAME " # GPU +query+="reliability > 0.99 " # high reliability +query+="num_gpus=1 " # single gpu +query+="gpu_name=$GPU_NAME " # GPU query+="driver_version >= 535.154.05 " # driver version -query+="cuda_vers >= 11.8 " # cuda version -query+="compute_cap >= 750 " # compute capability -query+="geolocation in [US] " # country US,CA,IS,TW,VN,GB,NO -query+="rentable=True " # rentable only -query+="verified=True " # verified by vast.ai -query+="disk_space >= $DISK_SPACE " # available disk space -query+="dph <= 1.0 " # less than $1 per hour -query+="duration >= 2 " # at least 2 days online -query+="inet_up >= 200 " # at least 200MB/s upload -query+="inet_down >= 200 " # at least 200MB/s download -query+="cpu_ram >= 32 " # at least 32GB ram -query+="inet_up_cost <= 0.25 " # upload cheaper than $0.25/GB -query+="inet_down_cost <= 0.25 " # download cheaper than $0.25/GB +query+="cuda_vers >= 11.8 " # cuda version +query+="compute_cap >= 750 " # compute capability +query+="geolocation in [US] " # country US,CA,IS,TW,VN,GB,NO +query+="rentable=True " # rentable only +query+="verified=True " # verified by vast.ai +query+="disk_space >= $DISK_SPACE " # available disk space +query+="dph <= 1.0 " # less than $1 per hour +query+="duration >= 2 " # at least 2 days online +query+="inet_up >= 200 " # at least 200MB/s upload +query+="inet_down >= 200 " # at least 200MB/s download +query+="cpu_ram >= 32 " # at least 32GB ram +query+="inet_up_cost <= 0.25 " # upload cheaper than $0.25/GB +query+="inet_down_cost <= 0.25 " # download cheaper than $0.25/GB TRIED_LIST=() while true; do @@ -85,14 +96,14 @@ while true; do if [ ${#TRIED_LIST[@]} -gt 0 ]; then condition="host_id not in [" for host_id in "${TRIED_LIST[@]}"; do - condition+="$host_id," + condition+="$host_id," done condition="${condition%,}" condition+="]" else condition="" fi - + OFFER_CMD="./vast search offers \"$query $condition\" -o 'dph' --raw" echo $OFFER_CMD OFFER=$(eval $OFFER_CMD) @@ -128,7 +139,7 @@ while true; do fi # write down the delete command - echo "source $WORKDIR/venv/bin/activate; $WORKDIR/vast destroy instance $INSTANCE_ID" > $WORKDIR/delete-instance.sh + echo "source $WORKDIR/venv/bin/activate; $WORKDIR/vast destroy instance $INSTANCE_ID" >$WORKDIR/delete-instance.sh chmod +x $WORKDIR/delete-instance.sh # register ssh key @@ -137,13 +148,13 @@ while true; do # write the ssh command to a file ssh_command="ssh -i $WORKDIR/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 $(./vast ssh-url $INSTANCE_ID)" - echo "$ssh_command \$@" > $WORKDIR/ssh-command.sh + echo "$ssh_command \$@" >$WORKDIR/ssh-command.sh chmod +x $WORKDIR/ssh-command.sh # write the rsync command to a file port=$(echo $(./vast ssh-url $INSTANCE_ID) | sed -E 's/^.*:(.*)$/\1/') hostname=$(echo $(./vast ssh-url $INSTANCE_ID) | sed -E 's/^[a-zA-Z]+:\/\/[a-zA-Z0-9._-]+@([^:]+):.*/\1/') - echo "rsync -avz --exclude='.git' --exclude='asset' -e \"ssh -i $WORKDIR/id_ed25519 -o StrictHostKeyChecking=no -p $port\" . root@${hostname}:/root/ppf-contact-solver" > $WORKDIR/rsync-command.sh + echo "rsync -avz --exclude='.git' --exclude='asset' -e \"ssh -i $WORKDIR/id_ed25519 -o StrictHostKeyChecking=no -p $port\" . root@${hostname}:/root/ppf-contact-solver" >$WORKDIR/rsync-command.sh chmod +x $WORKDIR/rsync-command.sh # Loop until SSH connection is successful @@ -170,4 +181,5 @@ while true; do if [ "$ssh_ready" = true ]; then break fi -done \ No newline at end of file +done +