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
|
# Compiled assets
|
||||||
public/css/
|
public/css/
|
||||||
public/js/
|
public/js/
|
||||||
|
|
||||||
|
# Ignore production configuration files to protect against credential leaks
|
||||||
|
config/production.yaml
|
||||||
|
@@ -1,16 +1,28 @@
|
|||||||
steps:
|
steps:
|
||||||
test_ruby34:
|
setup:
|
||||||
image: ruby:3.4
|
image: ruby:3.4
|
||||||
|
env:
|
||||||
|
RACK_ENV: testing
|
||||||
commands:
|
commands:
|
||||||
- gem install rake
|
- gem install rake
|
||||||
- bundle config set --local path "vendor/bundle"
|
- bundle config set --local path "vendor/bundle"
|
||||||
- bundle install
|
- bundle install
|
||||||
- rake db:migrate
|
- 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
|
- rake test:unit
|
||||||
group: tests
|
group: tests
|
||||||
|
|
||||||
style:
|
style:
|
||||||
image: ruby:3.4
|
image: ruby:3.4
|
||||||
|
env:
|
||||||
|
RACK_ENV: testing
|
||||||
commands:
|
commands:
|
||||||
- gem install rake
|
- gem install rake
|
||||||
- bundle config set --local path "vendor/bundle"
|
- bundle config set --local path "vendor/bundle"
|
||||||
|
13
Rakefile
13
Rakefile
@@ -3,18 +3,22 @@ require 'bundler/setup'
|
|||||||
namespace :db do
|
namespace :db do
|
||||||
desc 'Run migrations'
|
desc 'Run migrations'
|
||||||
task :migrate, [:version] do |t, args|
|
task :migrate, [:version] do |t, args|
|
||||||
require "sequel/core"
|
require 'sequel/core'
|
||||||
|
# load configuration
|
||||||
|
require_relative 'src/config'
|
||||||
|
conf = Config.new()
|
||||||
|
|
||||||
Sequel.extension :migration
|
Sequel.extension :migration
|
||||||
version = args[:version].to_i if args[:version]
|
version = args[:version].to_i if args[:version]
|
||||||
Sequel.connect('sqlite://data/gamedata.db') do |db|
|
Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database')) do |db|
|
||||||
Sequel::Migrator.run(db, "db/migrations", target: version)
|
Sequel::Migrator.run(db, 'db/migrations', target: version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :server do
|
namespace :server do
|
||||||
task :start do
|
task :start do
|
||||||
ENV['APP_ENV'] = 'production'
|
ENV['RACK_ENV'] = 'production'
|
||||||
system("puma")
|
system("puma")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -32,4 +36,3 @@ namespace :test do
|
|||||||
system("rubocop src/ spec/")
|
system("rubocop src/ spec/")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
database:
|
server:
|
||||||
adapter: 'sqlite'
|
host: '0.0.0.0'
|
||||||
database: 'data/gamedata.db'
|
port: '9292'
|
||||||
|
|
||||||
testing:
|
testing:
|
||||||
minimum_results_required: 3
|
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')
|
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
|
workers 2
|
||||||
threads 1, 5
|
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
|
class Config
|
||||||
|
|
||||||
DEFAULT_CONFIG = 'config/defaults.yaml'
|
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)
|
@data = YAML.load_file(DEFAULT_CONFIG)
|
||||||
|
|
||||||
# merge in user-defined configuration if it exists
|
# 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)
|
@data.merge!(YAML.load_file(config_path)) if File.exist?(config_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -6,7 +6,8 @@ require 'sqlite3'
|
|||||||
|
|
||||||
require_relative 'config'
|
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
|
# Load the Sequel timestamps plugin
|
||||||
Sequel::Model.plugin(:timestamps)
|
Sequel::Model.plugin(:timestamps)
|
||||||
|
Reference in New Issue
Block a user