diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fbb073 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vendor/ +/composer.lock diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b781ae5 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..063108a --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +Yakamara recipes for [Deployer](https://github.com/deployphp/deployer) +=============================== + +Installation +------------ + +``` +composer require yakamara/deployer-recipes +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..be44637 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "yakamara/deployer-recipes", + "description": "Yakamara recipes for Deployer", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Gregor Harlan", + "email": "gregor.harlan@yakamara.de" + } + ], + + "require": { + "php": "^7.4 || ^8.0", + "deployer/deployer": "^7.0@rc" + }, + + "config": { + "preferred-install": { + "*": "dist" + }, + "sort-packages": true + } +} diff --git a/recipe/base.php b/recipe/base.php new file mode 100644 index 0000000..08e5321 --- /dev/null +++ b/recipe/base.php @@ -0,0 +1,128 @@ +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', + ], + ]); +}); diff --git a/recipe/symfony.php b/recipe/symfony.php new file mode 100644 index 0000000..1f48a8b --- /dev/null +++ b/recipe/symfony.php @@ -0,0 +1,31 @@ +