Use IPFS for hosting glob files for Urbit (#677)

* Use IPFS for hosting glob files for Urbit

* Add env configuration for IPFS endpoints to instructions

* Make ship pier dir configurable in remote deployment script

* Update remote deployment script to accept glob hash arg
This commit is contained in:
prathamesh0
2023-12-05 15:00:03 +05:30
committed by GitHub
parent 2dd54892a1
commit f27da19808
7 changed files with 66 additions and 66 deletions
@@ -4,6 +4,11 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
echo "Using IPFS endpoint ${CERC_IPFS_GLOB_HOST_ENDPOINT} for hosting globs"
echo "Using IPFS server endpoint ${CERC_IPFS_SERVER_ENDPOINT} for reading glob files"
ipfs_host_endpoint=${CERC_IPFS_GLOB_HOST_ENDPOINT}
ipfs_server_endpoint=${CERC_IPFS_SERVER_ENDPOINT}
uniswap_app_build='/app-builds/uniswap/build'
uniswap_desk_dir='/urbit/zod/uniswap'
@@ -96,15 +101,17 @@ rm "${uniswap_desk_dir}/desk.ship"
hood "commit %uniswap"
dojo "-landscape!make-glob %uniswap /build"
echo "Copying over glob file to mounted volume"
mkdir -p /app-globs/uniswap
cp /urbit/zod/.urb/put/* /app-globs/uniswap/
glob_file=$(ls -1 -c zod/.urb/put | head -1)
echo "Glob filename: ${glob_file}"
echo "Created glob file: ${glob_file}"
upload_response=$(curl -X POST -F file=@./zod/.urb/put/${glob_file} ${ipfs_host_endpoint}/api/v0/add)
glob_cid=$(echo "$upload_response" | grep -o '"Hash":"[^"]*' | sed 's/"Hash":"//')
echo "Glob file uploaded to IFPS:"
echo "{ cid: ${glob_cid}, filename: ${glob_file} }"
# Curl and wait for the glob to be hosted
glob_url="http://uniswap-glob-host:3000/${glob_file}"
glob_url="${ipfs_server_endpoint}/ipfs/${glob_cid}?filename=${glob_file}"
echo "Checking if glob file hosted at ${glob_url}"
while true; do
@@ -128,7 +135,7 @@ cat << EOF > "${uniswap_desk_dir}/desk.docket-0"
color+0xcd.75df
image+'https://logowik.com/content/uploads/images/uniswap-uni7403.jpg'
base+'uniswap'
glob-http+['http://uniswap-glob-host:3000/${glob_file}' ${glob_hash}]
glob-http+['${glob_url}' ${glob_hash}]
version+[0 0 1]
website+'https://uniswap.org/'
license+'MIT'
@@ -1,23 +0,0 @@
#!/bin/bash
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Use config from mounted volume (when running web-app along with watcher stack)
echo "Waiting for uniswap app glob"
while [ ! -d /app-globs/uniswap ]; do
echo "Glob directory not found, retrying in 5 seconds..."
sleep 5
done
# Copy to a new globs directory
mkdir -p globs
cp -r /app-globs/uniswap/* ./globs
# Serve the glob file
cd globs
echo "Hosting glob file at port 3000"
python3 -m http.server 3000 --bind 0.0.0.0
@@ -1,21 +1,22 @@
#!/bin/bash
# $1: Glob file URL (eg. https://xyz.com/glob-abcd.glob)
# $2: Uniswap desk dir (default: ./zod/uniswap)
# $1: Glob file URL (eg. https://xyz.com/glob-0vabcd.glob)
# $2: Glob file hash (eg. 0vabcd)
# $3: Urbit ship's pier dir (default: ./zod)
if [ -z "$1" ]; then
echo "Glob file URL arg not provided"
if [ "$#" -lt 2 ]; then
echo "Insufficient arguments"
exit 0
fi
glob_url=$1
glob_file=$(basename "$glob_url")
glob_hash=$(echo "$glob_file" | sed "s/glob-\([a-z0-9\.]*\).glob/\1/")
echo "Using glob file ${glob_file}"
glob_hash=$2
echo "Using glob file from ${glob_url} with hash ${glob_hash}"
# Default pier dir: ./zod
# Default desk dir: ./zod/uniswap
uniswap_desk_dir="${2:-./zod/uniswap}"
pier_dir="${3:-./zod}"
uniswap_desk_dir="${pier_dir}/uniswap"
echo "Using ${uniswap_desk_dir} as the Uniswap desk dir path"
# Fire curl requests to perform operations on the ship
@@ -1,18 +1,21 @@
#!/bin/bash
# $1: Remote user host
# $2: Path to run the app installation in (where urbit ship dir is located)
# $3: Glob file URL (eg. https://xyz.com/glob-abcd.glob)
# $2: Remote Urbit ship's pier dir path (eg. /home/user/zod)
# $3: Glob file URL (eg. https://xyz.com/glob-0vabcd.glob)
# $4: Glob file hash (eg. 0vabcd)
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <username@remote_host> </path/to/remote/folder> <glob_url>"
if [ "$#" -ne 4 ]; then
echo "Incorrect number of arguments"
echo "Usage: $0 <username@remote_host> </path/to/remote/pier/folder> <glob_url> <glob_hash>"
exit 1
fi
remote_user_host="$1"
remote_folder="$2"
remote_pier_folder="$2"
glob_url="$3"
glob_hash="$4"
installation_script="./install-uniswap-app.sh"
ssh "$remote_user_host" "cd $remote_folder && bash -s $glob_url" < "$installation_script"
ssh "$remote_user_host" "bash -s $glob_url $glob_hash $remote_pier_folder" < "$installation_script"