From 05aebabba7ba19110b28370f31532dff252003ac Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Wed, 12 Jun 2024 13:03:29 +0300 Subject: [PATCH] add gen flist script --- scripts/deploy_garage.sh | 4 +- scripts/gen_flist.sh | 83 +++++++++++++++++++++++++++++++++++++++ scripts/manage_buckets.sh | 2 + 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100755 scripts/gen_flist.sh diff --git a/scripts/deploy_garage.sh b/scripts/deploy_garage.sh index ee9ce92..9a96fcc 100755 --- a/scripts/deploy_garage.sh +++ b/scripts/deploy_garage.sh @@ -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}') @@ -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}') diff --git a/scripts/gen_flist.sh b/scripts/gen_flist.sh new file mode 100755 index 0000000..586c708 --- /dev/null +++ b/scripts/gen_flist.sh @@ -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 +sudo apt-get install -y ca-certificates curl +sudo install -m 0755 -d /etc/apt/keyrings +sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc +sudo 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 +sudo ./aws/install + +cat > ~/.awsrc <