Skip to content

Commit

Permalink
Merge pull request #19 from mehrancodes/make-nginx-search-replace-syn…
Browse files Browse the repository at this point in the history
…tax-same-as-other

Make nginx search replace syntax same as other config keys
  • Loading branch information
mehrancodes authored Oct 6, 2023
2 parents d60a08f + be3efc6 commit fc57db4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 61 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,41 +154,47 @@ 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.

### `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
Expand All @@ -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?**

Expand Down
32 changes: 0 additions & 32 deletions app/Actions/SearchReplaceKeysInText.php

This file was deleted.

5 changes: 4 additions & 1 deletion app/Actions/TextToArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace App\Actions;

use Illuminate\Support\Str;
use Lorisleiva\Actions\Concerns\AsAction;

class TextToArray
Expand All @@ -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;
}
Expand Down
13 changes: 11 additions & 2 deletions app/Services/Forge/Pipeline/NginxTemplateSearchReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,12 +36,21 @@ public function __invoke(ForgeService $service, Closure $next)
$service->forge->updateSiteNginxFile(
$service->setting->server,
$service->site->id,
SearchReplaceKeysInText::run(
$this->searchAndReplaceKeys(
$service->setting->nginxSubstitute,
$template
)
);

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;
}
}
31 changes: 16 additions & 15 deletions config/forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'),

Expand All @@ -40,6 +52,9 @@
// Flag indicating if a database should be created (default: false).
'db_creation_required' => env('FORGE_DB_CREATION_REQUIRED', false),

// 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),

Expand All @@ -49,18 +64,4 @@
// 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'),
];

0 comments on commit fc57db4

Please sign in to comment.