Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nggw 103 move deployer #158

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
"symfony/web-profiler-bundle": "5.4.*",

"netgen/git-hooks": "^2.3",
"deployer/recipes": "^6.2",
"phpstan/phpstan": "^1.9",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-strict-rules": "^1.4",
"phpstan/phpstan-symfony": "^1.2",
"phpstan/phpstan-doctrine": "^1.3",
"php-cs-fixer/shim": "^3.20"
"php-cs-fixer/shim": "^3.20",
"deployer/deployer": "^7.3"
},
"config": {
"allow-plugins": {
Expand Down
25 changes: 13 additions & 12 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Deployer;

require 'recipe/symfony4.php';
require 'vendor/deployer/recipes/recipe/cachetool.php';
require 'vendor/deployer/recipes/recipe/rsync.php';
require 'vendor/deployer/recipes/recipe/sentry.php';
require 'vendor/deployer/recipes/recipe/slack.php';
require 'recipe/symfony.php';
require 'contrib/rsync.php';
require 'contrib/sentry.php';
require 'contrib/cachetool.php';

require __DIR__ . '/deploy/hosts.php';
require __DIR__ . '/deploy/tasks/server.php';
Expand All @@ -24,9 +23,12 @@
// optional: slack integration
//require __DIR__ . '/deploy/tasks/slack.php';


/** Parameters */
set('git_tty', true);

set('git_ssh_command', 'ssh');

add('copy_dirs', ['vendor']);

set('use_relative_symlink', false);
Expand All @@ -39,18 +41,18 @@
'commits' => getCommitsInformation()
]);

set('writable_recursive', true);

set('update_code_strategy', 'clone');

/** Execution */
task('deploy', [
'deploy:confirm',
// Upload server specific .env.local file. Those files are NOT to be committed to the repository
'server:upload_env',
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:clear_paths',
'deploy:shared',
// build and upload assets
'app:assets:deploy',
'app:graphql:deploy',
Expand All @@ -62,7 +64,6 @@
'deploy:sentry',
'git:tag:add',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:writable',
// Migrate database before symlink new release.
// 'database:migrate',
Expand All @@ -74,13 +75,13 @@
'cachetool:clear:opcache',
// Cleanup and finish the deploy
'deploy:unlock',
'cleanup',
'deploy:cleanup',
])->desc('Deploy your project');

// after successful deploy
after('deploy', 'httpcache:invalidate');
after('deploy', 'deploy:log:remote');
after('deploy', 'success');
after('deploy', 'deploy:success');

// If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
Expand Down
8 changes: 4 additions & 4 deletions deploy/files/.env.local.prod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
APP_ENV=prod
APP_SECRET=ThisIbexaPlatformTokenIsNotSoSecret_PleaseChangeIt
SERVER_ENVIRONMENT=prod
DATABASE_URL=mysql://root@localhost/ibexa
DATABASE_URL=mysql://root@127.0.0.1/ibexa
SEARCH_ENGINE=legacy
HTTPCACHE_PURGE_TYPE=local
HTTPCACHE_PURGE_SERVER=http://localhost:6081
HTTPCACHE_PURGE_SERVER=http://127.0.0.1:6081
CACHE_POOL=cache.tagaware.filesystem
SOLR_DSN=http://localhost:8983/solr
MAILER_DSN=smtp://localhost
SOLR_DSN=http://127.0.0.1:8983/solr
MAILER_DSN=smtp://127.0.0.1
SENTRY_DSN=
MAILER_LITE_API_KEY=
24 changes: 13 additions & 11 deletions deploy/hosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
namespace Deployer;

host('prod')
->hostname('some.server.com')
->setHostname('some.server.com')
->set('deploy_path', '/home/some/example/sites/example.com/htdocs')
->stage('prod')
->user('exampleweb')
->set('labels', ['stage' => 'prod'])
->setRemoteUser('exampleweb')
->set('http_user', 'exampleweb')
->set('cachetool', '/var/run/php/exampleweb.sock')
->set('cachetool', '/run/php/php8.1-fpm.sock')
->add('varnish_ban_hosts', ['www.example.com'])
->set('symfony_env', 'prod')
;

host('stage')
->hostname('192.0.2.10')
->set('deploy_path', '/var/www/my/project')
->stage('stage')
->user('deployer')
->set('http_user', 'www-data')
->setHostname('some.server.com')
->set('deploy_path', '/home/some/example/sites/example.com/htdocs')
->set('labels', ['stage' => 'stage'])
->setRemoteUser('exampleweb')
->set('http_user', 'exampleweb')
// ->set('branch', 'test-branch') // by default, master is used, this is the way to set up different branch per host
->set('cachetool', '/var/run/php/exampleweb.sock')
->add('varnish_ban_hosts', ['stage.example.com'])
->set('cachetool', '/run/php/php8.1-fpm.sock')
->add('varnish_ban_hosts', ['www.example.com'])
->set('symfony_env', 'stage')
;
14 changes: 7 additions & 7 deletions deploy/tasks/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
writeln('<comment>Checking for changes in asset files. If this fails, commit or stash your changes before deploying.</comment>');
$assetResourcePaths = get('asset_resource_paths');
foreach ($assetResourcePaths as $resourcePath) {
run("git diff --exit-code {$resourcePath}");
runLocally("git diff --exit-code {$resourcePath}");
}

