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 <nabarun@deepstacksoft.com>
This commit is contained in:
prathamesh0 2023-12-14 17:28:10 +05:30 committed by GitHub
parent 9ba410b095
commit b9b758bfdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 294 additions and 29 deletions

View File

@ -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:

View File

@ -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/

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
set -e set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then if [ -n "$CERC_SCRIPT_DEBUG" ]; then

View File

@ -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'
==

View File

@ -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
--

View File

@ -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
--

View File

@ -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
--

View File

@ -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
--

View File

@ -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

View File

@ -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" ]

View File

@ -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}

View File

@ -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: "<PASSWORD>\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
```

View File

@ -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

View File

@ -1,17 +1,17 @@
# self-hosted osmosis # self-hosted osmosis
Instructions to build and deploy: Instructions to build and deploy:
- self-hosted gitea - Self-hosted gitea
- an ipfs node - An ipfs node
- the osmosis front end - The osmosis front end
- a laconicd chain - A laconicd chain
## Setup ## Setup
Clone required repositories: Clone required repositories:
```bash ```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 # 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
``` ```

View File

@ -13,7 +13,7 @@ containers:
- cerc/watcher-ts - cerc/watcher-ts
- cerc/osmosis-front-end - cerc/osmosis-front-end
pods: pods:
- kubo # - kubo
- proxy-server - proxy-server
- osmosis-front-end - osmosis-front-end
# TODO: Fix pod config for deployment command # TODO: Fix pod config for deployment command

View File

@ -14,7 +14,7 @@ Clone required repositories:
```bash ```bash
laconic-so --stack uniswap-urbit-app setup-repositories --pull 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: 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: Edit `network` in spec file to map container ports to same ports in host:
``` ```yml
... ...
network: network:
ports: 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 * 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 laconic-so deployment --dir uniswap-urbit-app-deployment logs -f
# Expected output: # Expected output:
# laconic-3ccf7ee79bdae874-urbit-fake-ship-1 | docket: fetching %http glob for %uniswap desk # 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 * The uniswap app will be now visible at http://localhost:8080

View File

@ -6,7 +6,6 @@ repos:
containers: containers:
- cerc/uniswap-interface - cerc/uniswap-interface
- cerc/watcher-ts - cerc/watcher-ts
- cerc/urbit-globs-host
pods: pods:
- uniswap-interface - uniswap-interface
- proxy-server - proxy-server