From bf7f30df08361b41f3301a8a16c452ddfd433a86 Mon Sep 17 00:00:00 2001 From: Sanjiban Sengupta Date: Fri, 2 Feb 2024 04:36:16 +0530 Subject: [PATCH 1/5] fix: nginx deployment and docker secrets --- api/Dockerfile | 5 ++++- api/app.py | 2 +- api/components/duckdb.py | 2 +- client/Dockerfile | 2 ++ client/nginx.conf | 11 ++++++++++- client/vite.config.js | 5 ++--- docker-compose.yaml | 23 +++++++++++++++++++++-- 7 files changed, 41 insertions(+), 9 deletions(-) diff --git a/api/Dockerfile b/api/Dockerfile index e7634855..fa40a746 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -14,4 +14,7 @@ RUN pip install --no-cache-dir --upgrade -r /api/requirements.txt COPY ./ /api/ -CMD ["uvicorn", "app:app", "--reload", "--port", "9090"] +RUN --mount=type=secret,id=VITE_SESSION_SECRET \ + cat /run/secrets/VITE_SESSION_SECRET + +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--reload", "--port", "9090"] diff --git a/api/app.py b/api/app.py index fd910433..bec0a5e0 100644 --- a/api/app.py +++ b/api/app.py @@ -274,7 +274,7 @@ def substrait_fiddle_openapi(): app = FastAPI() -app.include_router(router, prefix="/route") +app.include_router(router, prefix="/api/route") app.openapi = substrait_fiddle_openapi app.add_middleware( TrustedHostMiddleware, diff --git a/api/components/duckdb.py b/api/components/duckdb.py index 3db51ba9..ebbe0246 100644 --- a/api/components/duckdb.py +++ b/api/components/duckdb.py @@ -6,7 +6,7 @@ # Pool size is default at 5 for maintaining # 5 concurrent DuckDB connection objects -POOL_SIZE = int(os.environ.get("DUCKDB_POOL_SIZE")) +POOL_SIZE = int(os.environ.get("DUCKDB_POOL_SIZE", 5)) diff --git a/client/Dockerfile b/client/Dockerfile index b8d8cf81..9b874ad3 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,6 +1,8 @@ FROM node:18-alpine as builder WORKDIR /app COPY . . +RUN --mount=type=secret,id=VITE_SESSION_SECRET \ + cat /run/secrets/VITE_SESSION_SECRET RUN npm ci RUN npm run build diff --git a/client/nginx.conf b/client/nginx.conf index 1d9f4741..8667a758 100644 --- a/client/nginx.conf +++ b/client/nginx.conf @@ -30,5 +30,14 @@ http { server_tokens off; root /app/static; + + location /api/ { + proxy_pass http://api:9090; # Use the service name instead of IP + 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/client/vite.config.js b/client/vite.config.js index 1c9506f0..46fc2b18 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -1,5 +1,4 @@ import { fileURLToPath, URL } from "node:url"; - import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import inject from "@rollup/plugin-inject"; @@ -7,6 +6,7 @@ import inject from "@rollup/plugin-inject"; const path = require("path"); export default defineConfig({ + base: '/', plugins: [ vue(), inject({ @@ -29,10 +29,9 @@ export default defineConfig({ server: { proxy: { "/api": { - target: "http://127.0.0.1:9090", + target: "http://api:9090", changeOrigin: true, secure: false, - rewrite: (path) => path.replace("/api", ""), }, }, }, diff --git a/docker-compose.yaml b/docker-compose.yaml index 361b0ecf..f98150de 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,12 +1,31 @@ version: '3.8' + services: api: build: ./api ports: - "9090:9090" environment: - - DUCKDB_POOL_SIZE=5 + - DUCKDB_POOL_SIZE=5 + networks: + - fiddle-network + secrets: + - vite_sess_secrt + client: build: ./client ports: - - "80:8080" + - "8080:8080" + networks: + - fiddle-network + secrets: + - vite_sess_secrt + +networks: + fiddle-network: + driver: bridge + +secrets: + vite_sess_secrt: + external: true + name: "${secrets.VITE_SESSION_SECRET}" From dd18220c320624bab3c88fff1d67cd49a4cf8f14 Mon Sep 17 00:00:00 2001 From: Sanjiban Sengupta Date: Fri, 2 Feb 2024 04:46:37 +0530 Subject: [PATCH 2/5] fix: pytest urls --- api/test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/api/test.py b/api/test.py index 109d4730..cd43772c 100644 --- a/api/test.py +++ b/api/test.py @@ -29,7 +29,7 @@ def test_validate_json(): "plan": plan, "override_levels": [2001, 1], } - response = client.post("/route/validate/", json=data, + response = client.post("/api/route/validate/", json=data, headers={"Host": "127.0.0.1"}) assert response.status_code == 200 @@ -40,7 +40,7 @@ def test_validate_binary(): file = file_stream.read() response = client.post( - "/route/validate/file/", + "/api/route/validate/file/", data={"override_levels": [1002, 2001]}, files={"file": ("q1.bin", file, "application/octet-stream")}, headers={"Host": "127.0.0.1"} @@ -68,7 +68,7 @@ def test_add_schema(): } ''' response = client.post( - "/route/add_schema/", + "/api/route/add_schema/", json={ "schema": schema }, @@ -86,7 +86,7 @@ def test_parse_to_substrait(): algorithm="HS256") response = client.post( - "/route/parse/", + "/api/route/parse/", json={ "query": "SELECT * FROM lineitem;", }, @@ -109,10 +109,10 @@ def test_save_plan_roundtrip(): "json_string": json_string, "validator_overrides": [2001, 1], } - response = client.post("/route/save/", json=data, headers={"Host": "127.0.0.1"}) + response = client.post("/api/route/save/", json=data, headers={"Host": "127.0.0.1"}) assert response.status_code == 200 - response = client.post("/route/fetch/?id=" + response.json(), + response = client.post("/api/route/fetch/?id=" + response.json(), headers={"Host": "127.0.0.1"}) assert response.status_code == 200 assert response.json()["json_string"] == json_string From 338145747c555c5b98429f1743c9ce9d539c9935 Mon Sep 17 00:00:00 2001 From: Sanjiban Sengupta Date: Fri, 2 Feb 2024 05:52:14 +0530 Subject: [PATCH 3/5] fix: vitest url --- client/src/assets/js/validate.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/assets/js/validate.test.js b/client/src/assets/js/validate.test.js index 4a2c88c1..5ea1b811 100644 --- a/client/src/assets/js/validate.test.js +++ b/client/src/assets/js/validate.test.js @@ -11,7 +11,7 @@ test("validate", async () => { "configured recursion limit for URI resolution has been reached", ); return axios - .post(BASE_URL + "/route/validate/", { + .post(BASE_URL + "/api/route/validate/", { plan: plan, override_levels: [2001, 1], }) From b650fd1c39acce555e559b0c2634d059adf4c3b3 Mon Sep 17 00:00:00 2001 From: Sanjiban Sengupta Date: Fri, 2 Feb 2024 12:20:27 +0530 Subject: [PATCH 4/5] fix: use env variables to run Cypress tests in GHCI --- .github/workflows/test_client_e2e.yaml | 16 ++++++++++++---- client/vite.config.js | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test_client_e2e.yaml b/.github/workflows/test_client_e2e.yaml index 2c609976..e1eedc04 100644 --- a/.github/workflows/test_client_e2e.yaml +++ b/.github/workflows/test_client_e2e.yaml @@ -2,14 +2,14 @@ name: Cypress Test on: [push] -env: - VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} - DUCKDB_POOL_SIZE: 5 - jobs: electron-run: runs-on: ubuntu-latest + env: + VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} + NODE_ENV: dev + steps: - name: Checkout backend uses: actions/checkout@v3 @@ -52,6 +52,10 @@ jobs: chrome-run: runs-on: ubuntu-latest + env: + VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} + NODE_ENV: dev + steps: - name: Checkout backend uses: actions/checkout@v3 @@ -88,6 +92,10 @@ jobs: edge-run: runs-on: ubuntu-latest + env: + VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} + NODE_ENV: dev + steps: - name: Checkout backend uses: actions/checkout@v3 diff --git a/client/vite.config.js b/client/vite.config.js index 46fc2b18..9ff1072c 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -29,7 +29,7 @@ export default defineConfig({ server: { proxy: { "/api": { - target: "http://api:9090", + target: process.env.NODE_ENV === 'dev' ? "http://127.0.0.1:9090" : "http://api:9090", changeOrigin: true, secure: false, }, From 868a60d4684ad8575b63e9ef9e69432a33d97bee Mon Sep 17 00:00:00 2001 From: Sanjiban Sengupta Date: Fri, 2 Feb 2024 12:27:03 +0530 Subject: [PATCH 5/5] fix: python formatting --- .github/workflows/test_client_e2e.yaml | 16 ++++------------ api/test.py | 4 +++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test_client_e2e.yaml b/.github/workflows/test_client_e2e.yaml index e1eedc04..ae3f72b4 100644 --- a/.github/workflows/test_client_e2e.yaml +++ b/.github/workflows/test_client_e2e.yaml @@ -2,14 +2,14 @@ name: Cypress Test on: [push] +env: + VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} + NODE_ENV: dev + jobs: electron-run: runs-on: ubuntu-latest - env: - VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} - NODE_ENV: dev - steps: - name: Checkout backend uses: actions/checkout@v3 @@ -52,10 +52,6 @@ jobs: chrome-run: runs-on: ubuntu-latest - env: - VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} - NODE_ENV: dev - steps: - name: Checkout backend uses: actions/checkout@v3 @@ -92,10 +88,6 @@ jobs: edge-run: runs-on: ubuntu-latest - env: - VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }} - NODE_ENV: dev - steps: - name: Checkout backend uses: actions/checkout@v3 diff --git a/api/test.py b/api/test.py index cd43772c..35000cf2 100644 --- a/api/test.py +++ b/api/test.py @@ -109,7 +109,9 @@ def test_save_plan_roundtrip(): "json_string": json_string, "validator_overrides": [2001, 1], } - response = client.post("/api/route/save/", json=data, headers={"Host": "127.0.0.1"}) + response = client.post("/api/route/save/", + json=data, + headers={"Host": "127.0.0.1"}) assert response.status_code == 200 response = client.post("/api/route/fetch/?id=" + response.json(),