Add an option to build magento artifact from the repository (#3456)

This commit is contained in:
guvra 2023-01-30 21:14:51 +01:00 committed by GitHub
parent 1bc90e8442
commit 30c66cee47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 18 deletions

View File

@ -245,9 +245,31 @@ settings section
```
### artifact_path
### build_from_repo
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L233)
If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory
```php title="Default value"
false
```
### repository
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L235)
Overrides [repository](/docs/recipe/common.md#repository) from `recipe/common.php`.
Set this value if "build_from_repo" is set to true. The target to deploy must also be set with "--branch", "--tag" or "--revision"
```php title="Default value"
null
```
### artifact_path
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L237)
```php title="Default value"
@ -259,7 +281,7 @@ return get('artifact_dir') . '/' . get('artifact_file');
### bin/tar
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L240)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L244)
:::info Autogenerated
@ -270,14 +292,14 @@ The value of this configuration is autogenerated on access.
### additional_shared_files
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L301)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L318)
Array of shared files that will be added to the default shared_files without overriding
### additional_shared_dirs
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L303)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L320)
Array of shared directories that will be added to the default shared_dirs without overriding
@ -395,7 +417,7 @@ This task is group task which contains next tasks:
### artifact:package
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L250)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L254)
Packages all relevant files in an artifact.
@ -403,7 +425,7 @@ tasks section
### artifact:upload
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L260)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L264)
Uploads artifact in release folder for extraction.
@ -411,7 +433,7 @@ Uploads artifact in release folder for extraction.
### artifact:extract
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L265)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L269)
Extracts artifact in release path.
@ -419,7 +441,7 @@ Extracts artifact in release path.
### build:remove-generated
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L271)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L275)
Clears generated files prior to building.
@ -427,7 +449,7 @@ Clears generated files prior to building.
### build:prepare
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L276)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L280)
Prepare local artifact build.
@ -435,7 +457,7 @@ Prepare local artifact build.
### deploy:additional-shared
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L307)
[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L324)
Adds additional files and dirs to the list of shared files and dirs.

View File

@ -229,6 +229,10 @@ after('deploy:failed', 'magento:maintenance:disable');
set('artifact_file', 'artifact.tar.gz');
set('artifact_dir', 'artifacts');
set('artifact_excludes_file', 'artifacts/excludes');
// If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory
set('build_from_repo', false);
// Set this value if "build_from_repo" is set to true. The target to deploy must also be set with "--branch", "--tag" or "--revision"
set('repository', null);
set('artifact_path', function () {
if (!test('[ -d {{artifact_dir}} ]')) {
@ -253,7 +257,7 @@ task('artifact:package', function() {
"No artifact excludes file provided, provide one at artivacts/excludes or change location"
);
}
run('{{bin/tar}} --exclude-from={{artifact_excludes_file}} -czf {{artifact_path}} .');
run('{{bin/tar}} --exclude-from={{artifact_excludes_file}} -czf {{artifact_path}} {{release_or_current_path}}');
});
desc('Uploads artifact in release folder for extraction.');
@ -274,14 +278,27 @@ task('build:remove-generated', function() {
desc('Prepare local artifact build');
task('build:prepare', function() {
if(! currentHost()->get('local')) {
{
throw new GracefulShutdownException("Artifact can only be built locally, you provided a non local host");
}
if (!currentHost()->get('local')) {
throw new GracefulShutdownException('Artifact can only be built locally, you provided a non local host');
}
set('deploy_path', '.');
set('release_path', '.');
set('current_path', '.');
$buildDir = get('build_from_repo') ? get('artifact_dir') . '/repo' : '.';
set('deploy_path', $buildDir);
set('release_path', $buildDir);
set('current_path', $buildDir);
if (!get('build_from_repo')) {
return;
}
$repository = (string) get('repository');
if ($repository === '') {
throw new GracefulShutdownException('You must specify the "repository" option.');
}
run('rm -rf {{release_or_current_path}}');
run('git clone {{repository}} {{release_or_current_path}}');
run('git -C {{release_or_current_path}} checkout --force {{target}}');
});
desc('Builds an artifact.');