Skip to content

Commit 378d570

Browse files
authored
Adding some new deployment configuration files (#533)
1 parent 3b8ddf0 commit 378d570

File tree

6 files changed

+118
-4
lines changed

6 files changed

+118
-4
lines changed

typescript/packages/toolshed/deno.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"tasks": {
33
"dev": "deno run -A --watch --env-file=.env index.ts",
4+
"production": "deno run -A --env-file=.env index.ts",
45
"test": "deno test -A --env-file=.env.test"
56
},
67
"fmt": {
7-
"exclude": [
8-
"./llm_documentation/*"
9-
]
8+
"exclude": ["./llm_documentation/*"]
109
},
1110
"imports": {
1211
"@/": "./",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
cd labs
3+
git pull origin main
4+
sudo systemctl restart toolshed@*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# /etc/systemd/system/tailscale-serve.service
2+
3+
[Unit]
4+
Description=Tailscale Serve Proxy
5+
After=network.target
6+
7+
[Service]
8+
# Running as root so that binding to port 443 is allowed.
9+
User=root
10+
ExecStart=/usr/bin/tailscale serve --https=443 localhost:8080
11+
Restart=on-failure
12+
RestartSec=5
13+
14+
[Install]
15+
WantedBy=multi-user.target
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# /etc/nginx/sites-enabled/toolshed.conf
2+
3+
# Trust all proxies (adjust as needed)
4+
set_real_ip_from 0.0.0.0/0;
5+
real_ip_header X-Forwarded-For;
6+
real_ip_recursive on;
7+
8+
# Map backend_choice to just the port number for the header.
9+
map $backend_choice $served_from {
10+
"127.0.0.1:8001" "8001";
11+
"127.0.0.1:8002" "8002";
12+
"127.0.0.1:8003" "8003";
13+
"127.0.0.1:8004" "8004";
14+
"127.0.0.1:8005" "8005";
15+
}
16+
17+
# Use the client's IP as the sticky value.
18+
map $remote_addr $sticky_value {
19+
default $remote_addr;
20+
}
21+
22+
# Deterministically assign a backend server based on the client's IP.
23+
split_clients "$sticky_value" $backend_choice {
24+
# NOTE: 8000 is running, but reserved for "internal" use, where our codebase
25+
# makes requests to localhost:8000.
26+
# 20% 127.0.0.1:8000;
27+
20% 127.0.0.1:8001;
28+
20% 127.0.0.1:8002;
29+
20% 127.0.0.1:8003;
30+
20% 127.0.0.1:8004;
31+
20% 127.0.0.1:8005;
32+
}
33+
34+
# Map for handling the upgrade header.
35+
map $http_upgrade $connection_upgrade {
36+
default Upgrade;
37+
'' close;
38+
}
39+
40+
server {
41+
listen 8080;
42+
server_name localhost;
43+
44+
location / {
45+
add_header X-Served-From $served_from always;
46+
proxy_set_header X-Forwarded-For $remote_addr;
47+
proxy_set_header X-Real-IP $remote_addr;
48+
proxy_set_header Host $host;
49+
proxy_set_header Tailscale-User-Login $http_tailscale_user_login;
50+
proxy_pass http://$backend_choice;
51+
}
52+
53+
location /api/storage/memory {
54+
proxy_pass http://$backend_choice;
55+
proxy_http_version 1.1;
56+
proxy_set_header Upgrade $http_upgrade;
57+
proxy_set_header Connection $connection_upgrade;
58+
proxy_set_header Host $host;
59+
proxy_set_header X-Real-IP $remote_addr;
60+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
61+
proxy_set_header Tailscale-User-Login $http_tailscale_user_login;
62+
63+
# Increase timeouts for long-lived WebSocket connections.
64+
proxy_read_timeout 86400;
65+
proxy_send_timeout 86400;
66+
}
67+
68+
# Expose Nginx status at /_nginx.
69+
location /_nginx {
70+
# Enable the stub_status module.
71+
stub_status;
72+
73+
# Optionally, restrict access to this endpoint.
74+
# For example, only allow local connections:
75+
# Allow all devices on the Tailscale network.
76+
allow 100.64.0.0/10;
77+
allow 127.0.0.1;
78+
allow ::1;
79+
deny all;
80+
}
81+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# /etc/systemd/system/toolshed@.service
2+
[Unit]
3+
Description=Toolshed Deno Service instance on port %I
4+
After=network.target
5+
6+
[Service]
7+
User=jake
8+
WorkingDirectory=/home/jake/labs/typescript/packages/toolshed
9+
Environment="PORT=%I"
10+
ExecStart=/bin/sh -c "/home/jake/.deno/bin/deno task production"
11+
Restart=always
12+
RestartSec=1
13+
14+
[Install]
15+
WantedBy=multi-user.target

typescript/packages/toolshed/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Sentry.init({
1313
tracesSampleRate: 1.0,
1414
});
1515

16-
Deno.serve(app.fetch);
16+
Deno.serve({ port }, app.fetch);

0 commit comments

Comments
 (0)