Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nginx deployment and docker secrets #66

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_client_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

env:
VITE_SESSION_SECRET: ${{ secrets.VITE_SESSION_SECRET }}
DUCKDB_POOL_SIZE: 5
NODE_ENV: dev

jobs:
electron-run:
Expand Down
5 changes: 4 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion api/components/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))



Expand Down
14 changes: 8 additions & 6 deletions api/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"}
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_add_schema():
}
'''
response = client.post(
"/route/add_schema/",
"/api/route/add_schema/",
json={
"schema": schema
},
Expand All @@ -86,7 +86,7 @@ def test_parse_to_substrait():
algorithm="HS256")

response = client.post(
"/route/parse/",
"/api/route/parse/",
json={
"query": "SELECT * FROM lineitem;",
},
Expand All @@ -109,10 +109,12 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 10 additions & 1 deletion client/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion client/src/assets/js/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
Expand Down
5 changes: 2 additions & 3 deletions client/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import inject from "@rollup/plugin-inject";

const path = require("path");

export default defineConfig({
base: '/',
plugins: [
vue(),
inject({
Expand All @@ -29,10 +29,9 @@ export default defineConfig({
server: {
proxy: {
"/api": {
target: "http://127.0.0.1:9090",
target: process.env.NODE_ENV === 'dev' ? "http://127.0.0.1:9090" : "http://api:9090",
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace("/api", ""),
},
},
},
Expand Down
23 changes: 21 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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}"
Loading