Skip to content

Commit

Permalink
Merge pull request #675 from Shelf-nu/switch-to-supavisor
Browse files Browse the repository at this point in the history
Switch to supavisor
  • Loading branch information
DonKoko authored Jan 22, 2024
2 parents 520a745 + 612a0f1 commit 3074e58
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
22 changes: 20 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
DATABASE_URL="postgres://postgres:{POSTGRES_PASSWORD}@db.{YOUR_INSTANCE_NAME}.supabase.co:5432/postgres"
SHADOW_DATABASE_URL="postgres://postgres:{POSTGRES_PASSWORD}@db.{YOUR_INSTANCE_NAME}.supabase.co:5432/postgres_shadow"
# Most of the connection information can be found within the Supabase dashboard. Navigate to your project > Project Settings > Database.
# There you will be able to find the values you need to use below
# You can either copy the connection string and insert your password or use the connection parameters to build the string yourself
DATABASE_URL="postgres://{USER}:{PASSWORD}@{HOST}:6543/{DB_NAME}?pgbouncer=true&connection_limit=1"

# Direct URL is used by prisma to run migrations. Depending on how you run your migrations, you could skip this in your procution environment
# More info here: https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections#external-connection-poolers
# and here: https://www.prisma.io/docs/orm/reference/prisma-schema-reference#fields
DIRECT_URL="postgres://{USER}:{PASSWORD}@{HOST}:5432/{DB_NAME}"

SESSION_SECRET="super-duper-s3cret"
SUPABASE_ANON_PUBLIC="{ANON_PUBLIC}"
SUPABASE_SERVICE_ROLE="{SERVICE_ROLE}"
SUPABASE_URL="https://{YOUR_INSTANCE_NAME}.supabase.co"
SERVER_URL="http://localhost:3000"


# Set this to false to disable requirement of subscription for premium features. This will make premium features available for all users
ENABLE_PREMIUM_FEATURES="true"

# The Stripe keys are needed only if you want to enable premium features
STRIPE_SECRET_KEY="stripe-secret-key"
STRIPE_PUBLIC_KEY="stripe-public-key"
STRIPE_WEBHOOK_ENDPOINT_SECRET="stripe-endpoint-secret"


SMTP_PWD="super-safe-passw0rd"
SMTP_HOST="mail.example.com"
SMTP_USER="[email protected]"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
/public/build
.env
.env.production
.env.staging
.cache

/prisma/data.db
Expand Down
1 change: 1 addition & 0 deletions app/database/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}

