diff --git a/docs/recipe/deploy/update_code.md b/docs/recipe/deploy/update_code.md index 84aafc93..4e9eae3d 100644 --- a/docs/recipe/deploy/update_code.md +++ b/docs/recipe/deploy/update_code.md @@ -39,6 +39,22 @@ Can be one of: ``` +### sub_directory +[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/update_code.php#L31) + +Specifies a sub directory within the repository to deploy. +Works only when [`update_code_strategy`](#update_code_strategy) is set to `archive` (default). + +Example: + - set value to `src` if you want to deploy the folder that lives at `/src`. + - set value to `src/api` if you want to deploy the folder that lives at `/src/api`. + +Note: do not use a leading `/`! + +```php title="Default value" +null +``` + ### git_ssh_command [Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/update_code.php#L53) @@ -49,14 +65,14 @@ will not permit connections to hosts with changed host keys. ```php title="Default value" 'ssh -o StrictHostKeyChecking=accept-new' -``` + ## Tasks ### deploy:update_code -[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/update_code.php#L59) + Updates code. diff --git a/recipe/deploy/update_code.php b/recipe/deploy/update_code.php index e9737150..98017636 100644 --- a/recipe/deploy/update_code.php +++ b/recipe/deploy/update_code.php @@ -52,6 +52,18 @@ set('update_code_strategy', 'archive'); // will not permit connections to hosts with changed host keys. set('git_ssh_command', 'ssh -o StrictHostKeyChecking=accept-new'); +/** + * Specifies a sub directory within the repository to deploy. + * Works only when [`update_code_strategy`](#update_code_strategy) is set to `archive` (default). + * + * Example: + * - set value to `src` if you want to deploy the folder that lives at `/src/api`. + * - set value to `src/api` if you want to deploy the folder that lives at `/src/api`. + * + * Note: do not use a leading `/`! + */ +set('sub_directory', null); + /** * Update code at {{release_path}} on host. */ @@ -60,6 +72,7 @@ task('deploy:update_code', function () { $git = get('bin/git'); $repository = get('repository'); $target = get('target'); + $subtarget = get('sub_directory') ? "$target:{{sub_directory}}" : $target; $bare = parse('{{deploy_path}}/.dep/repo'); $env = [ @@ -85,7 +98,7 @@ task('deploy:update_code', function () { // Copy to release_path. if (get('update_code_strategy') === 'archive') { - run("$git archive $target | tar -x -f - -C {{release_path}} 2>&1"); + run("$git archive $subtarget | tar -x -f - -C {{release_path}} 2>&1"); } else if (get('update_code_strategy') === 'clone') { cd('{{release_path}}'); run("$git clone -l $bare .");