interval / server

Interval Server is the central node used to run applications developed with the Interval SDK.
https://interval.com
MIT License
137 stars 44 forks source link

Remove the need to separately run `db-init` for docker deployed environments #1

Closed hiett closed 1 week ago

hiett commented 1 year ago

Right now, the db-init command uses the psql command line to run the initSql, along with running a prisma db push. For environments where you want to deploy with docker, this means you separately have to:

I am suggesting that instead, it would make more sense to automatically run this on startup.

And even better, drop the requirement of psql and use a NodeJs postgres driver to run the SQL.

This means that deploying interval to a docker environment (especially one where the Postgres instance isn't publicly exposed to the internet) would simply be running the image and providing a valid connection string. The image would take care then of updating the database and ensuring it's ready to go.

With the current setup, if you were to deploy the :latest image, and for some reason it was to re-create the container, and update the image and there were Prisma changes, you'd run into an error during runtime without any warning.

This would also mean that Interval would be super easy to deploy in "one click" on sites that will deploy a database along side it from a template, but also in Kubernetes - it's unlikely you want to publicly expose your database. Right now I'd have to mess around with having interval installed locally, port-forwarding my database to my local machine, running that, and then applying a deployment file

occamz commented 2 months ago

I was just trying to test out Interval and this blocked me. This is not a fix, but maybe somebody else finds it useful.

Override the entrypoint with this:

apk update
apk add postgresql
interval-server db-init --skip-create
interval-server start

Here is a complete docker-compose.yml example that runs for me:

version: "3.5"
services:
  interval-postgresql:
    container_name: interval-postgresql
    environment:
      - POSTGRES_USER=interval
      - POSTGRES_PASSWORD=interval
    image: postgres:12
    networks:
      - interval-network
    expose:
      - 5432
    volumes:
      - interval-data:/var/lib/postgresql/data

  interval:
    entrypoint: /bin/sh -c "apk update; apk add postgresql; interval-server db-init --skip-create; interval-server start"
    container_name: interval
    depends_on:
      - interval-postgresql
    environment:
      - APP_URL=http://localhost:3000
      - DATABASE_URL=postgresql://interval:interval@interval-postgresql:5432/interval
      - SECRET=123123
      - WSS_API_SECRET=123123
      - AUTH_COOKIE_SECRET=12312312312312312312312312312312
    image: alexarena/interval-server:latest
    networks:
      - interval-network
    ports:
      - 3000:3000
      - 3033:3033

networks:
  interval-network:
    driver: bridge
    name: interval-network

volumes:
  interval-data:

After the first run, you can remove the entrypoint override.

OzzieOrca commented 1 month ago

Thanks for this :)

FYI you can use apk add postgresql-client instead of apk add postgresql to install psql without installing the whole postgres server.

ThallesP commented 2 weeks ago

i did this on my fork for Railway deploy, in case anyone wants to take a look: https://github.com/ThallesP/interval-server-on-railway

and if anyone wants a simple way to deploy on Railway: Deploy on Railway

jacobmischka commented 1 week ago

Should be fixed by #20, thanks @ThallesP !