From 07118a2d72fa80fd15d16436cfed688ccf89f122 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 6 Dec 2023 11:39:33 +0530 Subject: [PATCH] Refactor to make Urbit app deployment script generic --- .../docker-compose-uniswap-interface.yml | 7 +- .../compose/docker-compose-uniswap-urbit.yml | 11 +- .../config/uniswap-interface/build-app.sh | 2 +- .../uniswap-interface/deploy-uniswap-app.sh | 141 +++++++----------- .../urbit-files/desk.docket-0 | 10 ++ .../urbit-files/mar/map.hoon | 18 +++ .../urbit-files/mar/ttf.hoon | 12 ++ .../urbit-files/mar/woff.hoon | 12 ++ 8 files changed, 112 insertions(+), 101 deletions(-) create mode 100644 stack_orchestrator/data/config/uniswap-interface/urbit-files/desk.docket-0 create mode 100644 stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/map.hoon create mode 100644 stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/ttf.hoon create mode 100644 stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/woff.hoon diff --git a/stack_orchestrator/data/compose/docker-compose-uniswap-interface.yml b/stack_orchestrator/data/compose/docker-compose-uniswap-interface.yml index 85b71af2..5494ce0a 100644 --- a/stack_orchestrator/data/compose/docker-compose-uniswap-interface.yml +++ b/stack_orchestrator/data/compose/docker-compose-uniswap-interface.yml @@ -9,9 +9,10 @@ services: - REACT_APP_AWS_API_ENDPOINT=${CERC_UNISWAP_GQL} command: ["./build-app.sh"] volumes: - - app_builds:/app-builds - ../config/uniswap-interface/build-app.sh:/app/build-app.sh + - urbit_app_builds:/app-builds + - ../config/uniswap-interface/urbit-files/mar:/app-builds/uniswap/mar + - ../config/uniswap-interface/urbit-files/desk.docket-0:/app-builds/uniswap/desk.docket-0 volumes: - app_builds: - app_globs: + urbit_app_builds: diff --git a/stack_orchestrator/data/compose/docker-compose-uniswap-urbit.yml b/stack_orchestrator/data/compose/docker-compose-uniswap-urbit.yml index 31fa99bf..63aa8036 100644 --- a/stack_orchestrator/data/compose/docker-compose-uniswap-urbit.yml +++ b/stack_orchestrator/data/compose/docker-compose-uniswap-urbit.yml @@ -5,15 +5,15 @@ services: restart: unless-stopped image: tloncorp/vere environment: + CERC_URBIT_APP: ${CERC_URBIT_APP} CERC_IPFS_GLOB_HOST_ENDPOINT: ${CERC_IPFS_GLOB_HOST_ENDPOINT:-http://ipfs-glob-host:5001} CERC_IPFS_SERVER_ENDPOINT: ${CERC_IPFS_SERVER_ENDPOINT:-http://ipfs-glob-host:8080} - entrypoint: ["bash", "-c", "./run-urbit-ship.sh && ./deploy-uniswap-app.sh && tail -f /dev/null"] + entrypoint: ["bash", "-c", "./run-urbit-ship.sh && ./deploy-app.sh && tail -f /dev/null"] volumes: - urbit_data:/urbit - - app_builds:/app-builds - - app_globs:/app-globs + - urbit_app_builds:/app-builds - ../config/urbit/run-urbit-ship.sh:/urbit/run-urbit-ship.sh - - ../config/uniswap-interface/deploy-uniswap-app.sh:/urbit/deploy-uniswap-app.sh + - ../config/uniswap-interface/deploy-uniswap-app.sh:/urbit/deploy-app.sh ports: - "80" healthcheck: @@ -40,7 +40,6 @@ services: volumes: urbit_data: - app_builds: - app_globs: + urbit_app_builds: ipfs-import: ipfs-data: diff --git a/stack_orchestrator/data/config/uniswap-interface/build-app.sh b/stack_orchestrator/data/config/uniswap-interface/build-app.sh index d3b012e6..b2324018 100755 --- a/stack_orchestrator/data/config/uniswap-interface/build-app.sh +++ b/stack_orchestrator/data/config/uniswap-interface/build-app.sh @@ -14,5 +14,5 @@ fi yarn build # Move build to app-builds so urbit can deploy it -mkdir /app-builds/uniswap +mkdir -p /app-builds/uniswap cp -r ./build /app-builds/uniswap/ diff --git a/stack_orchestrator/data/config/uniswap-interface/deploy-uniswap-app.sh b/stack_orchestrator/data/config/uniswap-interface/deploy-uniswap-app.sh index f07a205b..88ac39e1 100755 --- a/stack_orchestrator/data/config/uniswap-interface/deploy-uniswap-app.sh +++ b/stack_orchestrator/data/config/uniswap-interface/deploy-uniswap-app.sh @@ -4,19 +4,39 @@ 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' - -if [ -d ${uniswap_desk_dir} ]; then - echo "Uniswap desk dir already exists, skipping deployment..." +if [ -z "$CERC_URBIT_APP" ]; then + echo "CERC_URBIT_APP not set, exiting" exit 0 fi +echo "Creating Urbit application for ${CERC_URBIT_APP}" + +app_desk_dir=/urbit/zod/${CERC_URBIT_APP} +if [ -d ${app_desk_dir} ]; then + echo "Desk dir already exists for ${CERC_URBIT_APP}, skipping deployment..." + exit 0 +fi + +app_build=/app-builds/${CERC_URBIT_APP}/build +app_mark_files=/app-builds/${CERC_URBIT_APP}/mar +app_docket_file=/app-builds/${CERC_URBIT_APP}/desk.docket-0 + +echo "Reading app build from ${app_build}" +echo "Reading the additional mark files from ${app_mark_files}" +echo "Reading docket file ${app_docket_file}" + +# Loop until the app's build appears +while [ ! -d ${app_build} ]; do + echo "${CERC_URBIT_APP} app build not found, retrying in 5s..." + sleep 5 +done +echo "Build found..." + +echo "Using IPFS endpoint ${CERC_IPFS_GLOB_HOST_ENDPOINT} for hosting the ${CERC_URBIT_APP} glob" +echo "Using IPFS server endpoint ${CERC_IPFS_SERVER_ENDPOINT} for reading ${CERC_URBIT_APP} glob" +ipfs_host_endpoint=${CERC_IPFS_GLOB_HOST_ENDPOINT} +ipfs_server_endpoint=${CERC_IPFS_SERVER_ENDPOINT} + # Fire curl requests to perform operations on the ship dojo () { curl -s --data '{"source":{"dojo":"'"$1"'"},"sink":{"stdout":null}}' http://localhost:12321 @@ -26,80 +46,22 @@ hood () { curl -s --data '{"source":{"dojo":"+hood/'"$1"'"},"sink":{"app":"hood"}}' http://localhost:12321 } -# Create/mount a uniswap desk -hood "merge %uniswap our %landscape" -hood "mount %uniswap" - -# Loop until the uniswap build appears -while [ ! -d ${uniswap_app_build} ]; do - echo "Uniswap app build not found, retrying in 5s..." - sleep 5 -done -echo "Build found..." +# Create / mount the app's desk +hood "merge %${CERC_URBIT_APP} our %landscape" +hood "mount %${CERC_URBIT_APP}" # Copy over build to desk data dir -cp -r ${uniswap_app_build} ${uniswap_desk_dir} +cp -r ${app_build} ${app_desk_dir} -# Create a mark file for .map file type -cat << EOF > "${uniswap_desk_dir}/mar/map.hoon" -:: -:::: /hoon/map/mar - :: Mark for js source maps -/? 310 -:: -=, eyre -|_ mud=@ -++ grow - |% - ++ mime [/application/octet-stream (as-octs:mimes:html (@t mud))] - -- -++ grab - |% :: convert from - ++ mime |=([p=mite q=octs] (@t q.q)) - ++ noun cord :: clam from %noun - -- -++ grad %mime --- -EOF +# Copy over the additional mark files +cp ${app_mark_files}/* ${app_desk_dir}/mar/ -# Create a mark file for .woff file type -cat << EOF > "${uniswap_desk_dir}/mar/woff.hoon" -|_ dat=octs -++ grow - |% - ++ mime [/font/woff dat] - -- -++ grab - |% - ++ mime |=([=mite =octs] octs) - ++ noun octs - -- -++ grad %mime --- -EOF - -# Create a mark file for .ttf file type -cat << EOF > "${uniswap_desk_dir}/mar/ttf.hoon" -|_ dat=octs -++ grow - |% - ++ mime [/font/ttf dat] - -- -++ grab - |% - ++ mime |=([=mite =octs] octs) - ++ noun octs - -- -++ grad %mime --- -EOF - -rm "${uniswap_desk_dir}/desk.bill" -rm "${uniswap_desk_dir}/desk.ship" +rm "${app_desk_dir}/desk.bill" +rm "${app_desk_dir}/desk.ship" # Commit changes and create a glob -hood "commit %uniswap" -dojo "-landscape!make-glob %uniswap /build" +hood "commit %${CERC_URBIT_APP}" +dojo "-landscape!make-glob %${CERC_URBIT_APP} /build" glob_file=$(ls -1 -c zod/.urb/put | head -1) echo "Created glob file: ${glob_file}" @@ -110,6 +72,9 @@ glob_cid=$(echo "$upload_response" | grep -o '"Hash":"[^"]*' | sed 's/"Hash":"// echo "Glob file uploaded to IFPS:" echo "{ cid: ${glob_cid}, filename: ${glob_file} }" +# Flag to skip installation +# Exit here if the installation not required + # Curl and wait for the glob to be hosted glob_url="${ipfs_server_endpoint}/ipfs/${glob_cid}?filename=${glob_file}" @@ -128,19 +93,13 @@ done glob_hash=$(echo "$glob_file" | sed "s/glob-\([a-z0-9\.]*\).glob/\1/") -# Update the docket file -cat << EOF > "${uniswap_desk_dir}/desk.docket-0" -:~ title+'Uniswap' - info+'Self-hosted uniswap frontend.' - color+0xcd.75df - image+'https://logowik.com/content/uploads/images/uniswap-uni7403.jpg' - base+'uniswap' - glob-http+['${glob_url}' ${glob_hash}] - version+[0 0 1] - website+'https://uniswap.org/' - license+'MIT' -== -EOF +# Take the docket file from a volume (/app-builds/uniswap/desk.docket-0) +# Replace glob_url and glob_hash in that (refer landscape CI) + +# Replace the docket file for app +# Substitue the glob URL and hash +cp ${app_docket_file} ${app_desk_dir}/ +sed -i "s|REPLACE_WITH_GLOB_URL|${glob_url}|g; s|REPLACE_WITH_GLOB_HASH|${glob_hash}|g" desk.docket-0 # Commit changes and install the app hood "commit %uniswap" diff --git a/stack_orchestrator/data/config/uniswap-interface/urbit-files/desk.docket-0 b/stack_orchestrator/data/config/uniswap-interface/urbit-files/desk.docket-0 new file mode 100644 index 00000000..6256c41b --- /dev/null +++ b/stack_orchestrator/data/config/uniswap-interface/urbit-files/desk.docket-0 @@ -0,0 +1,10 @@ +:~ title+'Uniswap' + info+'Self-hosted uniswap frontend.' + color+0xcd.75df + image+'https://logowik.com/content/uploads/images/uniswap-uni7403.jpg' + base+'uniswap' + glob-http+['REPLACE_WITH_GLOB_URL' REPLACE_WITH_GLOB_HASH] + version+[0 0 1] + website+'https://uniswap.org/' + license+'MIT' +== diff --git a/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/map.hoon b/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/map.hoon new file mode 100644 index 00000000..e5d61eee --- /dev/null +++ b/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/map.hoon @@ -0,0 +1,18 @@ +:: +:::: /hoon/map/mar + :: Mark for js source maps +/? 310 +:: +=, eyre +|_ mud=@ +++ grow + |% + ++ mime [/application/octet-stream (as-octs:mimes:html (@t mud))] + -- +++ grab + |% :: convert from + ++ mime |=([p=mite q=octs] (@t q.q)) + ++ noun cord :: clam from %noun + -- +++ grad %mime +-- diff --git a/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/ttf.hoon b/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/ttf.hoon new file mode 100644 index 00000000..2d29193e --- /dev/null +++ b/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/ttf.hoon @@ -0,0 +1,12 @@ +|_ dat=octs +++ grow + |% + ++ mime [/font/ttf dat] + -- +++ grab + |% + ++ mime |=([=mite =octs] octs) + ++ noun octs + -- +++ grad %mime +-- diff --git a/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/woff.hoon b/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/woff.hoon new file mode 100644 index 00000000..2933aea7 --- /dev/null +++ b/stack_orchestrator/data/config/uniswap-interface/urbit-files/mar/woff.hoon @@ -0,0 +1,12 @@ +|_ dat=octs +++ grow + |% + ++ mime [/font/woff dat] + -- +++ grab + |% + ++ mime |=([=mite =octs] octs) + ++ noun octs + -- +++ grad %mime +--