Skip to content

Commit c47bdbb

Browse files
authored
document fly deployment (#297)
1 parent c8bb486 commit c47bdbb

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm in
2424
# Build stage for the server.
2525
FROM base AS build
2626
# TODO: Remove this when we switch to an actual database.
27-
# ENV DATABASE_URL="file:./dev.db"
27+
ENV DATABASE_URL="file:/data/production.sqlite"
2828
RUN \
2929
# TODO: This initalizes the database. But we should probably remove this later.
3030
# pnpm --filter server prisma migrate reset --force && \
@@ -48,7 +48,8 @@ FROM node:22-alpine AS server
4848
WORKDIR /app
4949
COPY --from=build /workspace/deployment/out .
5050
# TODO: Remove this when we switch to an actual database.
51-
ENV DATABASE_URL="file:/mnt/hypergraph_data/production.sqlite"
51+
ENV DATABASE_URL="file:/data/production.sqlite"
5252
RUN npm run prisma migrate deploy --skip-generate
5353
EXPOSE 3030
54+
# can't use fly.io release_command because it doesn't mount the volume containing the sqlite db file
5455
CMD ["sh", "-c", "npm run prisma migrate deploy && node dist/index.js"]

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,36 @@ pnpm publish
7474
pnpm build
7575
cd packages/hypergraph-react/publish
7676
pnpm publish
77-
```
77+
```
78+
79+
## Deploying your own SyncServer to Fly.io (single instance)
80+
81+
```sh
82+
# change the name of the `app` and `primary_region` in the fly.toml file
83+
84+
# create a volume for the sqlite db file - replace `fra` with your region
85+
fly volumes create data -s 1 -r fra
86+
87+
# set the DATABASE_URL (not sure if it's necessary since already set in the Dockerfile)
88+
fly secrets set DATABASE_URL=file:/data/production.sqlite
89+
90+
# deploy (ha=false to avoid starting multiple instances)
91+
fly launch --ha=false
92+
93+
# probably not necessary, but better safe than sorry
94+
fly scale count 1
95+
```
96+
97+
Resources:
98+
- https://fly.io/docs/js/prisma/sqlite/
99+
- https://programmingmylife.com/2023-11-06-using-sqlite-for-a-django-application-on-flyio.html
100+
- https://community.fly.io/t/backup-and-restore-sqlite-db-to-server/21232/2
101+
102+
### Multi-region deployments
103+
104+
As an alternative you might want to setup a lite-fs volume for multi-region deployments.
105+
106+
Resources:
107+
- https://github.com/epicweb-dev/node-sqlite-fly-tutorial/tree/main/steps
108+
- https://www.epicweb.dev/tutorials/deploy-web-applications/multi-region-data-and-deployment/prepare-for-multi-region-data-with-litefs
109+
- https://fly.io/docs/litefs/speedrun/

fly.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ cpu_kind = 'shared'
2222
cpus = 1
2323

2424
[mounts]
25-
source = "hypergraph_data"
26-
destination = "/mnt/hypergraph_data"
27-
28-
# [deploy]
29-
# release_command = "/bin/sh -c 'npm run prisma migrate deploy --skip-generate'"
25+
source = "data"
26+
destination = "/data"
27+
auto_extend_size_threshold = 80
28+
auto_extend_size_increment = "1GB"
29+
auto_extend_size_limit = "10GB"

0 commit comments

Comments
 (0)