From 077467a2c2efa78b52c4fed2fc4fb8fff4a5e259 Mon Sep 17 00:00:00 2001 From: Mehran Date: Fri, 6 Oct 2023 21:34:11 +0300 Subject: [PATCH 1/3] Made TextToArray action work with both ';' and '\n' seperators --- app/Actions/TextToArray.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Actions/TextToArray.php b/app/Actions/TextToArray.php index 6639405..60b3b45 100644 --- a/app/Actions/TextToArray.php +++ b/app/Actions/TextToArray.php @@ -13,6 +13,7 @@ namespace App\Actions; +use Illuminate\Support\Str; use Lorisleiva\Actions\Concerns\AsAction; class TextToArray @@ -21,7 +22,9 @@ class TextToArray public function handle(string $content): array { - parse_str(str_replace("\n", '&', $content), $output); + $separator = Str::contains($content, ';') ? ';' : "\n"; + + parse_str(str_replace($separator, '&', $content), $output); return $output; } From 1b3bbe85c9805ea5dfbee376df080f8d7b4fa479 Mon Sep 17 00:00:00 2001 From: Mehran Date: Fri, 6 Oct 2023 21:34:48 +0300 Subject: [PATCH 2/3] Made the Nginx keys NginxTemplateSearchReplace work with TextToArray action --- app/Actions/SearchReplaceKeysInText.php | 32 ------------------- .../Pipeline/NginxTemplateSearchReplace.php | 13 ++++++-- config/forge.php | 30 ++++++++--------- 3 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 app/Actions/SearchReplaceKeysInText.php diff --git a/app/Actions/SearchReplaceKeysInText.php b/app/Actions/SearchReplaceKeysInText.php deleted file mode 100644 index 672e7ff..0000000 --- a/app/Actions/SearchReplaceKeysInText.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace App\Actions; - -use Lorisleiva\Actions\Concerns\AsAction; - -class SearchReplaceKeysInText -{ - use AsAction; - - public function handle(string $substitutes, string $template): string - { - foreach (explode(',', $substitutes) as $substitute) { - [$key, $value] = explode(':', $substitute, 2); - - $template = str_replace($key, $value, $template); - } - - return $template; - } -} diff --git a/app/Services/Forge/Pipeline/NginxTemplateSearchReplace.php b/app/Services/Forge/Pipeline/NginxTemplateSearchReplace.php index 13a6fb6..c01e981 100644 --- a/app/Services/Forge/Pipeline/NginxTemplateSearchReplace.php +++ b/app/Services/Forge/Pipeline/NginxTemplateSearchReplace.php @@ -13,7 +13,7 @@ namespace App\Services\Forge\Pipeline; -use App\Actions\SearchReplaceKeysInText; +use App\Actions\TextToArray; use App\Services\Forge\ForgeService; use App\Traits\Outputifier; use Closure; @@ -36,7 +36,7 @@ public function __invoke(ForgeService $service, Closure $next) $service->forge->updateSiteNginxFile( $service->setting->server, $service->site->id, - SearchReplaceKeysInText::run( + $this->searchAndReplaceKeys( $service->setting->nginxSubstitute, $template ) @@ -44,4 +44,13 @@ public function __invoke(ForgeService $service, Closure $next) return $next($service); } + + protected function searchAndReplaceKeys(string $substitutes, string $template): string + { + foreach (TextToArray::run($substitutes) as $key => $value) { + $template = str_replace($key, $value, $template); + } + + return $template; + } } diff --git a/config/forge.php b/config/forge.php index 99f643c..39adbee 100644 --- a/config/forge.php +++ b/config/forge.php @@ -13,7 +13,7 @@ // Git service provider (default: 'github'). 'git_provider' => env('FORGE_GIT_PROVIDER', 'github'), - // Git repository URL or name. + // Git repository name. 'repository' => env('FORGE_GIT_REPOSITORY'), // Git branch name. @@ -22,6 +22,18 @@ // Pattern for subdomains. 'subdomain_pattern' => env('FORGE_SUBDOMAIN_PATTERN'), + // Deployment script content. + 'deploy_script' => env('FORGE_DEPLOY_SCRIPT'), + + // Template for Nginx configuration. + 'nginx_template' => env('FORGE_NGINX_TEMPLATE'), + + // Key/value pairs for customizing the Nginx template. + 'nginx_substitute' => env('FORGE_NGINX_SUBSTITUTE'), + + // Key/value pairs to be added to the environment file at runtime. + 'env_keys' => env('FORGE_ENV_KEYS'), + // PHP version (default: 'php82'). 'php_version' => env('FORGE_PHP_VERSION', 'php82'), @@ -40,8 +52,8 @@ // Flag indicating if a database should be created (default: false). 'db_creation_required' => env('FORGE_DB_CREATION_REQUIRED', false), - // Flag to enable SSL certification (default: false). - 'ssl_required' => env('FORGE_SSL_REQUIRED', false), + // Flag to enable SSL certification (default: true). + 'ssl_required' => env('FORGE_SSL_REQUIRED', true), // Flag to pause until SSL setup completes during provisioning (default: true). 'wait_on_ssl' => env('FORGE_WAIT_ON_SSL', true), @@ -49,18 +61,6 @@ // Flag to pause until site deployment completes during provisioning (default: true). 'wait_on_deploy' => env('FORGE_WAIT_ON_DEPLOY', true), - // Template for Nginx configuration. - 'nginx_template' => env('FORGE_NGINX_TEMPLATE'), - - // Key/value pairs for customizing the Nginx template. - 'nginx_substitute' => env('FORGE_NGINX_SUBSTITUTE'), - // Flag to enable Quick Deploy (default: true). 'quick_deploy' => env('FORGE_QUICK_DEPLOY', true), - - // Deployment script content. - 'deploy_script' => env('FORGE_DEPLOY_SCRIPT'), - - // Key/value pairs to be added to the environment file at runtime. - 'env_keys' => env('FORGE_ENV_KEYS'), ]; From be3efc609cd5c2ceb468f9f0a6d449b6c41f6442 Mon Sep 17 00:00:00 2001 From: Mehran Date: Fri, 6 Oct 2023 21:52:42 +0300 Subject: [PATCH 3/3] Made the non-required configs false --- README.md | 28 +++++++++++++++++----------- config/forge.php | 9 +++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e1f140e..ba4e907 100644 --- a/README.md +++ b/README.md @@ -154,31 +154,40 @@ FORGE_ENV_KEYS: ${{ secrets.LARAVEL_ENV_KEYS }} ``` ### `FORGE_NGINX_TEMPLATE` -This key allows you to specify a custom Nginx configuration template. This is useful when you need to tweak the default Nginx settings to cater to specific requirements of your application. +This key allows you to specify a custom [Nginx configuration](https://forge.laravel.com/docs/servers/nginx-templates.html) template. This is useful when you need to tweak the default Nginx settings to cater to specific requirements of your application. ### `FORGE_NGINX_SUBSTITUTE` Define key=value pairs to customize the Nginx template. This is particularly handy when you need to automatically set values inside your Nginx template, such as proxying your Nuxt.js app to a specific port. An example value might be: 'NUXT_PORT=1234; NEXT_PORT=7542'. ### `FORGE_PHP_VERSION` -Specify the desired PHP version for your application. The default is 'php82', but you can set it to other supported versions as per your application's requirements. +Specify the desired PHP version for your application. The default is 'php82', but you can set it to other supported versions installed on your server as per your application's requirements. ### `FORGE_PROJECT_TYPE` -Indicate the type of the project. The default is 'php', but depending on your application's stack, you might need to specify a different type. +Indicate the [type of the project](https://forge.laravel.com/api-documentation#create-site). The default is 'php', but depending on your application's stack, you might need to specify a different type. ### `FORGE_SITE_ISOLATION` -A flag to determine if site isolation is required. By default, it's set to false. Enable this if you need to isolate your site from other sites on the same server for security or performance reasons. +A flag to determine if [user isolation](https://forge.laravel.com/docs/sites/user-isolation.html) is required. By default, it's set to false. ### `FORGE_JOB_SCHEDULER` -This flag indicates whether a job scheduler, like Laravel's task scheduler, is needed. By default, it's set to false. If your application relies on scheduled tasks, you'd want to enable this. +This flag indicates whether a job scheduler, like Laravel's task scheduler, is needed. By default, it's set to false. ### `FORGE_AUTO_SOURCE_REQUIRED` A flag to determine if environment variables should be auto-sourced during deployment. By default, it's set to false. Enable this if your deployment process requires environment variables to be sourced automatically. ### `FORGE_DB_CREATION_REQUIRED` -Indicate if a database should be automatically created during the provisioning process. By default, it's set to false. If your application requires a database, you'd want to enable this. +Indicate if a database should be automatically created during the provisioning process. By default, it's set to false. ### `FORGE_SSL_REQUIRED` -This flag determines if SSL certification should be enabled for the site. By default, it's set to true, ensuring that your site is served over HTTPS. +This flag indicates whether SSL certification should be enabled for the site. While the default setting is false, enabling this ensures your site is served securely over HTTPS. + +**Note**: If you enable this, ensure you've added [a wildcard subdomain DNS record](https://en.wikipedia.org/wiki/Wildcard_DNS_record) pointing to your Forge server. + +### `FORGE_QUICK_DEPLOY` +This flag allows you to toggle the [Quick Deploy](https://forge.laravel.com/docs/sites/deployments.html#deploy-script) feature. By default, it's set to false. + +**Caution**: If you intend to enable this feature on your site, ensure the provision workflow isn't triggered. + +I've made the descriptions more concise and clear, and added emphasis where needed for clarity. ### `FORGE_WAIT_ON_SSL` A flag to pause the provisioning process until the SSL setup completes. By default, it's set to true, ensuring that the provisioning doesn't proceed until the SSL is fully set up. @@ -186,9 +195,6 @@ A flag to pause the provisioning process until the SSL setup completes. By defau ### `FORGE_WAIT_ON_DEPLOY` This flag pauses the provisioning process until the site deployment completes. By default, it's true, ensuring a smooth and complete deployment before any subsequent steps. -### `FORGE_QUICK_DEPLOY` -Enable or disable the Quick Deploy feature. By default, it's set to true. Quick Deploy allows for faster deployments by only deploying changes rather than the entire application. - --- ## Features @@ -212,7 +218,7 @@ This project is licensed under the MIT License - see the [LICENSE.md](https://gi **Q: Can we get a shorter link for long branch names?** -**A:** Absolutely! By configuring the [Subdomain Pattern](#subromain_pattern) you can shorten the domain, e.g., **plt-123.veyoze.com**. +**A:** Absolutely! By configuring the [Subdomain Pattern](https://github.com/mehrancodes/veyoze#forge_subdomain_pattern) you can shorten the domain, e.g., **plt-123.veyoze.com**. **Q: Why use environment keys for configuration instead of command arguments?** diff --git a/config/forge.php b/config/forge.php index 39adbee..a2cf560 100644 --- a/config/forge.php +++ b/config/forge.php @@ -52,8 +52,11 @@ // Flag indicating if a database should be created (default: false). 'db_creation_required' => env('FORGE_DB_CREATION_REQUIRED', false), - // Flag to enable SSL certification (default: true). - 'ssl_required' => env('FORGE_SSL_REQUIRED', true), + // Flag to enable Quick Deploy (default: true). + 'quick_deploy' => env('FORGE_QUICK_DEPLOY', false), + + // Flag to enable SSL certification (default: false). + 'ssl_required' => env('FORGE_SSL_REQUIRED', false), // Flag to pause until SSL setup completes during provisioning (default: true). 'wait_on_ssl' => env('FORGE_WAIT_ON_SSL', true), @@ -61,6 +64,4 @@ // Flag to pause until site deployment completes during provisioning (default: true). 'wait_on_deploy' => env('FORGE_WAIT_ON_DEPLOY', true), - // Flag to enable Quick Deploy (default: true). - 'quick_deploy' => env('FORGE_QUICK_DEPLOY', true), ];