refactor for external OXID recipe

Cette révision appartient à :
Daniel Seifert 2024-10-30 15:59:00 +01:00
Parent 1b57fc494d
révision 0864719abd
Signé par: DanielS
ID de la clé GPG: 6A513E13AEE66170
5 fichiers modifiés avec 15 ajouts et 163 suppressions

Voir le fichier

@ -2,28 +2,25 @@
This project uses [Deployer](https://deployer.org/) for scripted installation
## Preparation
To setup the customer repository, see [provisioning](provisioning.md).
### Server setup
Install Composer.
Install [Composer](https://getcomposer.org/).
Clone the repository into a separate directory (`deployer` for example) on your server and checkout this branch.
Run the command `composer create-project --dev d3/oxid-deployer-project deployer ^1.0`
Run `composer install` in it.
After that, add an alias for the deployer command: `alias dep='/usr/local/php8.2/bin/php /home/XXX/deployer/vendor/bin/dep'` and reload the changed configuration.
Add an alias for the deployer command: `alias dep='/usr/local/php8.2/bin/php /home/XXX/deployer/vendor/bin/dep'`. Load the changed configuration.
Rename `inventory.yml.dist` to `inventory.yml` and change project settings in it.
Change project settings in the `inventory.yml`.
Create a deploy key (if it's not exist). Set it in the repository settings.
Commit changed files.
Make sure, that Deployer has at least read access to the customers repository.
Commit changed files in the customers repository.
### Update Deployer
- `cd deployer`
- `composer update`
- apply changes in the `inventory.yml`
- commit changes
## Project

Voir le fichier

@ -1,5 +1,8 @@
{
"name": "d3/oxid-deployer-project",
"type": "project",
"license": "MIT",
"require-dev": {
"deployer/deployer": "^7.4"
"d3/oxid-deployer": "^1.0"
}
}

Voir le fichier

@ -1,137 +1,8 @@
<?php
namespace Deployer;
require 'recipe/composer.php';
require_once __DIR__.'/vendor/d3/oxid-deployer/recipe/oxid.php';
// Setup
import(__DIR__. '/inventory.yml');
// Hooks
after('deploy:failed', 'deploy:unlock');
after('deploy:vendors', 'deploy:d3OxidTasks');
/// Tasks
desc('Oxid related tasks');
task('deploy:d3OxidTasks', [
'deploy:clear_paths'
]);
desc('run all database migrations');
task('shop:runMigration', [
'shop:setShopsOffline',
'shop:executeMigrations',
'shop:setShopsOnline'
]);
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}} ]")
) {
$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.'"');
} else {
warning('missing config, task skipped');
}
});
task('shop:runMigration:failed', function() {
invoke('shop:setShopsOnline');
})->hidden();
fail('shop:runMigration', 'shop:runMigration:failed');
desc('execute OXID Doctrine migrations');
task('shop: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}} ]")
) {
$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.'"');
} else {
warning('missing config, task skipped');
}
});
desc('create database coniguration file');
task('setup:createDbConfig', function () {
try {
if (!has('db_conf_path') || !strlen(get('db_conf_path'))) {
throw new \RuntimeException('missing db_conf_path option, task stopped');
}
if (!test('[ -d $(dirname "{{db_conf_path}}") ]')) {
run('mkdir -p $(dirname "{{db_conf_path}}")');
if (!test('[ -d $(dirname "{{db_conf_path}}") ]')) {
throw new \RuntimeException('unable to create configured path {{db_conf_path}}, task stopped');
}
}
if (!test("[ -f {{db_conf_path}} ]")) {
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}}');
info('config successful created');
} else {
throw new \RuntimeException('can not create {{db_conf_path}}, task stopped');
}
} catch(\RuntimeException $e) {
warning($e->getMessage());
}
});
desc('show version of current OXID installation');
task('shop:getVersion', function () {
if (test("[ -f {{current_path}}/composer.lock ]")) {
cd('{{current_path}}');
info(
run(
'{{bin/composer}} show oxid-esales/oxideshop-ce | grep -ws "versions" | cut -d " " -f 4'
)
);
}
});
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');
}
});
import(__DIR__. '/inventory.yml');

Voir le fichier

@ -1,7 +1,7 @@
config:
application: my.shop.com
keep_releases: 5
repository: gitfhfac@git.d3data.de:Customers/my.shop.com.git
repository: git@github.com:Customers/my.shop.com.git
bin/php: /usr/local/php8.2/bin/php
bin/mysql: /usr/local/mysql/bin/mysql
bin/mysqldump: /usr/local/mysql/bin/mysqldump

Voir le fichier

@ -1,19 +0,0 @@
# Provisioning
## initial
- checkout the customer repository
- `git remote add deployment gitfhfac@git.d3data.de:D3Private/deployerRecipes.git && git remote set-url --push deployment DONTPUSH`
- `git fetch deployment`
- `git switch -c deployment deployment/rel_OXID_7.x`
checkout remote branch and rename it to `deployment`
- `git push origin deployment`
- `git remote rm deployment`
## update
- checkout the customer repository
- `git checkout deployment && git pull origin deployment`
- `git remote add deployment gitfhfac@git.d3data.de:D3Private/deployerRecipes.git && git remote set-url --push deployment DONTPUSH`
- `git fetch deployment`
- `git merge deployment/rel_OXID_7.x`
- `git push origin deployment`
- `git remote rm deployment`