From 81dc138e6940eaaf7f781536d601d0f883cce1f1 Mon Sep 17 00:00:00 2001 From: kurogeek Date: Tue, 25 Nov 2025 13:50:09 +0700 Subject: [PATCH] mob next [ci-skip] [ci skip] [skip ci] lastFile:tests/tests/think-gtcm.nix --- .nixos-test-history | 135 +++++++++++++++++++++++++++++++++++ modules/nixos/think-gtcm.nix | 99 ++++++------------------- tests/tests/think-gtcm.nix | 48 ++++++++----- 3 files changed, 184 insertions(+), 98 deletions(-) diff --git a/.nixos-test-history b/.nixos-test-history index e2601a2..212e984 100644 --- a/.nixos-test-history +++ b/.nixos-test-history @@ -97,3 +97,138 @@ # 2025-11-24 16:26:24.656220 +start_all() + +# 2025-11-25 10:47:30.543608 ++print(node1.execute("ls -al /run/")[1]) + +# 2025-11-25 10:47:47.291394 ++print(node1.execute("ls -al /run/think-gtcm")[1]) + +# 2025-11-25 10:51:09.769262 ++start_all() + +# 2025-11-25 11:00:34.699136 ++print(node1.execute("ls -al /run/think-gtcm")[1]) + +# 2025-11-25 11:05:01.639108 ++start_all() + +# 2025-11-25 11:05:52.361090 ++print(node1.execute("ls -al /run/think-gtcm")[1]) + +# 2025-11-25 11:06:02.844430 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 11:13:23.088862 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost")[1]) + +# 2025-11-25 11:14:01.467493 ++print(node1.execute("ls -al /run/phpfpm/")[1]) + +# 2025-11-25 11:16:13.687663 ++start_all() + +# 2025-11-25 11:16:49.608807 ++print(node1.execute("ls -al /run/phpfpm/")[1]) + +# 2025-11-25 11:16:53.334603 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost")[1]) + +# 2025-11-25 11:17:04.779069 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 11:25:12.482960 ++start_all() + +# 2025-11-25 11:25:51.342181 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 11:40:18.001245 ++print(node1.execute("ls -al /var/lib/")[1]) + +# 2025-11-25 11:40:37.001361 ++print(node1.execute("ls -al /var/lib/think.greaterchiangmai.com")[1]) + +# 2025-11-25 11:40:54.438752 ++print(node1.execute("cat /var/lib/think.greaterchiangmai.com/.env")[1]) + +# 2025-11-25 11:41:19.519497 ++print(node1.execute("ls -al /var/lib/think.greaterchiangmai.com/storage")[1]) + +# 2025-11-25 11:41:42.426706 ++print(node1.execute("ls -al /var/lib/think.greaterchiangmai.com/storage/framework")[1]) + +# 2025-11-25 11:41:46.387743 ++print(node1.execute("ls -al /var/lib/think.greaterchiangmai.com/storage/framework/cache")[1]) + +# 2025-11-25 11:41:58.617088 ++print(node1.execute("ls -al /var/lib/think.greaterchiangmai.com/public")[1]) + +# 2025-11-25 12:02:32.221565 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 12:05:35.375896 ++print(node1.execute("php")[1]) + +# 2025-11-25 12:06:20.909218 ++print(node1.execute("gtcm")[1]) + +# 2025-11-25 12:06:51.242291 ++print(node1.execute("gtcm config:cache")[1]) + +# 2025-11-25 12:07:17.385975 ++print(node1.execute("gtcm view:cache")[1]) + +# 2025-11-25 12:07:24.634055 ++print(node1.execute("gtcm view:clear")[1]) + +# 2025-11-25 12:08:50.031451 ++start_all() + +# 2025-11-25 12:09:24.686449 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 12:12:31.634657 ++start_all() + +# 2025-11-25 12:13:32.195413 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 12:57:53.552844 ++start_all() + +# 2025-11-25 12:58:35.119916 ++print(node1.execute("curl localhost")[1]) + +# 2025-11-25 13:03:51.177495 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost")[1]) + +# 2025-11-25 13:04:11.541577 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost/")[1]) + +# 2025-11-25 13:04:16.055561 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost/asdfasdkfj")[1]) + +# 2025-11-25 13:04:27.300525 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost/web")[1]) + +# 2025-11-25 13:04:34.302473 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost")[1]) + +# 2025-11-25 13:06:02.700710 ++print(node1.execute("artisan")[1]) + +# 2025-11-25 13:06:09.844650 ++print(node1.execute("gtcm")[1]) + +# 2025-11-25 13:21:23.388725 ++start_all() + +# 2025-11-25 13:22:15.869361 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost")[1]) + +# 2025-11-25 13:40:50.043328 ++print(node1.execute("curl -H 'Host: think.greaterchiangmai.com' localhost/category/chiangmai")[1]) + +# 2025-11-25 13:41:54.180205 ++print(node1.execute("journalctl -u phpfpm-think-gtcm")[1]) diff --git a/modules/nixos/think-gtcm.nix b/modules/nixos/think-gtcm.nix index b6c981e..ee9fdc4 100644 --- a/modules/nixos/think-gtcm.nix +++ b/modules/nixos/think-gtcm.nix @@ -13,8 +13,8 @@ let php = pkgs.php83; - artisan = pkgs.writeShellScript "gtcm" '' - #! #{pkgs.runtimeShell} + artisan = pkgs.writeScriptBin "gtcm" '' + #! ${pkgs.runtimeShell} cd ${think-gtcm} sudo() { if [[ "$USER" != ${cfg.user} ]]; then @@ -23,11 +23,11 @@ let exec "$@" fi } - sudo ${php} artisan "$@" + sudo ${lib.getExe php} artisan "$@" ''; - artisan-be = pkgs.writeShellScript "gtcm-be" '' - #! #{pkgs.runtimeShell} - cd ${think-gtcm} + artisan-be = pkgs.writeScriptBin "gtcm-be" '' + #! ${pkgs.runtimeShell} + cd ${think-backend-gtcm} sudo() { if [[ "$USER" != ${cfg.user} ]]; then exec /run/wrappers/bin/sudo -u ${cfg.user} "$@" @@ -35,7 +35,7 @@ let exec "$@" fi } - sudo ${php} artisan "$@" + sudo ${lib.getExe php} artisan "$@" ''; in @@ -83,7 +83,7 @@ in }; settings = lib.mkOption { - lib.type = + type = with lib.types; attrsOf ( nullOr ( @@ -133,70 +133,6 @@ in DB_PASSWORD = ""; } ''; - type = lib.types.submodule { - freeformType = lib.types.attrsOf ( - lib.types.oneOf [ - lib.types.str - lib.types.int - lib.types.bool - ] - ); - options = { - DB_CONNECTION = lib.mkOption { - type = lib.types.enum [ - "mysql" - ]; - default = "mysql"; - example = "mysql"; - description = '' - The type of database you wish to use. only "mysql". - ''; - }; - DB_HOST = lib.mkOption { - type = lib.types.str; - default = if cfg.settings.DB_CONNECTION == "pgsql" then "/run/postgresql" else "localhost"; - defaultText = '' - "localhost" if DB_CONNECTION is "sqlite" or "mysql", "/run/postgresql" if "pgsql". - ''; - description = '' - The machine which hosts your database. This is left at the - default value for "mysql" because we use the "DB_SOCKET" option - to connect to a unix socket instead. "pgsql" requires that the - unix socket location be specified here instead of at "DB_SOCKET". - This option does not affect "sqlite". - ''; - }; - DB_PORT = lib.mkOption { - type = lib.types.nullOr lib.types.int; - default = - if cfg.settings.DB_CONNECTION == "pgsql" then - 5432 - else if cfg.settings.DB_CONNECTION == "mysql" then - 3306 - else - null; - defaultText = '' - `null` if DB_CONNECTION is "sqlite", `3306` if "mysql", `5432` if "pgsql" - ''; - description = '' - The port your database is listening at. sqlite does not require - this value to be filled. - ''; - }; - DB_DATABASE = lib.mkOption { - type = lib.types.str; - default = "thinkgreatercm"; - }; - DB_USERNAME = lib.mkOption { - type = lib.types.str; - default = "thinkgreatercm"; - }; - DB_PASSWORD = lib.mkOption { - type = lib.types.str; - default = "thinkgreatercm"; - }; - }; - }; }; }; @@ -214,8 +150,8 @@ in inherit (cfg) user group; phpPackage = php; settings = { - "listen.owner" = cfg.user; - "listen.group" = cfg.group; + "listen.owner" = config.services.nginx.user; + "listen.group" = config.services.nginx.group; "listen.mode" = "0600"; "pm" = lib.mkDefault "dynamic"; "pm.max_children" = lib.mkDefault 10; @@ -230,6 +166,11 @@ in ''; }; + environment.systemPackages = [ + artisan + artisan-be + ]; + systemd.services.think-gtcm-setup = { description = "think.greaterchiangmai installation"; requiredBy = [ "phpfpm-think-gtcm.service" ]; @@ -268,7 +209,7 @@ in throw "unsupported type ${typeOf v}: ${(lib.generators.toPretty { }) v}"; }; }; - secretPaths = lib.mapAttrsToList (_: v: v._secret) (lib.filterAttrs (_: isSecret) cfg.config); + secretPaths = lib.mapAttrsToList (_: v: v._secret) (lib.filterAttrs (_: isSecret) cfg.settings); mkSecretReplacement = file: '' replace-secret ${ lib.escapeShellArgs [ @@ -300,9 +241,9 @@ in fi # migrate & seed db - ${php} artisan key:generate --force - ${php} artisan migrate --force - ${php} artisan config:cache + ${lib.getExe php} artisan key:generate --force + ${lib.getExe php} artisan migrate --force + ${lib.getExe php} artisan config:cache ''; }; @@ -329,7 +270,7 @@ in recommendedBrotliSettings = true; recommendedProxySettings = true; virtualHosts."${cfg.domain}" = { - root = "${cfg.package}/share/php/think-gtcm/public"; + root = "${think-gtcm}/public"; locations = { "/" = { index = "index.php"; diff --git a/tests/tests/think-gtcm.nix b/tests/tests/think-gtcm.nix index c0479f0..629c3c9 100644 --- a/tests/tests/think-gtcm.nix +++ b/tests/tests/think-gtcm.nix @@ -10,24 +10,27 @@ services.think-greaterchiangmai = { enable = true; settings = { - - APP_NAME = "Laravel"; - APP_ENV = "local"; - APP_KEY = ""; - APP_DEBUG = "true"; - APP_URL = "http://localhost"; - - LOG_CHANNEL = "stack"; - LOG_DEPRECATIONS_CHANNEL = "null"; - LOG_LEVEL = "debug"; + APP_SERVICES_CACHE = "/run/think-gtcm/cache/services.php"; + APP_PACKAGES_CACHE = "/run/think-gtcm/cache/packages.php"; + APP_CONFIG_CACHE = "/run/think-gtcm/cache/config.php"; + APP_ROUTES_CACHE = "/run/think-gtcm/cache/routes-v7.php"; + APP_EVENTS_CACHE = "/run/think-gtcm/cache/events.php"; DB_CONNECTION = "mysql"; DB_HOST = "localhost"; DB_PORT = 3306; DB_DATABASE = "thinkgtcm"; - DB_USERNAME = "thinkgtcm"; + DB_USERNAME = "gtcm"; DB_PASSWORD = ""; + APP_NAME = "Laravel"; + APP_ENV = "local"; + APP_DEBUG = "false"; + APP_URL = "http://localhost"; + + LOG_CHANNEL = "stack"; + LOG_LEVEL = "debug"; + BROADCAST_DRIVER = "log"; CACHE_DRIVER = "file"; FILESYSTEM_DISK = "local"; @@ -41,19 +44,26 @@ REDIS_PASSWORD = "null"; REDIS_PORT = "6379"; - AWS_ACCESS_KEY_ID = ""; - AWS_SECRET_ACCESS_KEY = ""; + MAIL_MAILER = "smtp"; + MAIL_HOST = "mailpit"; + MAIL_PORT = "1025"; + MAIL_USERNAME = "null"; + MAIL_PASSWORD = "null"; + MAIL_ENCRYPTION = "null"; + MAIL_FROM_ADDRESS = "hello@example.com"; + AWS_DEFAULT_REGION = "us-east-1"; - AWS_BUCKET = ""; AWS_USE_PATH_STYLE_ENDPOINT = "false"; - PUSHER_APP_ID = ""; - PUSHER_APP_KEY = ""; - PUSHER_APP_SECRET = ""; - PUSHER_HOST = ""; PUSHER_PORT = 443; PUSHER_SCHEME = "https"; PUSHER_APP_CLUSTER = "mt1"; + + UPLOAD_MAX_FILESIZE = "5000M"; + POST_MAX_SIZE = "5000M"; + + TEST_LOCAL = "false"; + }; }; }; @@ -62,7 +72,7 @@ testScript = '' start_all() - node1.wait_for_unit("phpfpm-think-greaterchiangmai") + node1.wait_for_unit("phpfpm-think-gtcm") node1.wait_for_open_port(80) output = node1.succeed("curl localhost") '';