Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Jan 21, 2022
0 parents commit af38e0c
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/composer.lock
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Yakamara Media GmbH & Co. KG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Yakamara recipes for [Deployer](https://github.com/deployphp/deployer)
===============================

Installation
------------

```
composer require yakamara/deployer-recipes
```
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "yakamara/deployer-recipes",
"description": "Yakamara recipes for Deployer",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Gregor Harlan",
"email": "[email protected]"
}
],

"require": {
"php": "^7.4 || ^8.0",
"deployer/deployer": "^7.0@rc"
},

"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
}
}
128 changes: 128 additions & 0 deletions recipe/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

declare(strict_types=1);

namespace Deployer;

use Deployer\Task\Context;

localhost('local')
->set('deploy_path', DEPLOYER_ROOT.'/.build')
->set('release_path', DEPLOYER_ROOT.'/.build/release')
->set('current_path', '{{release_path}}')
;

set('branch', fn () => runLocally('git rev-parse --abbrev-ref HEAD'));

set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --no-dev --no-scripts --optimize-autoloader --classmap-authoritative');

set('clear_paths', [
'.idea',
'assets',
'gulpfile.js',
'tests',
'.gitignore',
'.gitlab-ci.yml',
'.php-cs-fixer.dist.php',
'package.json',
'psalm.xml',
'README.md',
'webpack.config.js',
'yarn.lock',
'REVISION',
]);

after('deploy:failed', 'deploy:unlock');

task('deploy', [
'build:start',
'release',
]);

task('build:start', function () {
on(host('local'), fn () => invoke('build'));
})->once()->hidden();

task('build', [
'deploy:info',
'build:setup',
'build:assets',
'deploy:vendors',
'deploy:clear_paths',
]);

task('release', [
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'deploy:copy_dirs',
'upload',
'deploy:shared',
'deploy:writable',
'deploy:cache:clear',
'database:migrate',
'deploy:publish',
]);

task('build:setup', function () {
if ('local' !== Context::get()->getHost()->getAlias()) {
throw new \RuntimeException('Task "build" can only be called on host "local"');
}

if (getenv('CI')) {
set('deploy_path', DEPLOYER_ROOT);
set('release_path', DEPLOYER_ROOT);

return;
}

run('rm -rf {{release_path}}');
run('mkdir -p {{release_path}}');

invoke('deploy:update_code');
});

set('assets_install', 'yarn');
set('assets_build', 'yarn build');

task('build:assets', function () {
$install = get('assets_install');

if (!$install) {
return;
}

cd('{{release_path}}');

$isLocal = !getenv('CI');
if ($isLocal && test('[ -d {{deploy_path}}/.node_modules ]')) {
run('mv {{deploy_path}}/.node_modules node_modules');
}

run($install);

if ($build = get('assets_build')) {
run($build);
}

if ($isLocal) {
run('mv node_modules {{deploy_path}}/.node_modules');
}
});

task('upload', function () {
$source = getenv('CI') ? DEPLOYER_ROOT : host('local')->get('release_path');

upload($source.'/', '{{release_path}}', [
'flags' => '-az',
'options' => [
'--exclude', '.cache',
'--exclude', '.git',
'--exclude', '.tools',
'--exclude', 'deploy.php',
'--exclude', 'node_modules',
'--delete',
],
]);
});
31 changes: 31 additions & 0 deletions recipe/symfony.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Deployer;

require dirname(DEPLOYER_BIN, 2).'/recipe/symfony.php';
require __DIR__.'/base.php';

set('copy_dirs', [
'bin',
'config',
'migrations',
'public',
'src',
'templates',
'translations',
'vendor',
]);

task('deploy:stop_workers', function () {
if (!has('previous_release')) {
return;
}

$console = '{{bin/php}} {{previous_release}}/bin/console';
if (test('[[ $('.$console.' list messenger --raw {{console_options}} | grep messenger:stop-workers) ]]')) {
run($console.' messenger:stop-workers {{console_options}}');
}
});
after('deploy:symlink', 'deploy:stop_workers');

0 comments on commit af38e0c

Please sign in to comment.