Overhauled configuration so that it's a bit more useful in more spots; configuration now properly loads an environment config as well as defaults; updated some woodpecker config
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -65,3 +65,6 @@ node_modules/
|
||||
# Compiled assets
|
||||
public/css/
|
||||
public/js/
|
||||
|
||||
# Ignore production configuration files to protect against credential leaks
|
||||
config/production.yaml
|
||||
|
@@ -1,16 +1,28 @@
|
||||
steps:
|
||||
test_ruby34:
|
||||
setup:
|
||||
image: ruby:3.4
|
||||
env:
|
||||
RACK_ENV: testing
|
||||
commands:
|
||||
- gem install rake
|
||||
- bundle config set --local path "vendor/bundle"
|
||||
- bundle install
|
||||
- rake db:migrate
|
||||
|
||||
test_ruby34:
|
||||
image: ruby:3.4
|
||||
env:
|
||||
RACK_ENV: testing
|
||||
commands:
|
||||
- gem install rake
|
||||
- bundle config set --local path "vendor/bundle"
|
||||
- rake test:unit
|
||||
group: tests
|
||||
|
||||
style:
|
||||
image: ruby:3.4
|
||||
env:
|
||||
RACK_ENV: testing
|
||||
commands:
|
||||
- gem install rake
|
||||
- bundle config set --local path "vendor/bundle"
|
||||
|
13
Rakefile
13
Rakefile
@@ -3,18 +3,22 @@ require 'bundler/setup'
|
||||
namespace :db do
|
||||
desc 'Run migrations'
|
||||
task :migrate, [:version] do |t, args|
|
||||
require "sequel/core"
|
||||
require 'sequel/core'
|
||||
# load configuration
|
||||
require_relative 'src/config'
|
||||
conf = Config.new()
|
||||
|
||||
Sequel.extension :migration
|
||||
version = args[:version].to_i if args[:version]
|
||||
Sequel.connect('sqlite://data/gamedata.db') do |db|
|
||||
Sequel::Migrator.run(db, "db/migrations", target: version)
|
||||
Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database')) do |db|
|
||||
Sequel::Migrator.run(db, 'db/migrations', target: version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :server do
|
||||
task :start do
|
||||
ENV['APP_ENV'] = 'production'
|
||||
ENV['RACK_ENV'] = 'production'
|
||||
system("puma")
|
||||
end
|
||||
|
||||
@@ -32,4 +36,3 @@ namespace :test do
|
||||
system("rubocop src/ spec/")
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/gamedata.db'
|
||||
server:
|
||||
host: '0.0.0.0'
|
||||
port: '9292'
|
||||
|
||||
testing:
|
||||
minimum_results_required: 3
|
||||
|
3
config/development.yaml
Normal file
3
config/development.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/gamedata.db'
|
@@ -3,7 +3,9 @@ directory app_dir
|
||||
|
||||
environment ENV.fetch('RACK_ENV', 'development')
|
||||
|
||||
bind 'tcp://0.0.0.0:9292'
|
||||
require_relative '../src/config'
|
||||
conf = Config.new()
|
||||
|
||||
bind "tcp://#{conf.get('server.host')}:#{conf.get('server.port')}"
|
||||
workers 2
|
||||
threads 1, 5
|
||||
|
||||
|
3
config/testing.yaml
Normal file
3
config/testing.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/gamedata_testing.db'
|
@@ -6,11 +6,13 @@ require 'yaml'
|
||||
class Config
|
||||
|
||||
DEFAULT_CONFIG = 'config/defaults.yaml'
|
||||
ENVIRONMENT_CONFIG = ENV.fetch('RACK_ENV', 'development')
|
||||
|
||||
def initialize(config_path)
|
||||
def initialize(config_path = "config/#{ENVIRONMENT_CONFIG}.yaml")
|
||||
@data = YAML.load_file(DEFAULT_CONFIG)
|
||||
|
||||
# merge in user-defined configuration if it exists
|
||||
puts "Merging #{config_path} with #{DEFAULT_CONFIG}."
|
||||
@data.merge!(YAML.load_file(config_path)) if File.exist?(config_path)
|
||||
end
|
||||
|
||||
|
@@ -6,7 +6,8 @@ require 'sqlite3'
|
||||
|
||||
require_relative 'config'
|
||||
|
||||
$conf = Config.new(File.join(__dir__, 'config/defaults.yaml'))
|
||||
# Load configuration from environment config file
|
||||
$conf = Config.new()
|
||||
|
||||
# Load the Sequel timestamps plugin
|
||||
Sequel::Model.plugin(:timestamps)
|
||||
|
Reference in New Issue
Block a user