mirror of
https://github.com/vale981/phoebe
synced 2025-03-05 09:51:37 -05:00
rails: Add options for database pool size and connection timeout
Improvements: * Added new database options * Added first test file
This commit is contained in:
parent
4043563dbc
commit
96ac477d36
17 changed files with 141 additions and 8 deletions
|
@ -44,6 +44,12 @@ Module List
|
|||
Simple way to configure a whole network of WireGuard machines.
|
||||
|
||||
|
||||
Running Tests
|
||||
-------------
|
||||
|
||||
$ nix-build test
|
||||
|
||||
|
||||
[nixos]: https://nixos.org/
|
||||
[nixpkgs]: https://nixos.org/nixpkgs/
|
||||
[phoebe]: https://en.wikipedia.org/wiki/Phoebe_(moon)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<%= ENV['RAILS_ENV'] %>:
|
||||
adapter: postgresql
|
||||
encoding: unicode
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
pool: <%= ENV['DATABASE_POOL_SIZE'] %>
|
||||
timeout: <%= ENV['DATABASE_TIMEOUT'] %>
|
||||
host: <%= ENV['DATABASE_HOST'] %>
|
||||
port: <%= ENV['DATABASE_PORT'] %>
|
||||
database: <%= ENV['DATABASE_NAME'] %>
|
||||
|
|
|
@ -21,6 +21,8 @@ rec {
|
|||
DATABASE_PORT = toString app.database.port;
|
||||
DATABASE_NAME = app.database.name;
|
||||
DATABASE_USER = app.database.user;
|
||||
DATABASE_POOL_SIZE = toString app.database.pool;
|
||||
DATABASE_TIMEOUT = toString app.database.timeout;
|
||||
DATABASE_PASSWORD_FILE = "${app.home}/state/database.password";
|
||||
} // app.environment;
|
||||
|
||||
|
|
|
@ -45,10 +45,24 @@ let
|
|||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
type = types.ints.positive;
|
||||
default = config.services.postgresql.port;
|
||||
description = "Port number for the database server";
|
||||
};
|
||||
|
||||
pool = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 10;
|
||||
example = 5;
|
||||
description = "Size of connection pool.";
|
||||
};
|
||||
|
||||
timeout = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 1000;
|
||||
example = 5000;
|
||||
description = "Database timeout in milliseconds.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ let
|
|||
|
||||
preStart = optionalString (service.isMain || service.isMigration) ''
|
||||
# Link the package into the application's home directory:
|
||||
if [ ! -e "${funcs.appLink app}" ] || [ "${toString app.deployedExternally}" -ne 1 ]; then
|
||||
if [ ! -e "${funcs.appLink app}" ] || [ -z "${toString app.deployedExternally}" ]; then
|
||||
ln -nfs "${app.package}" "${funcs.appLink app}"
|
||||
fi
|
||||
|
||||
|
@ -82,9 +82,9 @@ let
|
|||
rm -rf ${app.home}/config
|
||||
mkdir -p ${app.home}/{config,log,tmp,db,state}
|
||||
cp -rf ${funcs.appLink app}/share/${app.name}/config.dist/* ${app.home}/config/
|
||||
cp ${funcs.appLink app}/share/${app.name}/db/schema.rb.dist ${app.home}/db/schema.rb
|
||||
cp ${./database.yml} ${app.home}/config/database.yml
|
||||
cp ${app.database.passwordFile} ${app.home}/state/database.password
|
||||
cp -f ${funcs.appLink app}/share/${app.name}/db/schema.rb.dist ${app.home}/db/schema.rb
|
||||
cp -f ${./database.yml} ${app.home}/config/database.yml
|
||||
cp -f ${app.database.passwordFile} ${app.home}/state/database.password
|
||||
|
||||
# Additional set up for the home directory:
|
||||
mkdir -p ${app.home}/home
|
||||
|
@ -96,7 +96,7 @@ let
|
|||
|
||||
# Copy the sourcedFile if necessary:
|
||||
${optionalString (app.sourcedFile != null) ''
|
||||
cp ${app.sourcedFile} ${app.home}/state/sourcedFile.sh
|
||||
cp -f ${app.sourcedFile} ${app.home}/state/sourcedFile.sh
|
||||
''}
|
||||
|
||||
# Fix permissions:
|
||||
|
|
8
test/default.nix
Normal file
8
test/default.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
}:
|
||||
|
||||
with pkgs;
|
||||
|
||||
{
|
||||
rails = (callPackage ./services/web/rails/test.nix {}).test;
|
||||
}
|
2
test/services/web/rails/app/Gemfile
Normal file
2
test/services/web/rails/app/Gemfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
source 'https://rubygems.org'
|
||||
gem('rake')
|
13
test/services/web/rails/app/Gemfile.lock
Normal file
13
test/services/web/rails/app/Gemfile.lock
Normal file
|
@ -0,0 +1,13 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
rake (12.3.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
rake
|
||||
|
||||
BUNDLED WITH
|
||||
1.17.2
|
1
test/services/web/rails/app/README.md
Normal file
1
test/services/web/rails/app/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
This is a fake Ruby on Rails application for testing.
|
19
test/services/web/rails/app/Rakefile
Normal file
19
test/services/web/rails/app/Rakefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
# A bunch of dummy rake tasks:
|
||||
|
||||
namespace :db do
|
||||
task :migrate do
|
||||
puts "db:migrate"
|
||||
end
|
||||
|
||||
namespace :schema do
|
||||
task :load do
|
||||
puts "db:schema:load"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :assets do
|
||||
task :precompile do
|
||||
puts "assets:precompile"
|
||||
end
|
||||
end
|
0
test/services/web/rails/app/config/database.yml
Normal file
0
test/services/web/rails/app/config/database.yml
Normal file
0
test/services/web/rails/app/config/secrets.yml
Normal file
0
test/services/web/rails/app/config/secrets.yml
Normal file
0
test/services/web/rails/app/db/schema.rb
Normal file
0
test/services/web/rails/app/db/schema.rb
Normal file
27
test/services/web/rails/app/default.nix
Normal file
27
test/services/web/rails/app/default.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{ pkgs ? import <nixpkgs> { }
|
||||
}:
|
||||
|
||||
let
|
||||
phoebe = import ../../../../../helpers.nix { inherit pkgs; };
|
||||
|
||||
puma = pkgs.writeShellScriptBin "puma" ''
|
||||
# Loop forever:
|
||||
while :; do :; done
|
||||
'';
|
||||
|
||||
env = pkgs.bundlerEnv {
|
||||
name = "app-env";
|
||||
ruby = pkgs.ruby;
|
||||
gemfile = ./Gemfile;
|
||||
lockfile = ./Gemfile.lock;
|
||||
gemset = ./nix/gemset.nix;
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
phoebe.mkRailsDerivation {
|
||||
inherit env;
|
||||
name = "app";
|
||||
src = ./.;
|
||||
extraPackages = [ puma ];
|
||||
}
|
12
test/services/web/rails/app/nix/gemset.nix
Normal file
12
test/services/web/rails/app/nix/gemset.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
rake = {
|
||||
groups = ["default"];
|
||||
platforms = [];
|
||||
source = {
|
||||
remotes = ["https://rubygems.org"];
|
||||
sha256 = "1cvaqarr1m84mhc006g3l1vw7sa5qpkcw0138lsxlf769zdllsgp";
|
||||
type = "gem";
|
||||
};
|
||||
version = "12.3.3";
|
||||
};
|
||||
}
|
29
test/services/web/rails/test.nix
Normal file
29
test/services/web/rails/test.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
}:
|
||||
|
||||
pkgs.nixosTest {
|
||||
name = "rails-test";
|
||||
|
||||
nodes = {
|
||||
simple = {config, pkgs, ...}: {
|
||||
imports = [ ../../../../modules ];
|
||||
phoebe.security.enable = false;
|
||||
phoebe.services.rails.apps.app = {
|
||||
package = import ./app/default.nix { inherit pkgs; };
|
||||
domain = "foo.example.com";
|
||||
port = 3000;
|
||||
database.name = "app";
|
||||
database.user = "app";
|
||||
database.passwordFile = "/dev/null";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
testScript = ''
|
||||
$simple->start;
|
||||
$simple->waitForUnit("rails-app-main.service");
|
||||
$simple->succeed("railsdo app rake -T");
|
||||
$simple->succeed("test -L /var/lib/rails/app/package");
|
||||
'';
|
||||
}
|
Loading…
Add table
Reference in a new issue