PHPackages                             digitalerase/deployer-extended - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. digitalerase/deployer-extended

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

digitalerase/deployer-extended
==============================

Library with some additional tasks for deployer (deployer.org).

18.0.0.17(2y ago)03.0k1MITPHP

Since Feb 19Pushed 2y agoCompare

[ Source](https://github.com/digitalerase/deployer-extended)[ Packagist](https://packagist.org/packages/digitalerase/deployer-extended)[ RSS](/packages/digitalerase-deployer-extended/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (73)Used By (1)

deployer-extended
=================

[](#deployer-extended)

> [![https://scrutinizer-ci.com/g/sourcebroker/deployer-extended/badges/quality-score.png?b=master](https://camo.githubusercontent.com/9aedbd9930e8964fb74156f8e4de920cddff0bedbee64c634bceada9cd80281c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f7572636562726f6b65722f6465706c6f7965722d657874656e6465642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sourcebroker/deployer-extended/?branch=master)[![http://img.shields.io/packagist/v/sourcebroker/deployer-extended.svg?style=flat](https://camo.githubusercontent.com/13dbaf484f9fc07c3a80ec815183a1ca3e73a1b7af174915263aaed7f1b43995/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f7572636562726f6b65722f6465706c6f7965722d657874656e6465642e7376673f7374796c653d666c6174)](https://packagist.org/packages/sourcebroker/deployer-extended)[![https://img.shields.io/badge/license-MIT-blue.svg?style=flat](https://camo.githubusercontent.com/f48f8d6cf609f5b181b9c3218a85175fe8a5809c7ea400347f39697a5d55065d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c6174)](https://packagist.org/packages/sourcebroker/deployer-extended)

- [What does it do?](#what-does-it-do)
- [Setting's documentation](#setting-s-documentation)
    - [composer\_version](#composer-version)
    - [composer\_channel](#composer-channel)
    - [composer\_channel\_autoupdate](#composer-channel-autoupdate)
    - [web\_path](#web-path)
- [Task's documentation](#task-s-documentation)
    - [buffer](#buffer)
        - [buffer:start](#buffer-start)
        - [buffer:stop](#buffer-stop)
    - [deploy](#deploy)
        - [deploy:check\_branch](#deploy-check-branch)
        - [deploy:check\_branch\_local](#deploy-check-branch-local)
        - [deploy:check\_composer\_install](#deploy-check-composer-install)
        - [deploy:check\_lock](#deploy-check-lock)
    - [file](#file)
        - [file:backup](#file-backup)
        - [file:copy\_dirs\_ignore\_existing](#file-copy-dirs-ignore-existing)
        - [file:copy\_files\_ignore\_existing](#file-copy-files-ignore-existing)
        - [file:rm2steps:1](#file-rm2steps-1)
        - [file:rm2steps:2](#file-rm2steps-2)
    - [cache](#cache)
        - [cache:clear\_php\_cli](#cache-clear-php-cli)
        - [cache:clear\_php\_http](#cache-clear-php-http)
- [Changelog](#changelog)

[What does it do?](#id1)
------------------------

[](#what-does-it-do)

Library with some additional tasks for deployer (deployer.org).

[Setting's documentation](#id2)
-------------------------------

[](#settings-documentation)

### [composer\_version](#id3)

[](#composer_version)

Install specific composer version. Use tags. Valid tags are here  . Default value is `null`.

### [composer\_channel](#id4)

[](#composer_channel)

Install latest version from channel. Set this variable to '1' or '2' (or 'stable', 'snapshot', 'preview'). Read more on composer docs. Default value is `stable` which will install latest version of composer. If you need stability set it better to '1' or '2'.

### [composer\_channel\_autoupdate](#id5)

[](#composer_channel_autoupdate)

If set then on each deploy the composer is checked for latest version according to `composer_channel` settings. Default value is `true`.

### [web\_path](#id6)

[](#web_path)

Path to public when not in root of project. Must be like "pub/" so without starting slash and with ending slash.

[Task's documentation](#id7)
----------------------------

[](#tasks-documentation)

### [buffer](#id8)

[](#buffer)

#### [buffer:start](#id9)

[](#bufferstart)

Starts buffering requests to application entrypoints. Application entrypoints means here any php file that can handle HTTP requests or handle CLI calls. For most good frameworks there is only few entrypoints.

The request are buffered but at the same time if you set special http header (by default HTTP\_X\_DEPLOYER\_DEPLOYMENT) with special value you will be able to make regular request. This can be very handy to check if the application is working at all after switch (symlink to current) and to warm up some caches.

When you run [buffer:stop](#buffer-stop) all the waiting requests will hit the http server (or cli entrypoint).

The entrypoints are taken from variable "buffer\_config" which is array of entrypoints configurations.

Options:

- **entrypoint\_filename**

    *required:* yes

    The filename that will be overwritten with "entrypoint_inject" php code. If entrypoint is inside folder then write it with this folder like: 'entrypoint_filename' =&gt; 'index.php'
- **entrypoint\_needle**

    *required:* no

    *default value:* &lt;?php

    A "needle" in "entrypoint_filename" after which the php code from "entrypoint_inject" will be injected.
- **entrypoint\_refresh**

    *required:* no

    *default value:* 200000 μs (200ms)

    How often the entrypoint will recheck if `.flag.requestbuffer` is still there. Values in microseconds.

    100000 μs = 100 ms = 0,1 s.
- **entrypoint\_inject**

    *required:* no

    A php code that actually do the buffering.

    The default code with already prefilled variables (random, locker_filename, locker_expire, entrypoint_refresh):

    ```
    isset($_SERVER['HTTP_X_DEPLOYER_DEPLOYMENT']) && $_SERVER['HTTP_X_DEPLOYER_DEPLOYMENT'] == 'af37fd227cb6429c211168666dd28391' ? $deployerExtendedEnableBufferLo
    isset($_ENV['DEPLOYER_DEPLOYMENT']) && $_ENV['DEPLOYER_DEPLOYMENT'] == 'af37fd227cb6429c211168666dd28391' ? $deployerExtendedEnableBufferLock = false: $deployerExtendedEnableBufferLock = true;
    clearstatcache(true, __DIR__ . '/.flag.requestbuffer');
    while (file_exists(__DIR__ . '/.flag.requestbuffer') && $deployerExtendedEnableBufferLock) {
        usleep(200000);
        clearstatcache(true);
        if(time() - @filectime(__DIR__ . '/.flag.requestbuffer') > 60) @unlink(__DIR__ . '/.flag.requestbuffer');
    }
    ```
- **locker\_filename**

    *required:* no

    *default value:* .flag.requestbuffer

    When file with name ".flag.requestbuffer" exists the requests are buffered. The task [buffer:stop](#buffer-stop) just removes the ".flag.requestbuffer" files without removing the "entrypoint_inject" code.
- **locker\_expire**

    *required:* no

    *default value:* 60

    The time in seconds after which the .flag.requestbuffer files will be removed automatically.

    Usually its buffer:stop task that should remove ".flag.requestbuffer" file. Unfortunately sometimes deploy can fail.

    If deploy will fail after buffer:start task and before buffer:stop then the ".flag.requestbuffer" will be automatically removed

    anyway after "locker_expire" time.

The simplest configuration example:

```
set('buffer_config', [
        'index.php' => [
            'entrypoint_filename' => 'index.php',
        ]
    ]
);
```

More entrypoints example. An example for CMS TYPO3 8.7 LTS:

```
set('buffer_config', [
        'index.php' => [
            'entrypoint_filename' => 'index.php', // frontend
        ]
        'typo3/index.php' => [
            'entrypoint_filename' => 'typo3/index.php', // backend
        ],
        'typo3/cli_dispatch.phpsh' => [
            'entrypoint_filename' => 'typo3/cli_dispatch.phpsh', // cli
        ]
    ]
);
```

More configuration options examples:

```
set('buffer_config', [
        'index.php' => [
            'entrypoint_filename' => 'index.php',
            'entrypoint_needle' => '// inject php code after this comment',
            'locker_filename' => 'deployment.lock',
            'entrypoint_inject' => 'while (file_exists(__DIR__ . ".flag.requestbuffer")){' . "\n"
                                   . 'usleep(200000);' . "\n"
                                   . 'clearstatcache(true, __DIR__ . "/.flag.requestbuffer")' . "\n"
                                   . '}'
        ]
    ]
);
```

#### [buffer:stop](#id10)

[](#bufferstop)

Stop buffering requests to application entrypoints. It deletes ".flag.requestbuffer" files.

### [deploy](#id11)

[](#deploy)

#### [deploy:check\_branch](#id12)

[](#deploycheck_branch)

Check if the branch you want to deploy is different from the branch currently deployed on host. If you have information that the branch on the host is different than the branch you want to deploy then you can take decision to overwrite it or not.

#### [deploy:check\_branch\_local](#id13)

[](#deploycheck_branch_local)

Check if the branch you are currently checked out on your local is the same branch you want to deploy. The `deploy.php` files on both branches can be different and that can influence the deploy process.

#### [deploy:check\_composer\_install](#id14)

[](#deploycheck_composer_install)

Check if there is composer.lock file on current instance and if its there then make dry run for "composer install". If "composer install" returns information that some packages needs to be updated or installed then it means that probably developer pulled composer.lock changes from repo but forget to make "composer install". In that case deployment is stopped to allow developer to update packages, make some test and make deployment then.

#### [deploy:check\_lock](#id15)

[](#deploycheck_lock)

Checks for existence of file deploy.lock in root of current instance. If the file deploy.lock is there then deployment is stopped.

You can use it for whatever reason you have. Imagine that you develop css/js locally with "grunt watch". After you have working code you may forget to build final js/css with "grunt build" and you will deploy css/js that will be not used on production which reads compiled css/js.

To prevent this situation you can make "grunt watch" to generate file "deploy.lock" (with text "Run 'grunt build'." inside) to inform you that you missed some step before deploying application.

### [file](#id16)

[](#file)

#### [file:backup](#id17)

[](#filebackup)

Creates backup of files. Single task may perform multiple archivization using defined filters. Old ones are deleted after executing this task. Default limit is 5.

Configuration description

- **file\_backup\_packages**

    *required:* yes

    *default value:* none

    *type:* array

    Packages definition
- **file\_backup\_keep**

    *required:* no

    *default value:* 5

    *type:* int

    Limit of backups per package

Sample configuration:

```
set('file_backup_packages', [
    'config' => [
        '-path "./etc/*"',
    ],
    'translations' => [
        '-path "./l10n/*"',
        '-path "./modules/*/l10n/*"',
    ],
    'small_images' => [
        [ '-path "./media/uploads/*"', '-size -25k' ],
        [ '-path "./media/theme/*"', '-size -25k' ],
    ],
]);

set('file_backup_keep', 10);
```

Config variable *file\_backup\_packages* stores information about backup packages and files filtering options. Each package defines filters which will be used in find command. First level element are groups which will be concatenated using logical alternative operator operator OR. If group is array type then group elements will be concatenated using logical conjunction operator.

Package *config*: It is simplest definition. For this package all files from directory "./etc/" will be backuped.

Package *translations*: For this one all files from directory "./l10n/" will be backuped. It will also include files from all "l10n/" from "modules" subdirectory. For example "modules/cookies/l10n"

Package *small\_images*: This one will contain all small (smaller than 25kB) files from "media/uploads" and "media/theme".

As you can see *file\_backup\_keep* is set to 10 which means only newest 10 backups per package will be stored.

#### file:copy\_dirs\_ignore\_existing

[](#filecopy_dirs_ignore_existing)

Copy directories from previous release except for those directories which already exists in new release.

#### file:copy\_files\_ignore\_existing

[](#filecopy_files_ignore_existing)

Copy files from previous release except for those files which already exists in new release.

#### [file:rm2steps:1](#id20)

[](#filerm2steps1)

Allows to remove files and directories in two steps for "security" and "speed".

**Security**

Sometimes removing cache folders with lot of files takes few seconds. In meantime of that process a new frontend request can hit http server and new file cache will start to being generated because it will detect that some cache files are missing and cache needs to be regenerated. A process which is deleting the cache folder can then delete the newly generated cache files. The output of cache folder is not predictable in that case and can crash the application.

**Speed**

If you decide to remove the cache folder during the [buffer:start](#buffer-start) then its crucial to do it as fast as possible in order to buffer as low requests as possible.

The solution for both problems of "security" and "speed" is first rename the folder to some temporary and then delete it later in next step. Renaming is atomic operation so there is no possibility that new http hit will start to build cache in the same folder. We also gain speed because we can delete the folders/files at the end of deployment with task [file:rm2steps:2](#file-rm2steps-2) if that's needed at all because deployer "cleanup" task will remove old releases anyway.

#### [file:rm2steps:2](#id21)

[](#filerm2steps2)

The second step of file:rm2steps tandem. Read more on [file:rm2steps:1](#file-rm2steps-1)

### [cache](#id22)

[](#cache)

#### [cache:clear\_php\_cli](#id23)

[](#cacheclear_php_cli)

This task clears the file status cache, opcache and eaccelerator cache for CLI context.

#### [cache:clear\_php\_http](#id24)

[](#cacheclear_php_http)

This task clears the file status cache, opcache and eaccelerator cache for HTTP context. It does following:

1. Creates file "cache\_clear\_\[random\].php" in "{{deploy\_path}}/current" folder.
2. Fetch this file with selected method - curl / wget / file\_get\_contents - by default its wget.
3. The file is not removed after clearing cache for reason. It allows to prevent problems with realpath\_cache. For more info read

You must set **public\_urls** configuration variable so the script knows the domain it should fetch the php script. Here is example:

```
server('prelive', 'example.com', 22)
  ->user('deploy')
  ->stage('prelive')
  ->set('deploy_path', '/home/web/html/www.example.com.prelive')
  ->set('public_urls', ['https://prelive.example.com']);
```

Task configuration variables:

- **cache:clear\_php\_http:phpcontent**

    *required:* no

    *type:* string

    *default value:*

    ```
