From 4122467e39b1800a76f36cdf2f2ea093a09376fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Fri, 12 Apr 2024 12:30:08 +0200 Subject: [PATCH] use nginx as a reverse proxy and fix alter statement in migrations (#1876) --- .../manual-deploy-obscuro-gateway.yml | 2 +- tools/walletextension/Dockerfile | 14 +++++++++- tools/walletextension/entrypoint.sh | 13 +++++++++ tools/walletextension/nginx.conf | 27 +++++++++++++++++++ .../mariadb/003_add_signature_type.sql | 3 +-- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tools/walletextension/entrypoint.sh create mode 100644 tools/walletextension/nginx.conf diff --git a/.github/workflows/manual-deploy-obscuro-gateway.yml b/.github/workflows/manual-deploy-obscuro-gateway.yml index 39376b734e..20f059305e 100644 --- a/.github/workflows/manual-deploy-obscuro-gateway.yml +++ b/.github/workflows/manual-deploy-obscuro-gateway.yml @@ -137,5 +137,5 @@ jobs: && docker run -d -p 80:80 -p 81:81 --name ${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }} \ -e OBSCURO_GATEWAY_VERSION="${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}" \ ${{ vars.DOCKER_BUILD_TAG_GATEWAY }} \ - ./wallet_extension_linux -host=0.0.0.0 -port=80 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR }} \ + -host=0.0.0.0 -port=8080 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR }} \ -logPath=sys_out -dbType=mariaDB -dbConnectionURL="obscurouser:${{ secrets.OBSCURO_GATEWAY_MARIADB_USER_PWD }}@tcp(obscurogateway-mariadb-${{ github.event.inputs.testnet_type }}.uksouth.cloudapp.azure.com:3306)/ogdb"' diff --git a/tools/walletextension/Dockerfile b/tools/walletextension/Dockerfile index 6fae9c88bc..b399a471dd 100644 --- a/tools/walletextension/Dockerfile +++ b/tools/walletextension/Dockerfile @@ -55,10 +55,22 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ # Lightweight final build stage. Includes bare minimum to start wallet extension FROM alpine:3.18 +# Install NGINX +RUN apk update && apk add nginx + # copy over the gateway executable COPY --from=build-wallet /home/obscuro/go-obscuro/tools/walletextension/bin /home/obscuro/go-obscuro/tools/walletextension/bin # copy over the .sql migration files COPY --from=build-wallet /home/obscuro/go-obscuro/tools/walletextension/storage/database /home/obscuro/go-obscuro/tools/walletextension/storage/database -WORKDIR /home/obscuro/go-obscuro/tools/walletextension/bin +# copy over the NGINX configuration file +COPY --from=build-wallet /home/obscuro/go-obscuro/tools/walletextension/nginx.conf /etc/nginx/nginx.conf + + +# copy over the entrypoint script +COPY --from=build-wallet /home/obscuro/go-obscuro/tools/walletextension/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + diff --git a/tools/walletextension/entrypoint.sh b/tools/walletextension/entrypoint.sh new file mode 100644 index 0000000000..f470d7de86 --- /dev/null +++ b/tools/walletextension/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Start NGINX in the background +nginx & + +# Start wallet_extension_linux with parameters passed to the script +/home/obscuro/go-obscuro/tools/walletextension/bin/wallet_extension_linux "$@" + +# Wait for any process to exit +wait -n + +# Exit with the status of the process that exited first +exit $? diff --git a/tools/walletextension/nginx.conf b/tools/walletextension/nginx.conf new file mode 100644 index 0000000000..b0a1e266b6 --- /dev/null +++ b/tools/walletextension/nginx.conf @@ -0,0 +1,27 @@ +events { + worker_connections 4096; +} + +http { + server { + listen 80; + + location = / { + proxy_pass http://localhost:8080/static/; # Redirects only the root URL + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + location / { + proxy_pass http://localhost:8080; # Pass all other requests to the app + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +} \ No newline at end of file diff --git a/tools/walletextension/storage/database/mariadb/003_add_signature_type.sql b/tools/walletextension/storage/database/mariadb/003_add_signature_type.sql index f99247c7a6..f04ffb6f23 100644 --- a/tools/walletextension/storage/database/mariadb/003_add_signature_type.sql +++ b/tools/walletextension/storage/database/mariadb/003_add_signature_type.sql @@ -1,2 +1 @@ -ALTER TABLE ogdb.accounts -ADD COLUMN signature_type INT DEFAULT 0; \ No newline at end of file +ALTER TABLE ogdb.accounts ADD COLUMN IF NOT EXISTS signature_type INT DEFAULT 0; \ No newline at end of file