mirror of
https://codeberg.org/demostf/api-client.git
synced 2026-06-03 08:34:15 +02:00
flake reorg, nix integration testing
This commit is contained in:
parent
06b003ec6e
commit
5cfd70d583
14 changed files with 3221 additions and 145 deletions
27
nix/demostf-api.nix
Normal file
27
nix/demostf-api.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
php,
|
||||
fetchFromGitHub,
|
||||
}: let
|
||||
phpWithExtensions = php.withExtensions ({
|
||||
enabled,
|
||||
all,
|
||||
}:
|
||||
enabled ++ (with all; [pdo apcu]));
|
||||
in
|
||||
phpWithExtensions.buildComposerProject (finalAttrs: {
|
||||
pname = "demostf-api";
|
||||
version = "0.1.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "demostf";
|
||||
repo = "api";
|
||||
rev = "1a8380360b993226ae1c6fcc226011e03a6c1467";
|
||||
hash = "sha256-JcBRU1N44tt0QDLnj6z9MCT3V2s2dkf+JbpWb1rmXnY=";
|
||||
};
|
||||
|
||||
vendorHash = "sha256-EYWCR2aJAoyWvEX+SML4Fb3F3KGcUtwCgqhAGT6ZjZ4=";
|
||||
|
||||
composerStrictValidation = false;
|
||||
|
||||
doCheck = false;
|
||||
})
|
||||
23
nix/demostf-parser.nix
Normal file
23
nix/demostf-parser.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
rustPlatform,
|
||||
fetchFromGitHub,
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "demostf-parser";
|
||||
version = "0.5.1";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "demostf";
|
||||
repo = "parser";
|
||||
rev = "0cd87a8a40e2a6af637d831b272c2758cebd2f9c";
|
||||
hash = "sha256-bKcc0hWTkdYUDMI/DjUh45abuBeQEvkn6TsuAz02H5Y=";
|
||||
};
|
||||
|
||||
cargoBuildFlags = ''
|
||||
--bin parse_demo
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
|
||||
cargoHash = "sha256-/Fnw6l2fznrBK780E4q1PKFOkT0eiL+dE+UuhFA+V9M=";
|
||||
}
|
||||
5
nix/overlay.nix
Normal file
5
nix/overlay.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
final: prev: {
|
||||
demostf-api = final.callPackage ./demostf-api.nix {};
|
||||
demostf-parser = final.callPackage ./demostf-parser.nix {};
|
||||
test-runner = final.callPackage ./test-runner.nix {};
|
||||
}
|
||||
42
nix/test-runner.nix
Normal file
42
nix/test-runner.nix
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
rustPlatform,
|
||||
openssl,
|
||||
pkg-config,
|
||||
lib,
|
||||
}: let
|
||||
inherit (lib.sources) sourceByRegex;
|
||||
inherit (builtins) fromTOML readFile;
|
||||
src = sourceByRegex ../. ["Cargo.*" "(src|tests)(/.*)?"];
|
||||
cargoPackage = (fromTOML (readFile ../Cargo.toml)).package;
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = cargoPackage.name;
|
||||
inherit (cargoPackage) version;
|
||||
|
||||
inherit src;
|
||||
|
||||
buildInputs = [
|
||||
openssl
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkg-config
|
||||
];
|
||||
|
||||
doCheck = false;
|
||||
|
||||
buildPhase = ''
|
||||
cargo build --tests
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp target/debug/deps/tests-???????????????? $out/bin/api-test
|
||||
'';
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ../Cargo.lock;
|
||||
};
|
||||
|
||||
meta.mainProgram = "api-test";
|
||||
}
|
||||
126
nix/test.nix
Normal file
126
nix/test.nix
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
name = "demostf-api-client-test";
|
||||
nodes.machine = {config, ...}: let
|
||||
fpmCfg = config.services.phpfpm.pools.demostf-api;
|
||||
in {
|
||||
config = {
|
||||
users.groups.demostf = {};
|
||||
users.users.demostf = {
|
||||
group = "demostf";
|
||||
isSystemUser = true;
|
||||
};
|
||||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = ["demostf"];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "demostf";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
initialScript = pkgs.writeText "init-sql-script" ''
|
||||
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
|
||||
'';
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts."localhost" = {
|
||||
root = "/var/empty";
|
||||
extraConfig = ''
|
||||
try_files $uri /index.php?$query_string /index.php;
|
||||
'';
|
||||
locations = {
|
||||
"~ ^(.+?\\.php)(/.*)?$" = {
|
||||
extraConfig = ''
|
||||
fastcgi_param PATH_INFO $2;
|
||||
fastcgi_pass unix:${fpmCfg.socket};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME ${pkgs.demostf-api}/share/php/demostf-api/src/public/index.php;
|
||||
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||
client_max_body_size 250m;
|
||||
'';
|
||||
};
|
||||
"= /upload" = {
|
||||
extraConfig = ''
|
||||
fastcgi_pass unix:${fpmCfg.socket};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME ${pkgs.demostf-api}/share/php/demostf-api/src/public/upload.php;
|
||||
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||
client_max_body_size 250m;
|
||||
'';
|
||||
};
|
||||
"/static/" = {
|
||||
alias = "/demos/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.phpfpm.pools.demostf-api = {
|
||||
phpPackage = pkgs.php.buildEnv {
|
||||
extensions = {
|
||||
enabled,
|
||||
all,
|
||||
}:
|
||||
enabled ++ (with all; [pdo apcu]);
|
||||
extraConfig = ''
|
||||
post_max_size = 150M
|
||||
upload_max_filesize = 150M
|
||||
'';
|
||||
};
|
||||
settings = {
|
||||
"clear_env" = "no";
|
||||
"pm" = "dynamic";
|
||||
"pm.max_children" = "25";
|
||||
"pm.start_servers" = "5";
|
||||
"pm.min_spare_servers" = "5";
|
||||
"pm.max_spare_servers" = "15";
|
||||
"catch_workers_output" = "yes";
|
||||
"listen.owner" = "nginx";
|
||||
"listen.group" = "nginx";
|
||||
};
|
||||
phpEnv = {
|
||||
BASE_HOST = "demos.tf";
|
||||
DEMO_ROOT = "/demos";
|
||||
DEMO_HOST = "localhost";
|
||||
DB_TYPE = "pgsql";
|
||||
DB_HOST = "/run/postgresql";
|
||||
DB_PORT = "5432";
|
||||
DB_DATABASE = "demostf";
|
||||
DB_USERNAME = "demostf";
|
||||
APP_ROOT = "http://localhost";
|
||||
EDIT_SECRET = "edit";
|
||||
PARSER_PATH = "${pkgs.demostf-parser}/bin/parse_demo";
|
||||
};
|
||||
user = "demostf";
|
||||
group = "demostf";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = let
|
||||
testBinary = lib.getExe pkgs.test-runner;
|
||||
initSql = pkgs.fetchurl {
|
||||
url = "https://github.com/demostf/db/raw/refs/heads/master/schema.sql";
|
||||
hash = "sha256-AwXN9mh9CRk6HWdvyUR+YdBkpmExNIDOIeDMz6XqjEQ=";
|
||||
};
|
||||
in ''
|
||||
machine.succeed("mkdir /demos && chmod 0777 /demos");
|
||||
machine.wait_for_unit("postgresql")
|
||||
machine.succeed("sudo -u demostf psql demostf demostf < ${initSql}");
|
||||
machine.succeed("sudo -u postgres psql postgres postgres -c \"alter user demostf with password 'test';\"");
|
||||
machine.wait_for_unit("phpfpm-demostf-api")
|
||||
machine.wait_for_unit("nginx")
|
||||
machine.wait_until_succeeds("curl http://127.0.0.1", timeout=45)
|
||||
machine.succeed("DB_URL='postgres://demostf:test@localhost/demostf'\
|
||||
TEST_DEMO='${../tests/data/gully.dem}'\
|
||||
API_ROOT='http://localhost/'\
|
||||
${testBinary} --test-threads 1", timeout=180)
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue