diff --git a/Dockerfile b/Dockerfile index 4ee4e70c..d8c33d7b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 667e9c89..37c42e8d 100644 --- a/README.md +++ b/README.md @@ -74,4 +74,36 @@ pnpm publish pnpm build cd packages/hypergraph-react/publish pnpm publish -``` \ No newline at end of file +``` + +## 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/ \ No newline at end of file diff --git a/fly.toml b/fly.toml index 89b29697..d7bac7c3 100644 --- a/fly.toml +++ b/fly.toml @@ -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"