Skip to content

Commit a6028f8

Browse files
committed
Merge branch 'next' into chore/cache-eviction-strategy
2 parents 36a773c + 6b25b59 commit a6028f8

File tree

21 files changed

+247
-95
lines changed

21 files changed

+247
-95
lines changed

apps/proxy/.env.example

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ CACHE_SCHEDULE_INTERVAL=1
1111
CACHE_TIMESTAMP_FILE=/var/lib/postgres-new/delete_cache_last_run
1212
# Cache time to live in hours
1313
CACHE_TTL=24
14-
DATA_MOUNT=/mnt/data
1514
S3FS_MOUNT=/mnt/s3
1615
SUPABASE_SERVICE_ROLE_KEY="<service-role-key>"
1716
SUPABASE_URL="<supabase-url>"
18-
WILDCARD_DOMAIN=db.example.com
19-
17+
WILDCARD_DOMAIN=db.example.com

apps/proxy/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Adjust NODE_VERSION as desired
44
ARG NODE_VERSION=20.16.0
5-
FROM node:${NODE_VERSION}-bookworm as base
5+
FROM node:${NODE_VERSION}-bookworm AS base
66

77
LABEL fly_launch_runtime="NodeJS"
88

@@ -13,7 +13,7 @@ WORKDIR /app
1313
ENV NODE_ENV=production
1414

1515
# Build S3FS
16-
FROM base as build-s3fs
16+
FROM base AS build-s3fs
1717

1818
# Install dependencies
1919
RUN apt-get update && \
@@ -28,7 +28,7 @@ RUN git clone https://github.com/supabase/s3fs-fuse.git --branch s3/support-endp
2828
make install
2929

3030
# Build app
31-
FROM base as build-app
31+
FROM base AS build-app
3232

3333
# Install packages needed to build node modules
3434
RUN apt-get update -qq && \

