Skip to content

Commit

Permalink
Merge pull request #78 from mittwald/doc-deploy-opcache
Browse files Browse the repository at this point in the history
Document how to flush OPcache during deployment
  • Loading branch information
martin-helmich authored Feb 9, 2024
2 parents 283e68d + 1ea4d47 commit 425cff0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
33 changes: 23 additions & 10 deletions docs/technologies/deployment/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The recipe will automatically configure the following things:

- The `deploy_path` will be set to the application's installation path.
- An SSH user will be created for the application, and the `remote_user` will be set to that user. By default, the SSH key configured in the `ssh_copy_id` variable will be used for authentication. To use a different SSH key pair, set the `mittwald_ssh_public_key` and `mittwald_ssh_private_key` variables (alternative, set the `mittwald_ssh_public_key_file` and `mittwald_ssh_private_key_file` variables to the path of the respective files).
- The [PHP OPcache][opcache] will automatically be cleared after deployment.

#### Alternative: Without the mittwald deployer recipe

Expand All @@ -91,6 +92,21 @@ host('ssh.fiestel.project.host') // you can determine your SSH host via the "mw
->set('deploy_path', '/html/<app-installation-path>');
```

To flush the [OPcache][opcache], you can add your own task definition to your `deploy.php` file, to be executed after the `deploy:symlink` stage. The following example uses the [CacheTool][cachetool] to selectively flush the OPcache for the application:

```php
task("opcache:flush", function (): void {
if (!test("[ -x cachetool.phar ]")) {
run("curl -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar");
run("chmod +x cachetool.phar");
}

run('./cachetool.phar opcache:invalidate:scripts --fcgi=127.0.0.1:9000 {{ deploy_path }}');
});

after("deploy:symlink", "opcache:flush");
```

The rest of your Deployer configuration depends on your project, and for this reason, will not be covered by this guide. For example, if you are deploying a TYPO3 project, you might want to use the [TYPO3 Deployer recipe](https://deployer.org/docs/7.x/recipe/typo3).

## Advanced recipe how-tos
Expand Down Expand Up @@ -146,10 +162,8 @@ You can also set the `mittwald_app_dependencies` value. This value may contain a
'composer' => '>=2.0',
]);
```

:::tip
Use the `mw app dependency list` command to get an overview of available dependencies.
:::

:::tip Use the `mw app dependency list` command to get an overview of available dependencies. :::

## CI integration

Expand All @@ -175,7 +189,7 @@ steps:

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Deploy SSH keys
env:
MITTWALD_SSH_PRIVATE_KEY: ${{ secrets.MITTWALD_SSH_PRIVATE_KEY }}
Expand Down Expand Up @@ -212,10 +226,7 @@ deploy:
- echo "$MITTWALD_SSH_PUBLIC_KEY" > .mw-deploy/id_rsa.pub
- chmod 600 .mw-deploy/id_rsa*
script:
- ./vendor/bin/dep deploy \
-o mittwald_app_id=$MITTWALD_APP_ID \
-o mittwald_ssh_public_key_file=.mw-deploy/id_rsa.pub \
-o mittwald_ssh_private_key_file=.mw-deploy/id_rsa
- ./vendor/bin/dep deploy \ -o mittwald_app_id=$MITTWALD_APP_ID \ -o mittwald_ssh_public_key_file=.mw-deploy/id_rsa.pub \ -o mittwald_ssh_private_key_file=.mw-deploy/id_rsa
environment:
name: production
```
Expand All @@ -236,4 +247,6 @@ This issue is caused by Deployers [SSH multiplexing feature](https://deployer.or
```

[mw-deployer]: https://packagist.org/packages/mittwald/deployer-recipes
[mw-deployer-issues]: https://github.com/mittwald/deployer-recipes/issues
[mw-deployer-issues]: https://github.com/mittwald/deployer-recipes/issues
[opcache]: https://www.php.net/manual/en/book.opcache.php
[cachetool]: https://github.com/gordalina/cachetool
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Das Rezept wird automatisch die folgenden Dinge konfigurieren:

- Der `deploy_path` wird auf den Installationspfad der Anwendung gesetzt.
- Ein SSH-Benutzer wird für die Anwendung erstellt, und der `remote_user` wird auf diesen Benutzer gesetzt. Standardmäßig wird der in der `ssh_copy_id`-Variable konfigurierte SSH-Schlüssel für die Authentifizierung verwendet. Um ein anderes SSH-Schlüsselpaar zu verwenden, setze die `mittwald_ssh_public_key`- und `mittwald_ssh_private_key`-Variablen (alternativ setze die `mittwald_ssh_public_key_file`- und `mittwald_ssh_private_key_file`-Variablen auf den Pfad der entsprechenden Dateien).
- Der [PHP OPcache][opcache] wird automatisch nach dem Deployment geleert.

#### Alternative: Ohne das mittwald Deployer-Rezept

Expand All @@ -85,6 +86,21 @@ host('ssh.fiestel.project.host') // you can determine your SSH host via the "mw
->set('deploy_path', '/html/<app-installation-path>');
```

Um den [OPcache][opcache] zu leeren, kannst du deine eigene Task-Definition zu deiner `deploy.php`-Datei hinzufügen, die nach der `deploy:symlink`-Phase ausgeführt werden soll. Das folgende Beispiel verwendet das [CacheTool][cachetool], um den OPcache für die Anwendung selektiv zu leeren:

```php
task("opcache:flush", function (): void {
if (!test("[ -x cachetool.phar ]")) {
run("curl -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar");
run("chmod +x cachetool.phar");
}

run('./cachetool.phar opcache:invalidate:scripts --fcgi=127.0.0.1:9000 {{ deploy_path }}');
});

after("deploy:symlink", "opcache:flush");
```

Der Rest deiner Deployer-Konfiguration hängt von deinem Projekt ab und wird daher nicht von dieser Anleitung abgedeckt. Wenn du beispielsweise ein TYPO3-Projekt deployen möchtest, könntest du das [TYPO3 Deployer-Rezept](https://deployer.org/docs/7.x/recipe/typo3) verwenden.

## Fortgeschrittene Anleitungen
Expand Down Expand Up @@ -226,3 +242,5 @@ Dieses Problem wird durch das [SSH-Multiplexing-Feature](https://deployer.org/do

[mw-deployer]: https://packagist.org/packages/mittwald/deployer-recipes
[mw-deployer-issues]: https://github.com/mittwald/deployer-recipes/issues
[opcache]: https://www.php.net/manual/de/book.opcache.php
[cachetool]: https://github.com/gordalina/cachetool

0 comments on commit 425cff0

Please sign in to comment.