16 Commits

13 changed files with 232 additions and 63 deletions

27
CHANGELOG.md Normal file
View File

@ -0,0 +1,27 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [unreleased](https://git.d3data.de/D3Public/OXID-Deployer/compare/1.0.1.0...rel_1.x)
## [1.0.1.0](https://git.d3data.de/D3Public/OXID-Deployer/compare/1.0.0.1...1.0.1.0) - 2024-11-19
### Added
- generic Composer task `dep composer [stage] --cmd="show oxid-esales/*"
## [1.0.0.1](https://git.d3data.de/D3Public/OXID-Deployer/compare/1.0.0.0...1.0.0.1) - 2024-11-04
### Changed
- handle config file from checkout to preven false isLaunched status
- move base inventory configuration to OXID recipe
## [1.0.0.0](https://git.d3data.de/D3Public/OXID-Deployer/releases/tag/1.0.0.0) - 2024-11-03
### Added
- initial implementation
- OXID base recipe
- additional shop depend deployment tasks
- additional task
- show OXID version
- create backup
- clone database
- run migrations

View File

@ -6,11 +6,21 @@ The recipe can usually also be used for projects based on OXID 6.4 and 6.5.
## Usage
See Deployer OXID recipe project for further instructions.
See [Deployer OXID recipe project](https://packagist.org/packages/d3/oxid-deployer-project) for further instructions.
## available tasks
- dep `shop:getVersion` [stage] - show version of current OXID installation
- dep `shop:cloneDatabase` [stage] - dump contents from source to destination database
- dep `shop:runMigration` [stage] - run all database migrations
- dep `setup:createDbConfig` [stage] - generate database configuration file
### generic
- dep `composer` [stage] [--cmd="show d3/*"] - execute generic Composer commands
### OXID
- dep `oxid:getVersion` [stage] - show version of current OXID installation
- dep `oxid:cloneDatabase` [stage] - dump contents from source to destination database
- dep `oxid:runMigration` [stage] - run all database migrations
### database
- dep `database:createBackup` [stage] - rotate old database backups and create a new one
- dep `database:clone` [stage] - dump contents from source to destination database
### setup
- dep `setup:createDbConfig` [stage] - generate database configuration file

View File

@ -1,6 +1,14 @@
{
"name": "d3/oxid-deployer",
"description": "Deployer recipe for OXID eShop",
"keywords": [
"deployer",
"deployment",
"recipe",
"OXID",
"eShop",
"d3"
],
"type": "library",
"license": "MIT",
"homepage": "https://d3data.de/",

14
recipe/composerTasks.php Normal file
View File

@ -0,0 +1,14 @@
<?php
namespace Deployer;
use \Symfony\Component\Console\Input\InputOption;
option('cmd', null, InputOption::VALUE_REQUIRED, 'full Composer command');
desc('run generic composer commands');
task('composer', function () {
$command = input()->getOption('cmd');
cd('{{release_or_current_path}}');
writeln(run('printf "\n" && {{bin/composer}} '.$command));
});

51
recipe/databaseTasks.php Normal file
View File

@ -0,0 +1,51 @@
<?php
namespace Deployer;
require_once 'inc/database.php';
desc('dump contents from source to destination database');
task('database:clone', function () {
if (get('mysql_configured') && get('mysqldump_configured')) {
info('Note: Use a dedicated read only user for accessing the source database.');
info('Using the following source database:');
$source_host = ask('source database host', 'localhost');
$source_port = ask('source database port', '3306');
$source_name = ask('source database name');
$source_user = ask('source database user');
$source_pass = askHiddenResponse('source database password');
$target_name = parse_ini_file(get('db_conf_path'))['database'];
if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "'.$target_name.'"? The target database "'.$target_name.'" will be overwritten!')) {
info('cloning database');
$auth = "-h".$source_host." -P".$source_port." -u".$source_user." -p'".$source_pass."'";
run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f");
info('creating views');
run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate');
info('successfully finished');
} else {
info('abborted');
}
} else {
warning('missing config, task skipped');
}
});
desc('rotate old database backups and create a new one');
task('database:createBackup', function () {
if (get('mysql_configured') && get('mysqldump_configured')) {
if (!test("[ -f {{deploy_path}}/database/rotatemap.conf ]")) {
run('printf "{{deploy_path}}/database/backup/backup.sql {\n rotate 5\n}" > {{deploy_path}}/database/rotatemap.conf');
}
if (!test("[ -d {{deploy_path}}/database/backup ]")) {
run("mkdir -p {{deploy_path}}/database/backup");
}
$source_name = parse_ini_file(get('db_conf_path'))['database'];
if (test("[ -f {{deploy_path}}/database/backup/backup.sql ]")) {
run("logrotate -f -s {{deploy_path}}/database/rotatemap.state {{deploy_path}}/database/rotatemap.conf");
}
run("{{bin/mysqldump}} --defaults-extra-file={{db_conf_path}} --opt --no-create-db -f ".$source_name." $({{bin/mysql}} --defaults-extra-file={{db_conf_path}} -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") > {{deploy_path}}/database/backup/backup.sql");
info('successfully dumped to {{deploy_path}}/database/backup/backup.sql');
} else {
warning('missing config, task skipped');
}
});

View File

@ -2,7 +2,24 @@
namespace Deployer;
task('deploy:d3OxidBeforeVendorsTasks', [
'deploy:oxid_backup_configfile'
])->hidden();
task('deploy:oxid_backup_configfile', function() {
if (test('[ -f {{release_path}}/source/config.inc.php ]')) {
run('mv {{release_path}}/source/config.inc.php {{release_path}}/source/config.deployment.inc.php');
}
})->hidden();
desc('Oxid related tasks');
task('deploy:d3OxidTasks', [
task('deploy:d3OxidAfterVendorTasks', [
'deploy:oxid_restore_configfile',
'deploy:clear_paths'
]);
])->hidden();
task('deploy:oxid_restore_configfile', function() {
if (test('[ -f {{release_path}}/source/config.deployment.inc.php ]')) {
run('mv {{release_path}}/source/config.deployment.inc.php {{release_path}}/source/config.inc.php');
}
})->hidden();

View File

@ -3,4 +3,5 @@
namespace Deployer;
after('deploy:failed', 'deploy:unlock');
after('deploy:vendors', 'deploy:d3OxidTasks');
before('deploy:vendors', 'deploy:d3OxidBeforeVendorsTasks');
after('deploy:vendors', 'deploy:d3OxidAfterVendorTasks');

21
recipe/inc/database.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace Deployer;
set('db_conf_path', function () {
return '{{deploy_path}}/database/.my.cnf';
});
set('database_configured', function() {
return has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]");
});
set('mysql_configured', function() {
return has('bin/mysql') && strlen(get('bin/mysql')) &&
get('database_configured');
});
set('mysqldump_configured', function() {
return has('bin/mysql') && strlen(get('bin/mysql')) &&
get('database_configured');
});

27
recipe/menu.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace Deployer;
task('logs:access')->hidden();
task('logs:app')->hidden();
task('logs:caddy')->hidden();
task('logs:php-fpm')->hidden();
task('provision:check')->hidden();
task('provision:composer')->hidden();
task('provision:configure')->hidden();
task('provision:databases')->hidden();
task('provision:firewall')->hidden();
task('provision:install')->hidden();
task('provision:mariadb')->hidden();
task('provision:mysql')->hidden();
task('provision:node')->hidden();
task('provision:php')->hidden();
task('provision:postgresql')->hidden();
task('provision:server')->hidden();
task('provision:ssh')->hidden();
task('provision:ssh_copy_id')->hidden();
task('provision:update')->hidden();
task('provision:upgrade')->hidden();
task('provision:user')->hidden();
task('provision:verify')->hidden();
task('provision:website')->hidden();

View File

@ -4,7 +4,11 @@ namespace Deployer;
require_once __DIR__.'/../../../deployer/deployer/recipe/composer.php';
require_once __DIR__.'/setup.php';
require_once __DIR__.'/menu.php';
require_once __DIR__.'/hooks.php';
require_once __DIR__.'/composerTasks.php';
require_once __DIR__.'/databaseTasks.php';
require_once __DIR__.'/deployTasks.php';
require_once __DIR__.'/setupTasks.php';
require_once __DIR__.'/shopTasks.php';
require_once __DIR__.'/shopTasks.php';

19
recipe/setup.php Normal file
View File

@ -0,0 +1,19 @@
<?php
namespace Deployer;
set('default_timeout', 3000);
set('shared_dirs', [
'source/sitemaps',
'source/export',
'source/log',
'source/import',
'source/out/downloads',
'source/out/media',
'source/out/pictures'
]);
set('copy_dirs', [
'var'
]);

View File

@ -2,7 +2,9 @@
namespace Deployer;
desc('create database coniguration file');
require_once 'inc/database.php';
desc('create database configuration file');
task('setup:createDbConfig', function () {
try {
if (!has('db_conf_path') || !strlen(get('db_conf_path'))) {
@ -18,11 +20,7 @@ task('setup:createDbConfig', function () {
run("touch {{db_conf_path}}");
}
if (test("[ -f {{db_conf_path}} ]")) {
$db_host = ask('database host', 'localhost');
$db_port = ask('database port', '3306');
$db_user = ask('database user');
$db_pass = askHiddenResponse('database password');
run('printf "[mysql]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'\n\n[mysqldump]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'" > {{db_conf_path}}');
run('printf "[client]\nhost=\"'.ask('database host', 'localhost').'\"\nport=\"'.ask('database port', '3306').'\"\nuser=\"'.ask('database user').'\"\npassword=\"'.askHiddenResponse('database password').'\"\n\n[mysql]\ndatabase=\"'.ask('database name').'\"" > {{db_conf_path}}');
info('config successful created');
} else {
throw new \RuntimeException('can not create {{db_conf_path}}, task stopped');
@ -30,4 +28,4 @@ task('setup:createDbConfig', function () {
} catch(\RuntimeException $e) {
warning($e->getMessage());
}
});
});

View File

@ -3,53 +3,49 @@
namespace Deployer;
desc('run all database migrations');
task('shop:runMigration', [
'shop:setShopsOffline',
'shop:executeMigrations',
'shop:setShopsOnline'
task('oxid:runMigration', [
'oxid:setShopsOffline',
'oxid:executeMigrations',
'oxid:setShopsOnline'
]);
require_once 'inc/database.php';
desc('set shops offline');
task('shop:setShopsOffline', function() {
if (has('bin/mysql') && strlen(get('bin/mysql')) &&
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
task('oxid:setShopsOffline', function() {
if (get('mysql_configured')) {
$query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';";
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"');
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} -e "'.$query.'"');
} else {
warning('missing config, task skipped');
}
});
task('shop:runMigration:failed', function() {
invoke('shop:setShopsOnline');
task('oxid:runMigration:failed', function() {
invoke('oxid:setShopsOnline');
})->hidden();
fail('shop:runMigration', 'shop:runMigration:failed');
fail('oxid:runMigration', 'oxid:runMigration:failed');
desc('execute OXID Doctrine migrations');
task('shop:executeMigrations', function () {
task('oxid:executeMigrations', function () {
if (test("[ -f {{current_path}}/vendor/bin/oe-eshop-doctrine_migration ]")) {
run('{{bin/php}} {{current_path}}/vendor/bin/oe-eshop-doctrine_migration migrations:migrate');
}
})->hidden();;
desc('set shops online');
task('shop:setShopsOnline', function() {
if (has('bin/mysql') && strlen(get('bin/mysql')) &&
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
task('oxid:setShopsOnline', function() {
if (get('mysql_configured')) {
$query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';";
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"');
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} -e "'.$query.'"');
} else {
warning('missing config, task skipped');
}
});
desc('show version of current OXID installation');
task('shop:getVersion', function () {
task('oxid:getVersion', function () {
if (test("[ -f {{current_path}}/composer.lock ]")) {
cd('{{current_path}}');
info(
@ -61,30 +57,6 @@ task('shop:getVersion', function () {
});
desc('dump contents from source to destination database');
task('shop:cloneDatabase', function () {
if (has('bin/mysql') && strlen(get('bin/mysql')) &&
has('bin/mysqldump') && strlen(get('bin/mysqldump')) &&
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
info('Note: Use a dedicated read only user for accessing the source database.');
info('Using the following source database:');
$source_host = ask('source database host', 'localhost');
$source_port = ask('source database port', '3306');
$source_name = ask('source database name');
$source_user = ask('source database user');
$source_pass = askHiddenResponse('source database password');
if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "{{db_name}}"? The target database "{{db_name}}" will be overwritten!')) {
info('cloning database');
$auth = "-h".$source_host." -P".$source_port." -u".$source_user." -p'".$source_pass."'";
run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f {{db_name}}");
info('creating views');
run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate');
info('successfully finished');
} else {
info('abborted');
}
} else {
warning('missing config, task skipped');
}
task('oxid:cloneDatabase', function () {
invoke('database:clone');
});