Home > Blockchain >  Unable to deploy a Laravel application with deployer
Unable to deploy a Laravel application with deployer

Time:11-28

Recently, I have upgraded Deployer from 6.X to 7.X and followed the upgrade guide from Deployer. Since I've made theses changes, I am unable to deploy application on the Gitlab CI. The error come from command deploy:update_code

[dev-env]  error  in update_code.php on line 90:
[dev-env] run export GIT_TERMINAL_PROMPT='0' GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new'; [ -f /web/.dep/repo/HEAD ] || /usr/bin/git clone --mirror  /web/.dep/repo 2>&1
[dev-env] fatal: repository '/web/.dep/repo' does not exist
[dev-env] exit code 128 (Invalid exit argument)

I have followed instructions given from this Github issue but with no concluent result

<?php

namespace Deployer;

/*
 |--------------------------------------------------------------------------
 | 0. Import needed recipes, and make sure the environment is right
 |--------------------------------------------------------------------------
 |
 */

require 'contrib/rsync.php';
require 'recipe/laravel.php';

/*
 |--------------------------------------------------------------------------
 | 1. Load external dependencies
 |--------------------------------------------------------------------------
 */

set('dotenv', '{{current_path}}/.env');

/*
 |--------------------------------------------------------------------------
 | 2. Variables
 |--------------------------------------------------------------------------
 */

set('$this->setRemoteUser()name', getenv('DEPLOYER_NAME', 'unknown'));
set('application', 'priv');
set('http_$this->setRemoteUser()', 'www-data');
set('keep_releases', 3);

/*
 |--------------------------------------------------------------------------
 | 3. Shared & Writable files / folders
 |--------------------------------------------------------------------------
 */

set('shared_dirs', [
    'storage'
]);

set('shared_files', [
    'public/.htaccess',
    '.env',
]);

add('writable_dirs', [

]);

/*
 |--------------------------------------------------------------------------
 | 4. Hosts
 |--------------------------------------------------------------------------
 */

/** PREPROD Priv1 */
host('priv-env')
    ->setHostname('10.95.1.1')
    ->setForwardAgent(false)
    ->setRemoteUser('priv')
    ->set('deploy_path', '/web')
    ->set('rsync_src', __DIR__)
    ->set('rsync_dest', '{{release_path}}')
    ->set('module', 'priv')
    ->setLabels([
       'group' => 'preProdHosts',
        'name' => 'dev-env',
    ]);

/*
 |--------------------------------------------------------------------------
 | 5. Tasks
 |--------------------------------------------------------------------------
 */

task('ca_cleanup', function() {
    run('cd {{release_path}}/ && php7.4 artisan ca:cl');
})->select('group=preProdHosts,group=prodHosts');

task('co_reload', function() {
    run('cd {{release_path}}/ && php7.4 artisan co:cl');
})->select('group=preProdHosts,group=prodHosts');

set('rsync', function () {
    $currentModule = get('module');
    $modulePaths = [
        'priv'  => [
            'Modules/Priv/*',
            'public/modules/priv/*',
    ];

    $exclude = [
        'node_modules/*',
        'tests/*',
        '.git',
        'deploy.php',
    ];

    foreach ($modulePaths as $moduleName => $modulePath) {
        if (empty($currentModule) || $currentModule === $moduleName) {
            continue;
        }
        $exclude = array_merge($exclude, $modulePath);
    }

    return [
        'exclude'       => $exclude,
        'exclude-file'  => '',
        'include'       => [],
        'include-file'  => false,
        'filter'        => [],
        'filter-file'   => false,
        'filter-perdir' => false,
        'flags'         => 'avz',
        'options'       => ['delete', 'delete-after', 'force'],
        'timeout'       => 1200,
    ];
});

task('deploy:storage_link_hybride', function () {
    run('cd {{release_path}}/public && ln -s ../storage/app/public/hybride/ ');
});

task('deploy:storage_link_elfinder', function () {
    run('cd {{release_path}}/public && ln -s ../storage/app/public/elfinder/ ');
});

task('deploy:migrate_n_seed', function () {
    run('cd {{release_path}}/ && php7.4 artisan migrate --force');
    run('cd {{release_path}}/ && php7.4 artisan db:seed --class=AdminRolesPermissionsUpdaterTableSeeder --force');
    run('cd {{release_path}}/ && php7.4 artisan db:seed --class=CustomerRolesPermissionsUpdaterTableSeeder --force');
});

task('deploy:migrate_n_priv_seed', function () {
    run('cd {{release_path}}/ && php7.4 artisan module:seed Priv --class=PrivRolesPermissionsUpdaterTableSeeder --force');
})->select('name=priv-preprod,name=prod');

task('deploy:migrate_n_amundi_seed', function () {
    run('cd {{release_path}}/ && php7.4 artisan module:seed Amundi --class=AmundiRolesPermissionsUpdaterTableSeeder --force');
    run('cd {{release_path}}/public/modules/amundi-catitre && ln -s ../amundi/fonts fonts');
    run('cd {{release_path}}/public/modules/amundi-catitre && ln -s ../amundi/images images');
    run('cd {{release_path}}/public/modules/amundi-catitre && ln -s ../amundi/documents documents');
})->select('name=priv2-preprod,name=priv2-prod');

task('sitemap:generate', function () {
    run('cd {{release_path}}/ && php artisan sitemap:generate');
})->select('name=priv-preprod,name=prod');

task('deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'rsync',
    'deploy:shared',
    'deploy:storage_link_elfinder',
    'deploy:storage_link_hybride',
    'deploy:migrate_n_seed',
    'deploy:migrate_n_priv_seed',
    'deploy:migrate_n_priv2_seed',
    'sitemap:generate',
    'deploy:symlink',
    'deploy:unlock',
    'ca_cleanup',
    'co_reload',
    'deploy:cleanup'
])->desc('Deploy your project');

after('deploy:failed', 'deploy:unlock');

CodePudding user response:

After investigating a bit on this, I've found the solution

On deployer 6.X, the task deploy:prepare only checks if deploy_path exists, otherwise create it. On deployer 7.X, deploy:prepare is completing many other tasks, as well as deploy:info, deploy:setup etc... and particulary deploy:update_code. This command try to fetch code from release_path on host, witch I haven't defined since I want to fetch code locally with rsync.

The solution was to suppress deploy:prepare from task flow since I already call tasks bundled onto this command

  • Related