apps/proxy/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,32 @@ To stop all Docker containers, run:
8484
docker compose down
8585
```
8686

87-
## Deployment
87+
## Deploying to fly.io
8888

89-
The proxy is deployed on Fly.io.
89+
1. Create a new app if it doesn't exist
9090

91-
A Tigris bucket is used to store the DB tarballs and the TLS certificates.
91+
```shell
92+
fly apps create postgres-new-proxy
93+
```
94+
95+
2. Set the appropriate environment variables and secrets for the app "postgres-new-proxy" (see `.env.example`) in fly.io UI.
96+
97+
3. Allocate a dedicated IPv4 address for the app, it's required to resolve wildcard DNS queries correctly.
98+
99+
```shell
100+
fly ips allocate-v4
101+
```
102+
103+
4. On Cloudflare, add a new CNAME DNS record pointing to the Fly.io app domain:
104+
105+
| Type | Name | Value |
106+
| --- | --- | --- |
107+
| CNAME | *.db | postgres-new-proxy.fly.dev |
108+
109+
5. Deploy the app
110+
111+
Due to a [bug](https://github.com/superfly/flyctl/issues/3870) in `fly` ignoring `.dockerignore` files when setting up a build context, we need to copy the file to the root of the repo and remove it after the deploy.
112+
113+
```shell
114+
cp .dockerignore ../.. && fly deploy ../.. --config apps/proxy/fly.toml && rm ../../.dockerignore
115+
```

apps/proxy/fly.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
app = 'postgres-new-proxy'
22

3-
primary_region = 'yyz'
3+
primary_region = 'iad'
4+
5+
[build]
6+
dockerfile = "Dockerfile"
7+
ignorefile = ".dockerignore"
48

59
[env]
610
CACHE_DISK_USAGE_THRESHOLD = "90"

apps/proxy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type-check": "tsc --noEmit"
1111
},
1212
"dependencies": {
13-
"@electric-sql/pglite": "0.2.0",
13+
"@electric-sql/pglite": "0.2.2",
1414
"@supabase/supabase-js": "^2.45.1",
1515
"find-up": "^7.0.0",
1616
"pg-gateway": "0.3.0-alpha.6",

apps/proxy/tools/certbot/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
AWS_ACCESS_KEY_ID=625729a08b95bf1b7ff351a663f3a23c
1+
AWS_ACCESS_KEY_ID="<aws-access-key-id>"
22
AWS_ENDPOINT_URL_S3=http://host.docker.internal:54321/storage/v1/s3
33
AWS_S3_BUCKET=s3fs
4-
AWS_SECRET_ACCESS_KEY=850181e4652dd023b7a98c58ae0d2d34bd487ee0cc3254aed6eda37307425907
4+
AWS_SECRET_ACCESS_KEY="<aws-secret-access-key>"
55
AWS_REGION=local
66
CERTBOT_DOMAIN=db.postgres.new
77
CERTBOT_EMAIL="<your-email>"

apps/proxy/tools/certbot/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN apk add --no-cache \
1919
fuse-dev \
2020
curl-dev
2121

22-
RUN git clone https://github.com/s3fs-fuse/s3fs-fuse.git --branch v1.94 && \
22+
RUN git clone https://github.com/supabase/s3fs-fuse.git --depth 1 --branch s3/support-endpoint-with-uris && \
2323
cd s3fs-fuse && \
2424
./autogen.sh && \
2525
./configure && \

apps/proxy/tools/certbot/README.md

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This service is responsible for managing the certificates for the PGLite instances.
44

5-
It uses `fly machine run --schedule weekly` to wake up the service every week to renew the certificates if needed. Let's Encrypt certificates are valid for 90 days.
5+
The certificates are created on Let's Encrypt (valid for 90 days) and stored in a S3 bucket under the `/tls` path.
66

77
## Testing certbot-service locally
88

@@ -32,74 +32,23 @@ The certificates will be generated in `/mnt/s3/tls`.
3232

3333
1. Create a new app if it doesn't exist
3434

35-
```shell
36-
flyctl apps create postgres-new-certbot
37-
```
35+
```shell
36+
fly apps create postgres-new-certbot
37+
```
3838

3939
2. Build and deploy the Docker image to fly.io image registry
4040

41-
```shell
42-
flyctl deploy --build-only --push -a postgres-new-certbot --image-label
43-
latest
44-
```
41+
```shell
42+
fly deploy --build-only --push --image-label latest
43+
```
4544

46-
1. Set the appropriate environment variables and secrets for the app "postgres-new-certbot" (see `.env.example`) in fly.io UI.
47-
48-
2. Setup [cron-manager](https://github.com/fly-apps/cron-manager?tab=readme-ov-file#getting-started) to run the certbot service every 2 weeks with the following `schedules.json`:
49-
50-
```json
51-
[
52-
{
53-
"name": "postgres-new-certbot",
54-
"app_name": "postgres-new-certbot",
55-
"schedule": "0 0 1,15 * *",
56-
"region": "ord",
57-
"command": "./certbot.sh",
58-
"command_timeout": 120,
59-
"enabled": true,
60-
"config": {
61-
"metadata": {
62-
"fly_process_group": "cron"
63-
},
64-
"auto_destroy": true,
65-
"disable_machine_autostart": true,
66-
"guest": {
67-
"cpu_kind": "shared",
68-
"cpus": 1,
69-
"memory_mb": 256
70-
},
71-
"image": "registry.fly.io/postgres-new-certbot:latest",
72-
"restart": {
73-
"max_retries": 1,
74-
"policy": "no"
75-
}
76-
}
77-
}
78-
]
79-
```
45+
3. Set the appropriate environment variables and secrets for the app "postgres-new-certbot" (see `.env.example`) in fly.io UI.
8046

81-
5. Test running the job by SSHing into cron-manager console
82-
83-
Run this command in the cron-manager root folder:
84-
85-
```shell
86-
flyctl ssh console
87-
```
47+
4. Deploy the machine with a schedule
8848

89-
Once in the cron-manager instance:
49+
```shell
50+
fly machine run registry.fly.io/postgres-new-certbot:latest "./certbot.sh" --region iad --schedule weekly
51+
```
9052

91-
```shell
92-
cm jobs trigger 1
93-
```
94-
95-
If you open the "postgres-new-certbot" live logs in fly.io UI, you should see the job being executed.
96-
97-
6. You can check if the certificates are present in the Tigris bucket
98-
99-
Run this command in the apps/db-instance folder:
100-
101-
```shell
102-
flyctl storage dashboard
103-
```
53+
The machine will now be started weekly in order to renew the certificates.
10454

105-
It should open the Tigris dashboard where you can check the bucket's content. The certificates should be created under `/tls`.

apps/proxy/tools/certbot/fly.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
app = 'postgres-new-certbot'
22

3-
primary_region = 'yyz'
3+
[[vm]]
4+
size = "shared-cpu-1x"

apps/web/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ AWS_ENDPOINT_URL_S3=http://localhost:54321/storage/v1/s3
33
AWS_S3_BUCKET=s3fs
44
AWS_SECRET_ACCESS_KEY=850181e4652dd023b7a98c58ae0d2d34bd487ee0cc3254aed6eda37307425907
55
AWS_REGION=local
6+
# Vercel KV (local Docker available)
7+
KV_REST_API_TOKEN="local_token"
8+
KV_REST_API_URL="http://localhost:8080"
69
OPENAI_API_KEY="<openai-api-key>"
710
NEXT_PUBLIC_IS_PREVIEW=true
811
NEXT_PUBLIC_SUPABASE_ANON_KEY="<supabase-anon-key>"

0 commit comments

Comments
 (0)