Remove the need for a DATABASE_URL

Since the application does not use a database, it's confusing to have to
set a bogus database URL environment variable. This change follows [the
Lucky guide][1] suggestion for disabling the need for database
configuration. That makes the setup a little easier.

[1]:
https://www.luckyframework.org/guides/database/intro-to-avram-and-orms
main
Michael Herold 9 months ago committed by Edward Loveall
parent 93f5cb2d9e
commit 098f7fe0f9
No known key found for this signature in database
GPG Key ID: A7606DFEC2BA731F

@ -6,8 +6,6 @@ This is a project written using [Lucky](https://luckyframework.org). It's main w
I'd love it if you deployed your own version of this app! A [few others](docs/instances.md) have already. To do so currently will take some knowledge of how a webserver runs. This app is built with the [Lucky framework](https://luckyframework.org) and there are a bunch of different ways to deploy. The main instance runs on [Ubuntu](https://luckyframework.org/guides/deploying/ubuntu) but there are also directions for [Heroku](https://luckyframework.org/guides/deploying/heroku) or [Dokku](https://luckyframework.org/guides/deploying/dokku).
One thing to note is that this app doesn't currently use a database. Any instructions around postgres can be safely ignored. However, Lucky (and it's dependency Avram) do require a `DATABASE_URL` formatted for postgres. It doesn't need to be the URL of an actual database server though. Here's mine: `DATABASE_URL=postgres://does@not/mater`
Hopefully a more comprehensive guide will be written at some point, but for now feel free to reach out to the [mailing list](https://lists.sr.ht/~edwardloveall/scribe) if you have any questions.
### Docker (Unsupported)
@ -23,7 +21,7 @@ $ docker build [--build-arg PUID=1000] [--build-arg PGID=1000] -t scribe:latest
To run (generating a base config from environment variables):
```
$ docker run -it --rm -p 8080:8080 -e SCRIBE_PORT=8080 -e SCRIBE_HOST=0.0.0.0 -e SCRIBE_DB=postgres://does@not/matter scribe:latest
$ docker run -it --rm -p 8080:8080 -e SCRIBE_PORT=8080 -e SCRIBE_HOST=0.0.0.0 scribe:latest
```
To run with mounted config from local fs:
@ -42,8 +40,6 @@ Other configuration needed when in `production` mode:
* PORT: The port Scribe should run on
* SECRET_KEY_BASE: A 32-bit string. Can be generated with `lucky gen.secret_key`
* DATABASE_URL: May be any valid postgres url since Scribe doesn't use a database
* Example: `postgres://does@not/matter`
* GITHUB_PERSONAL_ACCESS_TOKEN: to proxy gists with authenticated GitHub API requests
* GITHUB_USERNAME: to proxy gists with authenticated GitHub API requests

@ -1,24 +1,10 @@
database_name = "scribe_#{LuckyEnv.environment}"
class UnusedDB < Avram::Database
end
AppDatabase.configure do |settings|
if LuckyEnv.production?
settings.credentials = Avram::Credentials.parse(ENV["DATABASE_URL"])
else
settings.credentials = Avram::Credentials.parse?(ENV["DATABASE_URL"]?) || Avram::Credentials.new(
database: database_name,
hostname: ENV["DB_HOST"]? || "localhost",
port: ENV["DB_PORT"]?.try(&.to_i) || 5432,
username: ENV["DB_USERNAME"]? || "postgres",
password: ENV["DB_PASSWORD"]? || "postgres"
)
end
UnusedDB.configure do |settings|
settings.credentials = Avram::Credentials.void
end
Avram.configure do |settings|
settings.database_to_migrate = AppDatabase
settings.lazy_load_enabled = LuckyEnv.production?
# Always parse `Time` values with these specific formats.
# Used for both database values, and datetime input fields.
# settings.time_formats << "%F"
settings.database_to_migrate = UnusedDB
end

@ -1,4 +1,4 @@
#!/bin/sh
echo -e "port: ${SCRIBE_PORT}\nhost: ${SCRIBE_HOST}\ndatabase: ${SCRIBE_DB}" > ./config/watch.yml
echo -e "port: ${SCRIBE_PORT}\nhost: ${SCRIBE_HOST}" > ./config/watch.yml
./start_server

@ -6,7 +6,6 @@ Lucky::AssetHelpers.load_manifest "public/mix-manifest.json"
require "./version"
require "../config/server"
require "../config/**"
require "./app_database"
require "./constants"
require "./models/base_model"
require "./models/mixins/**"

@ -1,2 +0,0 @@
class AppDatabase < Avram::Database
end

@ -1,3 +1,3 @@
module Scribe
VERSION = "2022-04-04"
VERSION = "2022-05-21"
end

Loading…
Cancel
Save