From 098f7fe0f9020c3cdc796fdb8242d6a8846831d1 Mon Sep 17 00:00:00 2001 From: Michael Herold Date: Fri, 20 May 2022 10:08:44 -0500 Subject: [PATCH] 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 --- README.md | 6 +----- config/database.cr | 24 +++++------------------- script/docker_entrypoint | 2 +- src/app.cr | 1 - src/app_database.cr | 2 -- src/version.cr | 2 +- 6 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 src/app_database.cr diff --git a/README.md b/README.md index d7ace3e..4226c02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/database.cr b/config/database.cr index 6ab8be0..b4e751b 100644 --- a/config/database.cr +++ b/config/database.cr @@ -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 diff --git a/script/docker_entrypoint b/script/docker_entrypoint index 718a309..6326e70 100755 --- a/script/docker_entrypoint +++ b/script/docker_entrypoint @@ -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 diff --git a/src/app.cr b/src/app.cr index 1d7e49b..9cc1b56 100644 --- a/src/app.cr +++ b/src/app.cr @@ -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/**" diff --git a/src/app_database.cr b/src/app_database.cr deleted file mode 100644 index 0efd4f5..0000000 --- a/src/app_database.cr +++ /dev/null @@ -1,2 +0,0 @@ -class AppDatabase < Avram::Database -end diff --git a/src/version.cr b/src/version.cr index b2a5e6e..a4c4b6c 100644 --- a/src/version.cr +++ b/src/version.cr @@ -1,3 +1,3 @@ module Scribe - VERSION = "2022-04-04" + VERSION = "2022-05-21" end