generator client {
Expand Down
55 changes: 38 additions & 17 deletions docs/get-started.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
### Shelf's current stack

We have decided to give RemixJS a try.

For the purpose of shipping asap, we have opted into using a template: https://github.com/rphlmr/supa-fly-stack
Shelf's basic setup is based on a Remix stack by [rphlmr](https://github.com/rphlmr): https://github.com/rphlmr/supa-fly-stack

## What's in the stack

Expand Down Expand Up @@ -38,17 +36,40 @@ For the purpose of shipping asap, we have opted into using a template: https://g
- Add your `MAPTILER_TOKEN`, `SUPABASE_URL`, `SERVER_URL`, `SUPABASE_SERVICE_ROLE` (aka `service_role` `secret`), `SUPABASE_ANON_PUBLIC` (aka `anon` `public`) and `DATABASE_URL` in the `.env` file
> **Note:** `SERVER_URL` is your localhost on dev. It'll work for magic link login
```en
DATABASE_URL="postgres://postgres:{STAGING_POSTGRES_PASSWORD}@db.{STAGING_YOUR_INSTANCE_NAME}.supabase.co:5432/postgres"
```shell
# Most of the connection information can be found within the Supabase dashboard. Navigate to your project > Project Settings > Database.
# There you will be able to find the values you need to use below
# You can either copy the connection string and insert your password or use the connection parameters to build the string yourself
DATABASE_URL="postgres://{USER}:{PASSWORD}@{HOST}:6543/{DB_NAME}?pgbouncer=true&connection_limit=1"

# Direct URL is used by prisma to run migrations. Depending on how you run your migrations, you could skip this in your procution environment
# More info here: https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections#external-connection-poolers
# and here: https://www.prisma.io/docs/orm/reference/prisma-schema-reference#fields
DIRECT_URL="postgres://{USER}:{PASSWORD}@{HOST}:5432/{DB_NAME}"

SUPABASE_ANON_PUBLIC="{ANON_PUBLIC}"
SUPABASE_SERVICE_ROLE="{SERVICE_ROLE}"
SUPABASE_URL="https://{STAGING_YOUR_INSTANCE_NAME}.supabase.co"
SESSION_SECRET="super-duper-s3cret"
SERVER_URL="http://localhost:3000"
MAPTILER_TOKEN="someToken"

SMTP_HOST="smtp.yourhost.com"
SMTP_USER="[email protected]"
SMTP_PWD="yourSMTPpassword"

# Set this to false to disable requirement of subscription for premium features. This will make premium features available for all users
ENABLE_PREMIUM_FEATURES="true"

# The Stripe keys are needed only if you want to enable premium features
STRIPE_SECRET_KEY="stripe-secret-key"
STRIPE_PUBLIC_KEY="stripe-public-key"
STRIPE_WEBHOOK_ENDPOINT_SECRET="stripe-endpoint-secret"

MAPTILER_TOKEN="maptiler-token"
MICROSOFT_CLARITY_ID="microsoft-clarity-id"

INVITE_TOKEN_SECRET="secret-test-invite"
GEOCODE_API_KEY="geocode-api-key"
```

- This step only applies if you've opted out of having the CLI install dependencies for you:
Expand Down Expand Up @@ -104,8 +125,8 @@ Prior to your first deployment, you'll need to do a few things:
- Create two apps on Fly, one for staging and one for production:

```sh
fly apps create supa-fly-stack-template
fly apps create supa-fly-stack-template-staging # ** not mandatory if you don't want a staging environment **
fly apps create shelf-webapp
fly apps create shelf-webapp-staging # ** not mandatory if you don't want a staging environment **
```

> **Note:** For production app, make sure this name matches the `app` set in your `fly.toml` file. Otherwise, you will not be able to deploy.
Expand All @@ -128,17 +149,17 @@ Prior to your first deployment, you'll need to do a few things:

- Add a `SESSION_SECRET`, `SUPABASE_URL`, `SUPABASE_SERVICE_ROLE`,`SUPABASE_ANON_PUBLIC`, `SERVER_URL` and `DATABASE_URL` to your fly app secrets

> **Note:** To find your `SERVER_URL`, go to [your fly.io dashboard](https://fly.io/apps/supa-fly-stack-template-3a36)
> **Note:** To find your `SERVER_URL`, go to [your fly.io dashboard](https://fly.io/dashboard/)
To do this you can run the following commands:

```sh
```shell
# production (--app name is resolved from fly.toml)
fly secrets set SESSION_SECRET=$(openssl rand -hex 32)
fly secrets set SUPABASE_URL="https://{YOUR_INSTANCE_NAME}.supabase.co"
fly secrets set SUPABASE_SERVICE_ROLE="{SUPABASE_SERVICE_ROLE}"
fly secrets set SUPABASE_ANON_PUBLIC="{SUPABASE_ANON_PUBLIC}"
fly secrets set DATABASE_URL="postgres://postgres:{POSTGRES_PASSWORD}@db.{YOUR_INSTANCE_NAME}.supabase.co:5432/postgres"
fly secrets set DATABASE_URL="postgres://{USER}:{PASSWORD}@{HOST}:6543/{DB_NAME}?pgbouncer=true&connection_limit=1"
fly secrets set SERVER_URL="https://{YOUR_STAGING_SERVEUR_URL}"
fly secrets set MAPTILER_TOKEN="{YOUR_MAPTILER_TOKEN}"

Expand All @@ -148,12 +169,12 @@ Prior to your first deployment, you'll need to do a few things:


# staging (specify --app name) ** not mandatory if you don't want a staging environnement **
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app supa-fly-stack-template-staging
fly secrets set SUPABASE_URL="https://{YOUR_STAGING_INSTANCE_NAME}.supabase.co" --app supa-fly-stack-template-staging
fly secrets set SUPABASE_SERVICE_ROLE="{STAGING_SUPABASE_SERVICE_ROLE}" --app supa-fly-stack-template-staging
fly secrets set SUPABASE_ANON_PUBLIC="{STAGING_SUPABASE_ANON_PUBLIC}" --app supa-fly-stack-template-staging
fly secrets set DATABASE_URL="postgres://postgres:{STAGING_POSTGRES_PASSWORD}@db.{STAGING_YOUR_INSTANCE_NAME}.supabase.co:5432/postgres" --app supa-fly-stack-template-staging
fly secrets set SERVER_URL="https://{YOUR_STAGING_SERVEUR_URL}" --app supa-fly-stack-template-staging
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app shelf-webapp-staging
fly secrets set SUPABASE_URL="https://{YOUR_STAGING_INSTANCE_NAME}.supabase.co" --app shelf-webapp-staging
fly secrets set SUPABASE_SERVICE_ROLE="{STAGING_SUPABASE_SERVICE_ROLE}" --app shelf-webapp-staging
fly secrets set SUPABASE_ANON_PUBLIC="{STAGING_SUPABASE_ANON_PUBLIC}" --app shelf-webapp-staging
fly secrets set DATABASE_URL="postgres://{USER}:{PASSWORD}@{HOST}:6543/{DB_NAME}?pgbouncer=true&connection_limit=1" --app shelf-webapp-staging
fly secrets set SERVER_URL="https://{YOUR_STAGING_SERVEUR_URL}" --app shelf-webapp-staging

```

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
"db:prepare-migration": "prisma generate && prisma migrate dev --create-only --skip-seed",
"db:generate-type": "prisma generate",
"db:deploy-migration": "prisma migrate deploy && prisma generate",
"db:deploy-migration:staging": "dotenv -e .env.staging -- prisma migrate deploy && prisma generate",
"db:deploy-migration:production": "dotenv -e .env.production -- prisma migrate deploy && prisma generate",
"dev": "remix dev",
"production:dev": "dotenv -e .env.production -- remix dev",
"staging:dev": "dotenv -e .env.staging -- remix dev",
"format": "prettier --write .",
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
"setup": "run-s setup:db setup:seed",
"setup:db": "prisma generate && prisma migrate deploy",
"setup:seed": "prisma db seed",
"reset:db": "prisma migrate reset",
"reset:db:staging": "dotenv -e .env.staging -- prisma migrate reset",
"start": "remix-serve build/index.js",
"start:ci": "dotenv -- remix-serve build",
"test": "echo test",
Expand Down

0 comments on commit 3074e58

Please sign in to comment.