From 9b785bfa43a38e2171203f2d9207221fd2c91384 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Wed, 6 Dec 2023 16:36:55 +0530 Subject: [PATCH] Host osmosis app static build using python server --- .../docker-compose-osmosis-front-end.yml | 22 +++++++++++- .../data/config/osmosis/build-app.sh | 18 ++++++++++ .../cerc-osmosis-front-end/build.sh | 2 +- .../data/stacks/osmosis/README.md | 36 +++++++++++++++---- .../data/stacks/osmosis/stack.yml | 6 ++-- 5 files changed, 74 insertions(+), 10 deletions(-) create mode 100755 stack_orchestrator/data/config/osmosis/build-app.sh diff --git a/stack_orchestrator/data/compose/docker-compose-osmosis-front-end.yml b/stack_orchestrator/data/compose/docker-compose-osmosis-front-end.yml index 663fc7d5..23cea8b4 100644 --- a/stack_orchestrator/data/compose/docker-compose-osmosis-front-end.yml +++ b/stack_orchestrator/data/compose/docker-compose-osmosis-front-end.yml @@ -3,7 +3,24 @@ version: "3.2" services: osmosis-front-end: image: cerc/osmosis-front-end:local - restart: always + restart: on-failure + environment: + - NEXT_PUBLIC_WEB_API_BASE_URL=${CERC_WEB_API_BASE_URL} + working_dir: /app/packages/web + command: ["./build-app.sh"] + volumes: + - ../config/osmosis/build-app.sh:/app/packages/web/build-app.sh + - app_builds:/app-builds + + python-server: + image: python:3 + depends_on: + osmosis-front-end: + condition: service_completed_successfully + restart: on-failure + command: ["python3", "-m", "http.server", "-d" ,"/app-builds/osmosis/build", "4000"] + volumes: + - app_builds:/app-builds ports: - "3000" healthcheck: @@ -12,3 +29,6 @@ services: timeout: 5s retries: 15 start_period: 5s + +volumes: + app_builds: diff --git a/stack_orchestrator/data/config/osmosis/build-app.sh b/stack_orchestrator/data/config/osmosis/build-app.sh new file mode 100755 index 00000000..09813063 --- /dev/null +++ b/stack_orchestrator/data/config/osmosis/build-app.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +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 + +# Move build to app-builds +mkdir /app-builds/osmosis +cp -r ./out /app-builds/osmosis/build diff --git a/stack_orchestrator/data/container-build/cerc-osmosis-front-end/build.sh b/stack_orchestrator/data/container-build/cerc-osmosis-front-end/build.sh index 22f2c346..c4a9f27e 100755 --- a/stack_orchestrator/data/container-build/cerc-osmosis-front-end/build.sh +++ b/stack_orchestrator/data/container-build/cerc-osmosis-front-end/build.sh @@ -1,4 +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:local -f ${CERC_REPO_BASE_DIR}/osmosis-frontend/docker/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/osmosis-frontend +docker build -t cerc/osmosis-front-end: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/stacks/osmosis/README.md b/stack_orchestrator/data/stacks/osmosis/README.md index d3e8421c..663516d5 100644 --- a/stack_orchestrator/data/stacks/osmosis/README.md +++ b/stack_orchestrator/data/stacks/osmosis/README.md @@ -39,15 +39,14 @@ Edit `network` in spec file to map container ports to same ports in host ``` ... ports: - osmosis-front-end: - - '3000:3000' - ipfs: - - 0.0.0.0:8080:8080 - - 0.0.0.0:4001:4001 - - 0.0.0.0:5001:5001 + proxy-server: + - '4000:4000' + python-server: + - '3000:3000' ``` ### 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`. @@ -58,6 +57,31 @@ Once you've made any needed changes to the spec file, create a deployment from i laconic-so --stack osmosis deploy create --spec-file osmosis-spec.yml --deployment-dir osmosis-deployment ``` +## Set env variables + +Inside the deployment directory, open the file `config.env` and set the following env variables: + + ```bash + # Osmosis API base URL + # Set this to proxy server endpoint for uniswap app + # (Eg. http://localhost:4000) + # (Eg. https://abc.xyz.com) + CERC_WEB_API_BASE_URL= + + # Optional + + # TODO: Change to CERC_ENABLE_PROXY after rebase + # Whether to run the proxy server + # (Disable only if proxy not required to be run) (Default: true) + ENABLE_PROXY= + + # Proxy server configuration + # Used only if proxy is enabled + + # Upstream API URL + CERC_PROXY_UPSTREAM=https://app.osmosis.zone + ``` + ## Start the stack Start the deployment: diff --git a/stack_orchestrator/data/stacks/osmosis/stack.yml b/stack_orchestrator/data/stacks/osmosis/stack.yml index 43c49d0b..cc0e4e77 100644 --- a/stack_orchestrator/data/stacks/osmosis/stack.yml +++ b/stack_orchestrator/data/stacks/osmosis/stack.yml @@ -5,14 +5,16 @@ repos: - git.vdb.to/cerc-io/hosting@names-for-so - gitea.com/gitea/act_runner # For osmosis frontend - - github.com/osmosis-labs/osmosis-frontend + - github.com/cerc-io/osmosis-frontend@ng-export-static # TODO: Update branch after merge containers: - cerc/act-runner - cerc/act-runner-task-executor + - cerc/watcher-ts - cerc/osmosis-front-end pods: - - osmosis-front-end - kubo + - proxy-server + - osmosis-front-end # TODO: Fix pod config for deployment command # TODO: mirroring all of osmosis repos: https://git.vdb.to/cerc-io/hosting/pulls/42 # - name: gitea