feat(templates/php): Updated template to use process-compose.

This commit is contained in:
Spencer Brower
2024-03-08 13:46:32 -05:00
parent 0318b2ae1a
commit 8dc7010df3
6 changed files with 175 additions and 20 deletions

1
.gitignore vendored
View File

@@ -0,0 +1 @@
templates/php/.direnv

View File

@@ -1,19 +1,34 @@
(cors) {
@origin header Origin {args[0]}
header @origin Access-Control-Allow-Origin "{args[0]}"
header @origin Access-Control-Allow-Methods "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE"
}
wp.test {
root * .
encode zstd gzip
file_server
php_fastcgi 127.0.0.1:9000
php_fastcgi 127.0.0.1:9009
tls internal
}
laravel.test {
# import cors laravel.test
respond /caddy/live OK
root * ./public
try_files {path} page-cache/{path}.html page-cache/{path}.json page-cache/{path}.xml
encode zstd gzip
file_server
php_fastcgi 127.0.0.1:9000
php_fastcgi 127.0.0.1:9009
# Uncomment for Laravel Octane
# reverse_proxy :8000
tls internal
}
}

View File

@@ -1,2 +0,0 @@
web: sudo caddy run
php: php-fpm -F -y php-fpm.conf

110
templates/php/flake.lock generated Normal file
View File

@@ -0,0 +1,110 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1709336216,
"narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1705331948,
"narHash": "sha256-qjQXfvrAT1/RKDFAMdl8Hw3m4tLVvMCc8fMqzJv0pP4=",
"path": "/nix/store/yy19v2dwb8ldphvia9smajvwv3ycx2c1-source",
"rev": "b8dd8be3c790215716e7c12b247f45ca525867e2",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1709237383,
"narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1667085676,
"narHash": "sha256-jPHYYoSdrV3ypWG4oi9SUeI2MU6dLjxM88+9io5Rrx0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e6e6bad81b7e11f37d893ef39712ce8918ae2338",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"process-compose-flake": {
"locked": {
"lastModified": 1708624100,
"narHash": "sha256-zZPheCD9JGg2EtK4A9BsIdyl8447egOow4fjIfHFHRg=",
"owner": "Platonic-Systems",
"repo": "process-compose-flake",
"rev": "44d260ddba5a51570dee54d5cd4d8984edaf98c2",
"type": "github"
},
"original": {
"owner": "Platonic-Systems",
"repo": "process-compose-flake",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"process-compose-flake": "process-compose-flake",
"sbrow": "sbrow"
}
},
"sbrow": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1703272630,
"narHash": "sha256-2od1Ocy53GwXSFMI1/R8xBVuvr08tf/9mTpyBwVl0ns=",
"owner": "sbrow",
"repo": "nix",
"rev": "0318b2ae1aa897e67fffa52d9d0c05bd1b9eccfc",
"type": "github"
},
"original": {
"owner": "sbrow",
"repo": "nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View File

@@ -3,31 +3,62 @@
inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs/23.11";
# dolt.url = "github:sbrow/dolt";
# phps.url = "github:fossar/nix-phps";
# phps.inputs.nixpkgs.follows = "nixpkgs";
sbrow.url = "github:sbrow/nix";
flake-parts.url = "github:hercules-ci/flake-parts";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
};
outputs = inputs@{ self, flake-parts, nixpkgs, /* phps, */ sbrow }:
outputs = inputs@{ self, flake-parts, nixpkgs, /* phps, */ process-compose-flake, sbrow }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.process-compose-flake.flakeModule
];
systems = [ "x86_64-linux" ];
perSystem = { pkgs, system, ... }:
/* let phpPkgs = phps.legacyPackages.${system}; in */ {
formatter = pkgs.nixpkgs-fmt;
perSystem =
{ pkgs, system, inputs', ... }:
let
php = pkgs.php.buildEnv {
extensions = ({ enabled, all }: enabled ++ (with all; [
xdebug
]));
extraConfig = ''
; xdebug 3
xdebug.mode=debug
xdebug.client_port=9000
devShells.default = pkgs.mkShell
{
buildInputs = with pkgs; [
caddy
foreman
php
phpPackages.composer
];
; xdebug 2
xdebug.remote_enable=1
'';
};
};
in
{
formatter = pkgs.nixpkgs-fmt;
process-compose.default.settings.processes = {
web.command = "sudo ${pkgs.caddy}/bin/caddy run";
mail.command = "${pkgs.mailhog}/bin/MailHog";
php.command = "${php}/bin/php-fpm -F -y php-fpm.conf";
# redis.command = "${$pks.redis}/bin/redis-server";
# db.command = "${doltPkg}/bin/dolt sql-server --config dolt.yml";
};
devShells.default = pkgs.mkShell
{
buildInputs = with pkgs; [
caddy
php
php.packages.composer
php.packages.phpcbf
php.packages.phpcs
];
};
};
};
}

View File

@@ -4,11 +4,11 @@ error_log = /dev/stderr
[site]
;access.log = /proc/self/fd/2
access.log = /dev/stderr
listen = 127.0.0.1:9000
listen = 127.0.0.1:9009
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.process_idle_timeout = 10s
pm.process_idle_timeout = 10s