Skip to content
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
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm in
# Build stage for the server.
FROM base AS build
# TODO: Remove this when we switch to an actual database.
# ENV DATABASE_URL="file:./dev.db"
ENV DATABASE_URL="file:/data/production.sqlite"
RUN \
# TODO: This initalizes the database. But we should probably remove this later.
# pnpm --filter server prisma migrate reset --force && \
Expand All @@ -48,7 +48,8 @@ FROM node:22-alpine AS server
WORKDIR /app
COPY --from=build /workspace/deployment/out .
# TODO: Remove this when we switch to an actual database.
ENV DATABASE_URL="file:/mnt/hypergraph_data/production.sqlite"
ENV DATABASE_URL="file:/data/production.sqlite"
RUN npm run prisma migrate deploy --skip-generate
EXPOSE 3030
# can't use fly.io release_command because it doesn't mount the volume containing the sqlite db file
CMD ["sh", "-c", "npm run prisma migrate deploy && node dist/index.js"]
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,36 @@ pnpm publish
pnpm build
cd packages/hypergraph-react/publish
pnpm publish
```
```

## Deploying your own SyncServer to Fly.io (single instance)

```sh
# change the name of the `app` and `primary_region` in the fly.toml file

# create a volume for the sqlite db file - replace `fra` with your region
fly volumes create data -s 1 -r fra

# set the DATABASE_URL (not sure if it's necessary since already set in the Dockerfile)
fly secrets set DATABASE_URL=file:/data/production.sqlite

# deploy (ha=false to avoid starting multiple instances)
fly launch --ha=false

# probably not necessary, but better safe than sorry
fly scale count 1
```

Resources:
- https://fly.io/docs/js/prisma/sqlite/
- https://programmingmylife.com/2023-11-06-using-sqlite-for-a-django-application-on-flyio.html
- https://community.fly.io/t/backup-and-restore-sqlite-db-to-server/21232/2

### Multi-region deployments

As an alternative you might want to setup a lite-fs volume for multi-region deployments.

Resources:
- https://github.com/epicweb-dev/node-sqlite-fly-tutorial/tree/main/steps
- https://www.epicweb.dev/tutorials/deploy-web-applications/multi-region-data-and-deployment/prepare-for-multi-region-data-with-litefs
- https://fly.io/docs/litefs/speedrun/
10 changes: 5 additions & 5 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ cpu_kind = 'shared'
cpus = 1

[mounts]
source = "hypergraph_data"
destination = "/mnt/hypergraph_data"

# [deploy]
# release_command = "/bin/sh -c 'npm run prisma migrate deploy --skip-generate'"
source = "data"
destination = "/data"
auto_extend_size_threshold = 80
auto_extend_size_increment = "1GB"
auto_extend_size_limit = "10GB"
Loading