From b9b758bfdda091a4ea367e21fe1e06be9a18a1a0 Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:28:10 +0530 Subject: [PATCH] Add a stack for running Osmosis frontend app on Urbit (#683) * Deploy osmosis on Urbit fake ship * Remove Urbit configuration from existing osmosis stack * Add a separate stack for Osmosis front end on Urbit * Run script for renaming build files with bash * Add environment variables required in urbit osmosis build * Fix BASEPATH in compose file * Remove ipfs-glob-host from network config in osmosis readme * Use laconic branch for osmosis frontend --------- Co-authored-by: Nabarun --- ...docker-compose-osmosis-front-end-urbit.yml | 20 +++ .../config/osmosis/build-app-for-urbit.sh | 22 +++ .../data/config/osmosis/build-app.sh | 2 +- .../config/osmosis/urbit-files/desk.docket-0 | 10 ++ .../config/osmosis/urbit-files/mar/ico.hoon | 12 ++ .../config/osmosis/urbit-files/mar/jpg.hoon | 12 ++ .../config/osmosis/urbit-files/mar/map.hoon | 18 ++ .../config/osmosis/urbit-files/mar/webp.hoon | 12 ++ .../cerc-osmosis-front-end-urbit/build.sh | 4 + .../cerc-urbit-globs-host/Dockerfile | 7 - .../cerc-urbit-globs-host/build.sh | 9 - .../data/stacks/osmosis-urbit-app/README.md | 158 ++++++++++++++++++ .../data/stacks/osmosis-urbit-app/stack.yml | 13 ++ .../data/stacks/osmosis/README.md | 10 +- .../data/stacks/osmosis/stack.yml | 2 +- .../data/stacks/uniswap-urbit-app/README.md | 11 +- .../data/stacks/uniswap-urbit-app/stack.yml | 1 - 17 files changed, 294 insertions(+), 29 deletions(-) create mode 100644 stack_orchestrator/data/compose/docker-compose-osmosis-front-end-urbit.yml create mode 100755 stack_orchestrator/data/config/osmosis/build-app-for-urbit.sh create mode 100644 stack_orchestrator/data/config/osmosis/urbit-files/desk.docket-0 create mode 100644 stack_orchestrator/data/config/osmosis/urbit-files/mar/ico.hoon create mode 100644 stack_orchestrator/data/config/osmosis/urbit-files/mar/jpg.hoon create mode 100644 stack_orchestrator/data/config/osmosis/urbit-files/mar/map.hoon create mode 100644 stack_orchestrator/data/config/osmosis/urbit-files/mar/webp.hoon create mode 100755 stack_orchestrator/data/container-build/cerc-osmosis-front-end-urbit/build.sh delete mode 100644 stack_orchestrator/data/container-build/cerc-urbit-globs-host/Dockerfile delete mode 100755 stack_orchestrator/data/container-build/cerc-urbit-globs-host/build.sh create mode 100644 stack_orchestrator/data/stacks/osmosis-urbit-app/README.md create mode 100644 stack_orchestrator/data/stacks/osmosis-urbit-app/stack.yml diff --git a/stack_orchestrator/data/compose/docker-compose-osmosis-front-end-urbit.yml b/stack_orchestrator/data/compose/docker-compose-osmosis-front-end-urbit.yml new file mode 100644 index 00000000..238231f4 --- /dev/null +++ b/stack_orchestrator/data/compose/docker-compose-osmosis-front-end-urbit.yml @@ -0,0 +1,20 @@ +version: "3.2" + +services: + osmosis-front-end: + image: cerc/osmosis-front-end-urbit:local + restart: on-failure + environment: + - NEXT_PUBLIC_WEB_API_BASE_URL=${CERC_WEB_API_BASE_URL} + - NEXT_PUBLIC_BASEPATH=/apps/osmosis + - NEXT_PUBLIC_URBIT_DEPLOYMENT=true + working_dir: /app/packages/web + command: ["./build-app-for-urbit.sh"] + volumes: + - ../config/osmosis/build-app-for-urbit.sh:/app/packages/web/build-app-for-urbit.sh + - urbit_app_builds:/app-builds + - ../config/osmosis/urbit-files/mar:/app/packages/web/mar + - ../config/osmosis/urbit-files/desk.docket-0:/app/packages/web/desk.docket-0 + +volumes: + urbit_app_builds: diff --git a/stack_orchestrator/data/config/osmosis/build-app-for-urbit.sh b/stack_orchestrator/data/config/osmosis/build-app-for-urbit.sh new file mode 100755 index 00000000..1f7dba41 --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/build-app-for-urbit.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +# Check and exit if a deployment already exists (on restarts) +if [ -d /app-builds/osmosis/build ]; then + echo "Build already exists, remove volume to rebuild" + exit 0 +fi + +yarn build:static +./build.sh + +# Move build to app-builds +mkdir -p /app-builds/osmosis +cp -r ./out /app-builds/osmosis/build + +cp -r mar /app-builds/osmosis/ +cp desk.docket-0 /app-builds/osmosis/ diff --git a/stack_orchestrator/data/config/osmosis/build-app.sh b/stack_orchestrator/data/config/osmosis/build-app.sh index 2f3cfd01..9d13bbc3 100755 --- a/stack_orchestrator/data/config/osmosis/build-app.sh +++ b/stack_orchestrator/data/config/osmosis/build-app.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e if [ -n "$CERC_SCRIPT_DEBUG" ]; then diff --git a/stack_orchestrator/data/config/osmosis/urbit-files/desk.docket-0 b/stack_orchestrator/data/config/osmosis/urbit-files/desk.docket-0 new file mode 100644 index 00000000..969d6349 --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/urbit-files/desk.docket-0 @@ -0,0 +1,10 @@ +:~ title+'Osmosis' + info+'Self-hosted osmosis frontend.' + color+0xcd.75df + image+'https://logowik.com/content/uploads/images/osmosis8548.logowik.com.webp' + base+'osmosis' + glob-http+['REPLACE_WITH_GLOB_URL' REPLACE_WITH_GLOB_HASH] + version+[0 0 1] + website+'https://osmosis.zone/' + license+'MIT' +== diff --git a/stack_orchestrator/data/config/osmosis/urbit-files/mar/ico.hoon b/stack_orchestrator/data/config/osmosis/urbit-files/mar/ico.hoon new file mode 100644 index 00000000..e862b9b9 --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/urbit-files/mar/ico.hoon @@ -0,0 +1,12 @@ +|_ dat=@ +++ grow + |% + ++ mime [/image/x-icon (as-octs:mimes:html dat)] + -- +++ grab + |% + ++ mime |=([p=mite q=octs] q.q) + ++ noun @ + -- +++ grad %mime +-- diff --git a/stack_orchestrator/data/config/osmosis/urbit-files/mar/jpg.hoon b/stack_orchestrator/data/config/osmosis/urbit-files/mar/jpg.hoon new file mode 100644 index 00000000..81a77d46 --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/urbit-files/mar/jpg.hoon @@ -0,0 +1,12 @@ +|_ dat=@ +++ grow + |% + ++ mime [/image/jpeg (as-octs:mimes:html dat)] + -- +++ grab + |% + ++ mime |=([p=mite q=octs] q.q) + ++ noun @ + -- +++ grad %mime +-- diff --git a/stack_orchestrator/data/config/osmosis/urbit-files/mar/map.hoon b/stack_orchestrator/data/config/osmosis/urbit-files/mar/map.hoon new file mode 100644 index 00000000..e5d61eee --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/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/osmosis/urbit-files/mar/webp.hoon b/stack_orchestrator/data/config/osmosis/urbit-files/mar/webp.hoon new file mode 100644 index 00000000..1909d0dd --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/urbit-files/mar/webp.hoon @@ -0,0 +1,12 @@ +|_ dat=@ +++ grow + |% + ++ mime [/image/webp (as-octs:mimes:html dat)] + -- +++ grab + |% + ++ mime |=([p=mite q=octs] q.q) + ++ noun @ + -- +++ grad %mime +-- diff --git a/stack_orchestrator/data/container-build/cerc-osmosis-front-end-urbit/build.sh b/stack_orchestrator/data/container-build/cerc-osmosis-front-end-urbit/build.sh new file mode 100755 index 00000000..9a47ada9 --- /dev/null +++ b/stack_orchestrator/data/container-build/cerc-osmosis-front-end-urbit/build.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# Build the osmosis front end image +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh +docker build -t cerc/osmosis-front-end-urbit:local -f ${CERC_REPO_BASE_DIR}/osmosis-frontend/docker/Dockerfile.static ${build_command_args} ${CERC_REPO_BASE_DIR}/osmosis-frontend diff --git a/stack_orchestrator/data/container-build/cerc-urbit-globs-host/Dockerfile b/stack_orchestrator/data/container-build/cerc-urbit-globs-host/Dockerfile deleted file mode 100644 index 7a3ca9b7..00000000 --- a/stack_orchestrator/data/container-build/cerc-urbit-globs-host/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3.13.0a2-alpine3.18 - -RUN apk --update --no-cache add alpine-sdk jq bash curl wget - -WORKDIR /app - -ENTRYPOINT [ "bash" ] diff --git a/stack_orchestrator/data/container-build/cerc-urbit-globs-host/build.sh b/stack_orchestrator/data/container-build/cerc-urbit-globs-host/build.sh deleted file mode 100755 index ebd396f1..00000000 --- a/stack_orchestrator/data/container-build/cerc-urbit-globs-host/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# Build the urbit-globs-host image - -source ${CERC_CONTAINER_BASE_DIR}/build-base.sh - -# See: https://stackoverflow.com/a/246128/1701505 -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -docker build -t cerc/urbit-globs-host:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${SCRIPT_DIR} diff --git a/stack_orchestrator/data/stacks/osmosis-urbit-app/README.md b/stack_orchestrator/data/stacks/osmosis-urbit-app/README.md new file mode 100644 index 00000000..59da7411 --- /dev/null +++ b/stack_orchestrator/data/stacks/osmosis-urbit-app/README.md @@ -0,0 +1,158 @@ +# Self-hosted Osmosis Front End On Urbit + +Instructions to build and deploy: +- Urbit +- An ipfs node +- The osmosis front end + +## Setup + +Clone required repositories: + +```bash +laconic-so --stack osmosis-urbit-app setup-repositories --pull + +# If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories and re-run the command +``` + +Build the container images: + +```bash +laconic-so --stack osmosis-urbit-app build-containers +``` + +## Create a deployment + +First, create a spec file for the deployment, which will map the stack's ports and volumes to the host: + +```bash +laconic-so --stack osmosis-urbit-app deploy init --output osmosis-urbit-app-spec.yml +``` + +### Ports + +Edit `network` in spec file to map container ports to same ports in host: + +```yml +... +network: + ports: + urbit-fake-ship: + - '8080:80' + proxy-server: + - '4000:4000' + ipfs: + - '8081:8080' + - '5001:5001' +``` + +Note: Skip the `ipfs` ports if need to use an externally running IPFS node + +### Data volumes + +Container data volumes are bind-mounted to specified paths in the host filesystem. +The default setup (generated by `laconic-so deploy init`) places the volumes in the `./data` subdirectory of the deployment directory. The default mappings can be customized by editing the "spec" file generated by `laconic-so deploy init`. + +--- + +Once you've made any needed changes to the spec file, create a deployment from it: + +```bash +laconic-so --stack osmosis-urbit-app deploy create --spec-file osmosis-urbit-app-spec.yml --deployment-dir osmosis-urbit-app-deployment +``` + +## Set env variables + +Inside the deployment directory, open the file `config.env` and set the following env variables: + +(Note: Use the following config as is if running the stack locally) + + ```bash + # App to be installed (Do not change) + CERC_URBIT_APP=osmosis + + # Osmosis API base URL + # Set this to proxy server endpoint for osmosis app + # (Eg. http://localhost:4000 - in case stack is being run locally with proxy enabled) + # (Eg. https://abc.xyz.com - in case https://abc.xyz.com is pointed to the proxy endpoint) + CERC_WEB_API_BASE_URL=http://localhost:4000 + + # Optional + + # Whether to enable app installation on Urbit + # (just builds and uploads the glob file if disabled) (Default: true) + CERC_ENABLE_APP_INSTALL= + + # Whether to run the proxy server + # (Disable only if proxy not required to be run) (Default: true) + CERC_ENABLE_PROXY= + + # Proxy server configuration + # Used only if proxy is enabled + + # Upstream API URL + CERC_PROXY_UPSTREAM=https://app.osmosis.zone + + # IPFS configuration + + # IFPS endpoint to host the glob file on + # (Default: http://ipfs:5001 pointing to in-stack IPFS node) + CERC_IPFS_GLOB_HOST_ENDPOINT= + + # IFPS endpoint to fetch the glob file from + # (Default: http://ipfs:8080 pointing to in-stack IPFS node) + CERC_IPFS_SERVER_ENDPOINT= + ``` + +## Start the stack + +Start the deployment: + +```bash +laconic-so deployment --dir osmosis-urbit-app-deployment start +``` + +* List and check the health status of all the containers using `docker ps` and wait for them to be `healthy` + +* Run the following to get login password for Urbit web interface: + + ```bash + laconic-so deployment --dir osmosis-urbit-app-deployment exec urbit-fake-ship "curl -s --data '{\"source\":{\"dojo\":\"+code\"},\"sink\":{\"stdout\":null}}' http://localhost:12321" + + # Expected output: "\n"% + ``` + +* Open the Urbit web UI at http://localhost:8080 and use the `PASSWORD` from previous step to login + +* The osmosis app is not available when starting stack for the first time. Check `urbit-fake-ship` logs to see that app has installed: + + ```bash + laconic-so deployment --dir osmosis-urbit-app-deployment logs -f + + # Expected output: + # laconic-3ccf7ee79bdae874-urbit-fake-ship-1 | docket: fetching %http glob for %osmosis desk + # laconic-3ccf7ee79bdae874-urbit-fake-ship-1 | ">="">="osmosis app installed + ``` + +* The osmosis app will be now visible at http://localhost:8080 + +## Clean up + +To stop all osmosis-urbit-app services running in the background, while preserving data: + +```bash +# Only stop the docker containers +laconic-so deployment --dir osmosis-urbit-app-deployment stop + +# Run 'start' to restart the deployment +``` + +To stop all osmosis-urbit-app services and also delete data: + +```bash +# Stop the docker containers +laconic-so deployment --dir osmosis-urbit-app-deployment stop --delete-volumes + +# Remove deployment directory (deployment will have to be recreated for a re-run) +rm -r osmosis-urbit-app-deployment +``` diff --git a/stack_orchestrator/data/stacks/osmosis-urbit-app/stack.yml b/stack_orchestrator/data/stacks/osmosis-urbit-app/stack.yml new file mode 100644 index 00000000..2cf3e9fd --- /dev/null +++ b/stack_orchestrator/data/stacks/osmosis-urbit-app/stack.yml @@ -0,0 +1,13 @@ +version: "0.1" +name: osmosis-urbit-app +repos: + - github.com/cerc-io/osmosis-frontend@laconic + - github.com/cerc-io/watcher-ts@v0.2.78 +containers: + - cerc/osmosis-front-end-urbit + - cerc/watcher-ts +pods: + - osmosis-front-end-urbit + - proxy-server + - fixturenet-urbit + - kubo diff --git a/stack_orchestrator/data/stacks/osmosis/README.md b/stack_orchestrator/data/stacks/osmosis/README.md index ef5504ae..54cda3da 100644 --- a/stack_orchestrator/data/stacks/osmosis/README.md +++ b/stack_orchestrator/data/stacks/osmosis/README.md @@ -1,17 +1,17 @@ # self-hosted osmosis Instructions to build and deploy: -- self-hosted gitea -- an ipfs node -- the osmosis front end -- a laconicd chain +- Self-hosted gitea +- An ipfs node +- The osmosis front end +- A laconicd chain ## Setup Clone required repositories: ```bash -laconic-so --stack osmosis setup-repositories +laconic-so --stack osmosis setup-repositories --pull # If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories and re-run the command ``` diff --git a/stack_orchestrator/data/stacks/osmosis/stack.yml b/stack_orchestrator/data/stacks/osmosis/stack.yml index b0e51a1d..221fbb60 100644 --- a/stack_orchestrator/data/stacks/osmosis/stack.yml +++ b/stack_orchestrator/data/stacks/osmosis/stack.yml @@ -13,7 +13,7 @@ containers: - cerc/watcher-ts - cerc/osmosis-front-end pods: - - kubo + # - kubo - proxy-server - osmosis-front-end # TODO: Fix pod config for deployment command diff --git a/stack_orchestrator/data/stacks/uniswap-urbit-app/README.md b/stack_orchestrator/data/stacks/uniswap-urbit-app/README.md index 7f49c16f..cdbb7f6a 100644 --- a/stack_orchestrator/data/stacks/uniswap-urbit-app/README.md +++ b/stack_orchestrator/data/stacks/uniswap-urbit-app/README.md @@ -14,7 +14,7 @@ Clone required repositories: ```bash laconic-so --stack uniswap-urbit-app setup-repositories --pull -# If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories mentioned below and re-run the command +# If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories and re-run the command ``` Build the container images: @@ -35,7 +35,7 @@ laconic-so --stack uniswap-urbit-app deploy init --output uniswap-urbit-app-spec Edit `network` in spec file to map container ports to same ports in host: -``` +```yml ... network: ports: @@ -134,13 +134,14 @@ laconic-so deployment --dir uniswap-urbit-app-deployment start * Open the Urbit web UI at http://localhost:8080 and use the `PASSWORD` from previous step to login -* The uniswap app is not available when starting stack for the first time. Check `urbit-fake-ship` logs to see that app has installed - ``` +* The uniswap app is not available when starting stack for the first time. Check `urbit-fake-ship` logs to see that app has installed: + + ```bash laconic-so deployment --dir uniswap-urbit-app-deployment logs -f # Expected output: # laconic-3ccf7ee79bdae874-urbit-fake-ship-1 | docket: fetching %http glob for %uniswap desk - # laconic-3ccf7ee79bdae874-urbit-fake-ship-1 | ">="">="Uniswap app installed + # laconic-3ccf7ee79bdae874-urbit-fake-ship-1 | ">="">="uniswap app installed ``` * The uniswap app will be now visible at http://localhost:8080 diff --git a/stack_orchestrator/data/stacks/uniswap-urbit-app/stack.yml b/stack_orchestrator/data/stacks/uniswap-urbit-app/stack.yml index 31499406..1e5ad3f5 100644 --- a/stack_orchestrator/data/stacks/uniswap-urbit-app/stack.yml +++ b/stack_orchestrator/data/stacks/uniswap-urbit-app/stack.yml @@ -6,7 +6,6 @@ repos: containers: - cerc/uniswap-interface - cerc/watcher-ts - - cerc/urbit-globs-host pods: - uniswap-interface - proxy-server