Skip to content

Commit

Permalink
add gen flist script
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Jun 12, 2024
1 parent f2c8b9d commit bd48ded
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scripts/deploy_garage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ printf "$MNEMONIC\n$NETWORK\n" | tfcmd login

# Deploy a vm with mycelium and public IP (mycelium not suppoerted yet) for s3 server TODO: mycelium and remove public IP

tfcmd deploy vm --name s3_server --ssh ~/.ssh/id_rsa.pub --cpu 8 --memory 16 --disk 50 --ipv4
tfcmd deploy vm --name s3_server --ssh ~/.ssh/id_rsa.pub --cpu 8 --memory 16 --disk 50 --ipv4 --rootfs 10
sleep 6 # wait deployment
OUTPUT=$(tfcmd get vm s3_server 2>&1 | tail -n +3 | tr { '\n' | tr , '\n' | tr } '\n')
MYCELIUM_IP=$(echo "$OUTPUT" | grep -Eo '"mycelium_ip"[^,]*' | awk -F'"' '{print $4}')
Expand All @@ -43,6 +43,8 @@ PUBLIC_IP=$(echo "$OUTPUT" | grep -Eo '"computedip"[^,]*' | awk -F'"' '{print $
# Deploy a name gateway to expose a domain for garage web
tfcmd deploy gateway name -n $DOMAIN --backends http://$PUBLIC_IP:3902
tfcmd deploy gateway name -n flist.$DOMAIN --backends http://$PUBLIC_IP:3902
tfcmd deploy gateway name -n blobs.$DOMAIN --backends http://$PUBLIC_IP:3902
sleep 6 # wait deployment
OUTPUT=$(tfcmd get gateway name $DOMAIN 2>&1 | tail -n +3 | tr { '\n' | tr , '\n' | tr } '\n')
FQDN=$(echo "$OUTPUT" | grep -Eo '"FQDN"[^,]*' | awk -F'"' '{print $4}')
Expand Down
83 changes: 83 additions & 0 deletions scripts/gen_flist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

set -ex

if [ -z ${IMAGE+x} ]
then
echo 'Error! $IMAGE is required.'
exit 64
fi

if [ -z ${PUBLIC_IP+x} ]
then
echo 'Error! $PUBLIC_IP is required.'
exit 64
fi

if [ -z ${WRITE_KEY_ID+x} ]
then
echo 'Error! $WRITE_KEY_ID is required.'
exit 64
fi

if [ -z ${WRITE_KEY_SECRET+x} ]
then
echo 'Error! $WRITE_KEY_SECRET is required.'
exit 64
fi

# Install docker2fl tool

ssh root@$PUBLIC_IP "
apt-get update
apt-get install -y curl
curl https://sh.rustup.rs -sSf | sh
export PATH="$HOME/.cargo/bin:$PATH"
apt-get install -y build-essential
apt-get install -y musl-tools
apt-get install -y git
apt-get update
# Install docker
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
git clone https://github.com/threefoldtech/rfs.git
cd rfs
rustup target add x86_64-unknown-linux-musl
cargo build --release --target=x86_64-unknown-linux-musl
mv ./target/x86_64-unknown-linux-musl/release/docker2fl /usr/local/bin
"

# Convert docker image to a flist using docker2fl

ssh root@$PUBLIC_IP "docker2fl -i $IMAGE -s 's3://$WRITE_KEY_ID:$WRITE_KEY_SECRET@$PUBLIC_IP:3900/blobs?region=garage'"

# Upload the generated flist on s3 server flist bucket (use any client for it, aws cli is used here)

ssh root@$PUBLIC_IP "
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
cat > ~/.awsrc <<EOF
export AWS_ACCESS_KEY_ID=$WRITE_KEY_ID # put your Key ID here
export AWS_SECRET_ACCESS_KEY=$WRITE_KEY_SECRET # put your Secret key here
export AWS_DEFAULT_REGION='garage'
export AWS_ENDPOINT_URL='http://$PUBLIC_IP:3900'
aws --version
EOF
source ~/.awsrc
aws s3 cp "threefolddev-ubuntu-22.04.fl" "s3://flist/threefolddev-ubuntu-22.04.fl"
#TODO: # threefolddev/ubuntu:22.04
"
2 changes: 2 additions & 0 deletions scripts/manage_buckets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ garage layout assign -z dc1 -c 1G $NODE_ID
garage layout apply --version 1
garage bucket create blobs
garage bucket create flist
garage bucket website --allow flist
garage bucket website --allow blobs
garage bucket list
"

Expand Down

0 comments on commit bd48ded

Please sign in to comment.