$installCmd = get('asset_install_command');
run($installCmd);
runLocally($installCmd);

$buildCmd = get('asset_build_command');
run($buildCmd);
})->local();
runLocally($buildCmd);
})->once();

task('app:assets:ibexa:build', function() {
run("{{asset_ibexa_build_command}}");
})->local();
runLocally('{{asset_ibexa_build_command}}');
})->once();

task('app:assets:upload', function() {
$assetPaths = get('asset_build_paths');
$excludedPaths = get('asset_exclude_paths', []);

$config = [];
foreach ($excludedPaths as $excludedPath) {
$config['options'][] = "--exclude {$excludedPath}";
$config['options'][] = "--exclude= {$excludedPath}";
}

foreach ($assetPaths as $path) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/tasks/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

desc('Execute kaliop migrations');
task('database:kaliop:migrate', function () {
run('{{bin/php}} {{bin/console}} kaliop:migration:migrate --env={{symfony_env}}');
run('{{bin/console}} kaliop:migration:migrate --env={{symfony_env}}');
});
2 changes: 1 addition & 1 deletion deploy/tasks/git.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

runLocally("$git tag -a $tag -m '" . $message . "' " . trim($commitHash));
runLocally("$git push origin $tag");
})->onStage('prod');
})->select('stage=prod');
4 changes: 2 additions & 2 deletions deploy/tasks/graphql.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
]);

task('app:graphql:generate', function () {
run("{{graphql_generate_command}}");
})->local();
runLocally("{{graphql_generate_command}}");
})->once();


task('app:graphql:upload', function () {
Expand Down
2 changes: 1 addition & 1 deletion deploy/tasks/logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

$result = run('cat '.$file);

write($result);
writeln($result);
});
9 changes: 3 additions & 6 deletions deploy/tasks/overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Deployer;

set('bin/cachetool', function(){
return 'cachetool-7.0.0.phar';
});

// overridden to make sure public folder is correctly symlinked (L79)
desc('Rollback to previous release');
Expand All @@ -20,9 +17,9 @@

// Remove release
run("rm -rf {{deploy_path}}/releases/{$releases[0]}");
if (isVerbose()) {
writeln("Rollback to `{$releases[1]}` release was successful.");
}

writeln("Rollback to `{$releases[1]}` release was successful.");

} else {
writeln("<comment>No more releases you can revert to.</comment>");
}
Expand Down
4 changes: 2 additions & 2 deletions deploy/tasks/rsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
return;
}

$host = $server->getRealHostname();
$host = $server->getHostname();
$port = $server->getPort() ? ' -p' . $server->getPort() : '';
$sshArguments = $server->getSshArguments();
$user = !$server->getUser() ? '' : $server->getUser() . '@';
$user = !$server->getRemoteUser() ? '' : $server->getRemoteUser() . '@';

runLocally("rsync -{$config['flags']} -e 'ssh$port $sshArguments' {{rsync_options}}{{rsync_includes}}{{rsync_excludes}}{{rsync_filter}} '$user$host:$src/' '$dst/'", $config);
});
16 changes: 9 additions & 7 deletions deploy/tasks/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
}

$stage = null;
if (input()->hasArgument('stage')) {
$stage = input()->getArgument('stage');
$labels = get('labels');
if (array_key_exists('stage', $labels)) {
$stage = $labels['stage'];
}

$question = 'Please confirm deploy';
Expand All @@ -30,13 +31,14 @@
if(!askConfirmation($question)) {
die("Ok, no deploy then.\n");
}
})->onStage('prod');
})->select('stage=prod');

desc('Upload appropriate .env.local file to the server');
task('server:upload_env', function() {
$stage = 'dev';
if (input()->hasArgument('stage')) {
$stage = input()->getArgument('stage');
$labels = get('labels');
if (array_key_exists('stage', $labels)) {
$stage = $labels['stage'];
}

$path = get('deploy_path');
Expand Down Expand Up @@ -79,7 +81,7 @@ function invalidateFOSHttpCache($tag = null)
{
$tag = !empty($tag) ? $tag : get('http_invalidate_tag');

run("{{bin/php}} {{bin/console}} fos:httpcache:invalidate:tag {$tag} {{console_options}}");
run("{{bin/console}} fos:httpcache:invalidate:tag {$tag} {{console_options}}");
}

desc('Invalidate content on varnish per host');
Expand Down Expand Up @@ -124,7 +126,7 @@ function invalidateFOSHttpCache($tag = null)
task('crontab:list', function () {
$result = run('crontab -l');

write($result);
writeln($result);
});

desc('Reindex solr');
Expand Down
2 changes: 1 addition & 1 deletion deploy/tasks/slack.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
/** execution */
before('deploy', 'slack:notify');

after('success', 'slack:notify:success');
after('deploy:success', 'slack:notify:success');
after('deploy:failed', 'slack:notify:failure');