From 0dc416d352f4592a5947422cc44fd35b262ffb38 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Tue, 7 Jan 2025 13:25:14 +1100 Subject: [PATCH] feat: Add nixpacks config --- etc/head.php | 2 +- nixpacks.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 nixpacks.json diff --git a/etc/head.php b/etc/head.php index a4a7dbf..732b11d 100644 --- a/etc/head.php +++ b/etc/head.php @@ -1,7 +1,7 @@ HNSChat diff --git a/nixpacks.json b/nixpacks.json new file mode 100644 index 0000000..c2337b2 --- /dev/null +++ b/nixpacks.json @@ -0,0 +1,46 @@ +{ + "providers": [], + "buildImage": "ghcr.io/railwayapp/nixpacks:ubuntu-1731369831", + "variables": { + "NIXPACKS_METADATA": "php", + "PORT": "80" + }, + "staticAssets": { + "apache.template.conf": "\n ServerName localhost\n DocumentRoot \"${NIXPACKS_PHP_ROOT_DIR:-/app}\"\n\n \n Options Indexes FollowSymLinks\n AllowOverride All\n Require all granted\n \n\n \n SetHandler \"proxy:fcgi://127.0.0.1:9000\"\n \n\n ErrorLog /dev/stdout\n CustomLog /dev/stdout combined\n\n Header always set X-Frame-Options \"SAMEORIGIN\"\n Header always set X-Content-Type-Options \"nosniff\"\n\n RewriteEngine On\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule ^ index.php [QSA,L]\n\n \n Require all denied\n \n", + "php-fpm.conf": "[www]\nlisten = 127.0.0.1:9000\nuser = nobody\npm = dynamic\npm.max_children = 50\npm.min_spare_servers = 4\npm.max_spare_servers = 32\npm.start_servers = 18\nclear_env = no\ncatch_workers_output = yes\n", + "scripts/config/template.mjs": "import { readFile, writeFile } from \"fs/promises\";\nimport { getNixPath } from \"../util/nix.mjs\";\n\nconst replaceStr = input =>\n input\n .replaceAll(/\\${(\\w+)}/g,\n (_all, name) => process.env[name]\n )\n .replaceAll(/\\$!{(\\w+)}/g,\n (_all, exe) => getNixPath(exe)\n )\n\nexport async function compileTemplate(infile, outfile) {\n await writeFile(outfile,\n replaceStr(await readFile(infile, { encoding: 'utf8' })),\n { encoding: 'utf8' })\n}\n", + "scripts/prestart.mjs": "#!/usr/bin/env node\nimport { compileTemplate } from \"./config/template.mjs\";\nimport { e } from \"./util/cmd.mjs\";\n\nif (process.argv.length != 4) {\n console.error(`Usage: ${process.argv[1]} `);\n process.exit(1);\n}\n\nawait compileTemplate(process.argv[2], process.argv[3]);\nconsole.log(`Server starting on port ${process.env.PORT}`);\n", + "scripts/util/cmd.mjs": "import { execSync } from \"child_process\";\nexport const e = cmd => execSync(cmd).toString().replace('\\n', '');" + }, + "phases": { + "install": { + "dependsOn": [ + "setup" + ], + "cmds": [ + "mkdir -p /var/log/apache2 && mkdir -p /var/cache/apache2" + ] + }, + "setup": { + "nixPkgs": [ + "(php83.withExtensions (pe: pe.enabled ++ []))", + "apacheHttpd", + "libmysqlclient", + "php83Packages.composer", + "nodejs_18", + "npm-9_x" + ], + "nixLibs": [ + "libmysqlclient" + ], + "nixOverlays": [ + "https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz" + ], + "nixpkgsArchive": "dbc4f15b899ac77a8d408d8e0f89fa9c0c5f2b78" + } + }, + "start": { + "cmd": "node /assets/scripts/prestart.mjs /assets/apache.template.conf /etc/apache2/sites-available/000-default.conf && a2enmod proxy_fcgi headers rewrite && (php-fpm -y /assets/php-fpm.conf & apachectl -D FOREGROUND)" + } + } + \ No newline at end of file