From 276ae3a54532c6f71d3f0fd31c318e221e506e11 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Fri, 9 Feb 2024 11:13:43 -0500 Subject: [PATCH] Add some lnplaylive-frontend code to ss --- www/lnplaylive-frontend/.gitignore | 1 + www/lnplaylive-frontend/Dockerfile | 10 +++ www/lnplaylive-frontend/build.sh | 48 ++++++++++++++ www/lnplaylive-frontend/some_code.sh | 99 ++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 www/lnplaylive-frontend/.gitignore create mode 100644 www/lnplaylive-frontend/Dockerfile create mode 100755 www/lnplaylive-frontend/build.sh create mode 100644 www/lnplaylive-frontend/some_code.sh diff --git a/www/lnplaylive-frontend/.gitignore b/www/lnplaylive-frontend/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/www/lnplaylive-frontend/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/www/lnplaylive-frontend/Dockerfile b/www/lnplaylive-frontend/Dockerfile new file mode 100644 index 0000000..04414d6 --- /dev/null +++ b/www/lnplaylive-frontend/Dockerfile @@ -0,0 +1,10 @@ +ARG BASE_IMAGE +FROM $BASE_IMAGE +RUN mkdir /lnplaylive +COPY app/ /lnplaylive +WORKDIR /lnplaylive +EXPOSE 5173 +ENV HOST=0.0.0.0 +ENV PORT 5173 +RUN npm i +RUN npm run build diff --git a/www/lnplaylive-frontend/build.sh b/www/lnplaylive-frontend/build.sh new file mode 100755 index 0000000..80f5d1b --- /dev/null +++ b/www/lnplaylive-frontend/build.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -exu +cd "$(dirname "$0")" + + +# this is the default case when a .env doesn't exist. We stub it out. +if [ "$CLN_COUNT" -gt 0 ] && [ -z "$LNPLAYLIVE_FRONTEND_ENV" ]; then + # before I can do any of this, I need to stub out the .env file... + # in order to do that, the lightning nodes need to be up first. + LNPLAYLIVE_FRONTEND_ENV="$(pwd)/.env" + PUBLIC_ADDRESS="$(bash -c "../../get_node_uri.sh --id=0 --port=$STARTING_WEBSOCKET_PORT")" + PUBLIC_WEBSOCKET_PROXY="$(echo "$PUBLIC_ADDRESS" | grep -o '@.*')" + + WS_PROTO=ws + if [ "$ENABLE_TLS" = true ]; then + WS_PROTO=wss + fi + + PUBLIC_RUNE=$(bash -c "../../lightning-cli.sh --id=0 commando-rune restrictions='[[\"method^lnplaylive\",\"method=waitinvoice\",\"rate=120\"]]'" | jq -r '.rune') + + cat > "$LNPLAYLIVE_FRONTEND_ENV" </dev/null; then + docker build -t "$LNPLAYLIVE_IMAGE_NAME" --build-arg BASE_IMAGE="${NODE_BASE_DOCKER_IMAGE_NAME}" ./ + + rm -rf ./app/node_modules + rm -rf ./app/.sveltekit + rm ./app/.env + fi + + # and then load them back up with our freshly build version. + docker run -t -v lnplay-live:/output "$LNPLAYLIVE_IMAGE_NAME" cp -r /lnplaylive/build/ /output/ +else + echo "ERROR: you are deploying the lnplaylive frontend application, but there is no .env file for it to build with! " + echo " you may need a backend deployment, or you need to define LNPLAYLIVE_FRONTEND_ENV in your config." + exit 1 +fi \ No newline at end of file diff --git a/www/lnplaylive-frontend/some_code.sh b/www/lnplaylive-frontend/some_code.sh new file mode 100644 index 0000000..c5b86e3 --- /dev/null +++ b/www/lnplaylive-frontend/some_code.sh @@ -0,0 +1,99 @@ +# this code was found in layers above the current dir; +# need to incorporate all this into sovereign-stack + +# if we are deploying the lnplaylive frontend, we can rebuild at this point +# because it required build-time info from the deployed backend. The build script below +# will stub out those envs and rebuild the output from the app. +if [ "$DEPLOY_LNPLAYLIVE_FRONTEND" = true ]; then + env LNPLAYLIVE_FRONTEND_ENV="$LNPLAYLIVE_FRONTEND_ENV" ./lnplay/lnplaylive-frontend/build.sh +fi + + + +if [ "$DEPLOY_LNPLAYLIVE_FRONTEND" = true ]; then + if ! docker image inspect "$NODE_BASE_DOCKER_IMAGE_NAME" &> /dev/null; then + # pull bitcoind down + docker pull -q "$NODE_BASE_DOCKER_IMAGE_NAME" >> /dev/null + fi + + if ! docker volume list | grep -q "lnplay-live"; then + docker volume create lnplay-live + fi +fi + + + + + + + + + +# if [ "$DEPLOY_LNPLAYLIVE_FRONTEND" = true ]; then +# cat >> "$DOCKER_COMPOSE_YML_PATH" <> "$DOCKER_COMPOSE_YML_PATH" <> "$DOCKER_COMPOSE_YML_PATH" <> "$DOCKER_COMPOSE_YML_PATH" <> "$NGINX_CONFIG_PATH" <.+)$ { + autoindex off; + server_tokens off; + gzip_static on; + root /lnplaylive/build; + index 404.html; + } + + location / { + autoindex off; + server_tokens off; + gzip_static on; + root /lnplaylive/build; + index index.html; + } + } +EOF + +el