forked from aaronaliascrypto/infernet-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.tpl
More file actions
60 lines (50 loc) · 2.54 KB
/
node.tpl
File metadata and controls
60 lines (50 loc) · 2.54 KB
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
#! /bin/bash
# Directory for deployment files
DIR=~/deploy
# Script to setup a node in an GCP cluster. Startup scripts on GCP run at EVERY boot,
# so no need to set up a cron job to bring services back up on reboot. However, we need
# to ensure that installation of docker, libraries, and GPU drivers only happen once at
# the time of node creation. Therefore, we will check if the /root/deploy/config.json
# file exists and if not, we will assume this is the first boot and install everything.
if [ ! -f "$DIR/config.json" ]; then
cd ~/
sudo apt update
sudo apt-get update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
# Install docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt install -y docker-ce docker-compose-plugin
# Install GPU driver if necessary
GPU="${gpu}"
if [ "$GPU" = "true" ]; then
if ! nvidia-smi &> /dev/null
then
echo "nvidia-smi did not succeed, installing NVIDIA drivers..."
# Install driver
sudo apt-get -y install nvidia-driver-470
# Install container toolkit
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
else
echo "nvidia-smi is already installed."
fi
else
echo "GPU not enabled for this instance."
fi
fi
# Extract deployment files
mkdir -p "$DIR" && cd "$DIR"
curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/deploy-tar -H "Metadata-Flavor: Google"| base64 --decode > deploy.tar.gz
tar -xzvf deploy.tar.gz && rm deploy.tar.gz
# Write config file
curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/secret-config -H "Metadata-Flavor: Google" | base64 --decode > config.json
chmod 600 config.json
# build your local container
sudo docker build -t ritualnetwork/hello-world-infernet:latest .
sudo docker compose up -d