From 56033763555e88a00a979ce95f59506b4f797e7a Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 17 Dec 2024 14:25:42 +0100 Subject: [PATCH 1/5] Add hypernode docs for NextJS example --- .../applications/config-for-nextjs.md | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 docs/hypernode-deploy/applications/config-for-nextjs.md diff --git a/docs/hypernode-deploy/applications/config-for-nextjs.md b/docs/hypernode-deploy/applications/config-for-nextjs.md new file mode 100644 index 00000000..a464f3bc --- /dev/null +++ b/docs/hypernode-deploy/applications/config-for-nextjs.md @@ -0,0 +1,129 @@ +# Config for Magento 2 + +```{note} +NextJS is not officially supported on the Hypernode Platform. So please use this at your own risk,. +``` + +Configuration to use as Hypernode Deploy deploy.php for a NextJS webserver application: + +```php +> ~/.bashrc'); + run('source ~/.bashrc'); + } + + run('npm install -g pm2 --prefix /data/web/.local'); +}); + +task('deploy:pm2:restart', static function() { + within('{{release_path}}', function () { + run('pm2 startOrRestart ecosystem.config.js --env prod'); + }); +}); + +$configuration = new Configuration(); + +$configuration->setPlatformConfigurations([ + new PlatformConfiguration\NginxConfiguration('etc/nginx'), + new PlatformConfiguration\HypernodeSettingConfiguration('supervisor_enabled', 'False'), + new PlatformConfiguration\HypernodeSettingConfiguration('rabbitmq_enabled', 'False'), + new PlatformConfiguration\HypernodeSettingConfiguration('elasticsearch_enabled', 'False'), + new PlatformConfiguration\HypernodeSettingConfiguration('opensearch_enabled', 'False'), + new PlatformConfiguration\HypernodeSettingConfiguration('varnish_enabled', 'False'), + new PlatformConfiguration\HypernodeSettingConfiguration('nodejs_version', '20'), +]); + +$configuration->addBuildTask('node:env'); +$configuration->addBuildTask('node:install'); +$configuration->addBuildTask('node:build'); + +$configuration->addDeployTask('deploy:pm2:install'); +$configuration->addDeployTask('deploy:pm2:restart'); + +$configuration->setSharedFiles([ + '.env' +]); + +$configuration->setDeployExclude([ + './.git', + './deploy.php', + '.gitignore', + './etc' +]); + +$productionStage = $configuration->addStage('production', 'my-next-application.nl'); +$productionStage->addServer('app.hypernode.io'); + +$acceptanceStage = $configuration->addStage('acceptance', 'my-next-application.nl'); +$acceptanceStage->addBrancherServer('app') + ->setLabels(['stage=acceptance']); + +return $configuration; +``` + +This will: + +- Configure the Hypernode settings optimal for the least load of non-used applications and servers. +- Install [PM2](https://pm2.keymetrics.io/) if not present on the server. +- Sets up a vhost for application. +- Sets up the nginx configuration to proxy to the NextJS server. + +You will still need to add the nginx configuration file, so create the `./etc/nginx/server.headless.conf` file: + +```nginx +location / { + proxy_pass http://localhost:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_cache_bypass $http_upgrade; + + # Optional: set maximum response time to 60 seconds + proxy_read_timeout 60s; + proxy_connect_timeout 60s; +} + +# Optional: specific location for static assets if they are served by Next.js +location /_next/ { + proxy_pass http://localhost:3000; + proxy_cache_bypass $http_upgrade; +} +``` + +And to save configuration about pm2, add the `ecosystem.config.js` file: + +``` +module.exports = { + apps: [ + { + name: 'my-next-app', + exec_mode: 'cluster', + instances: 'max', // Or a number of instances + script: 'node_modules/next/dist/bin/next', + args: 'start' + } + ] + } +``` \ No newline at end of file From b453f8cb3d7a625d1c8448f666508db18ae31c21 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 17 Dec 2024 13:35:21 +0000 Subject: [PATCH 2/5] Fix markdown linting --- docs/hypernode-deploy/applications/config-for-nextjs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hypernode-deploy/applications/config-for-nextjs.md b/docs/hypernode-deploy/applications/config-for-nextjs.md index a464f3bc..6e4ee76c 100644 --- a/docs/hypernode-deploy/applications/config-for-nextjs.md +++ b/docs/hypernode-deploy/applications/config-for-nextjs.md @@ -114,7 +114,7 @@ location /_next/ { And to save configuration about pm2, add the `ecosystem.config.js` file: -``` +```js module.exports = { apps: [ { From 2c89764bb25acc9a44fb29610b29c36b7fc54646 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 17 Dec 2024 14:08:14 +0000 Subject: [PATCH 3/5] Rename article title to NextJS --- docs/hypernode-deploy/applications/config-for-nextjs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hypernode-deploy/applications/config-for-nextjs.md b/docs/hypernode-deploy/applications/config-for-nextjs.md index 6e4ee76c..0a1c741d 100644 --- a/docs/hypernode-deploy/applications/config-for-nextjs.md +++ b/docs/hypernode-deploy/applications/config-for-nextjs.md @@ -1,4 +1,4 @@ -# Config for Magento 2 +# Config for NextJS ```{note} NextJS is not officially supported on the Hypernode Platform. So please use this at your own risk,. From 03c2999808aa4126273afa3454923ec83d5fd062 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Wed, 18 Dec 2024 15:15:21 +0100 Subject: [PATCH 4/5] Remove unused node:env step from NestJS configuration --- docs/hypernode-deploy/applications/config-for-nextjs.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/hypernode-deploy/applications/config-for-nextjs.md b/docs/hypernode-deploy/applications/config-for-nextjs.md index 0a1c741d..578f67c1 100644 --- a/docs/hypernode-deploy/applications/config-for-nextjs.md +++ b/docs/hypernode-deploy/applications/config-for-nextjs.md @@ -53,7 +53,6 @@ $configuration->setPlatformConfigurations([ new PlatformConfiguration\HypernodeSettingConfiguration('nodejs_version', '20'), ]); -$configuration->addBuildTask('node:env'); $configuration->addBuildTask('node:install'); $configuration->addBuildTask('node:build'); From f508d222f14cd10204575ef819853bbd60889309 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Fri, 20 Dec 2024 14:32:45 +0000 Subject: [PATCH 5/5] Add new line to fix formatting issues --- docs/hypernode-deploy/applications/config-for-nextjs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hypernode-deploy/applications/config-for-nextjs.md b/docs/hypernode-deploy/applications/config-for-nextjs.md index 578f67c1..5f276c20 100644 --- a/docs/hypernode-deploy/applications/config-for-nextjs.md +++ b/docs/hypernode-deploy/applications/config-for-nextjs.md @@ -125,4 +125,4 @@ module.exports = { } ] } -``` \ No newline at end of file +```