Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ChristopherSFSD's avatar

Critique my Envoy script?

I've created my own Envoy script for deployment to my various other environments and I'm wondering if there is anything critical I may be missing. I'm looking for any comments / critique on my script. Are there any additions or changes you would make? Should I be calling composer clear-cache or anything like that?

{{--
    EXAMPLE USAGE:

    envoy run deploy --env=dev
    envoy run deploy --env=staging --seed=StagingDatabaseSeeder
--}}
@servers(['myservername' => '[email protected]'])

@setup
    $paths = array(
        'dev' => '/Library/Server/Web/Data/Sites/AppName/dev',
        'staging' => '/Library/Server/Web/Data/Sites/AppName/staging',
        'production' => '/Library/Server/Web/Data/Sites/AppName/production'
    );
@endsetup

@task('down')
    cd {{ $paths[$env] }}
    /usr/local/bin/php artisan down
@endtask

@task('git')
    cd {{ $paths[$env] }}
    git pull origin master
@endtask

@task('composer')
    cd {{ $paths[$env] }}

    export PATH=$PATH:/usr/local/bin

    composer.phar install
    composer.phar dump-autoload -o
@endtask

@task('migrate')
    cd {{ $paths[$env] }}

    @if(isset($seed) && strlen($seed))
        /usr/local/bin/php artisan migrate:refresh --env={{$env}} --seeder={{$seed}}
    @else
        /usr/local/bin/php artisan migrate --env={{$env}}
    @endif

    echo {{ 'DB Migration complete.' . ((isset($seed) && strlen($seed)) ? ' Seeded with ' . $seed : '') }}
@endtask

@task('optimize')
    cd {{ $paths[$env] }}
    /usr/local/bin/php artisan optimize
@endtask

@task('up')
    cd {{ $paths[$env] }}
    /usr/local/bin/php artisan up
@endtask

@task('deploy-complete')
    echo {{ 'Deployment to ' . strtoupper($env) . ' complete.' }}
@endtask

@macro('deploy')
    down
    git
    composer
    migrate
    optimize
    up
    deploy-complete
@endmacro

@macro('pull')
    git
    deploy-complete
@endmacro
0 likes
2 replies
ChristopherSFSD's avatar

I do have one issue with deployment right now ... composer install does not seem to run. If I ssh to the project folder and composer install, it works but in Envoy it does not. It outputs "Your requirements could not be resolved to an installable set of packages"

I'm at a loss as to why that is.

EDIT: I did add a clear-compiled task that runs before the composer task.

ChristopherSFSD's avatar

I found that it wasn't finding composer.phar because of a $PATH issue. And I got a little more clever with a few things. Here's my updated Envoy script ...

{{--
    EXAMPLE USAGE:

    envoy run deploy --env=dev
    envoy run deploy --env=staging --seed=StagingDatabaseSeeder
--}}
@servers(['myservername' => '[email protected]'])

@setup
    $paths = array(
        'dev' => '/Library/Server/Web/Data/Sites/AppName/dev',
        'staging' => '/Library/Server/Web/Data/Sites/AppName/staging',
        'production' => '/Library/Server/Web/Data/Sites/AppName/production'
    );

    $cd = 'cd ' . $paths[$env];
    $php = '/usr/local/bin/php';
    $art = $php . ' artisan';
@endsetup

@task('down')
    {{ $cd }}
    {{ $art }} down
@endtask

@task('git')
    {{ $cd }}
    git pull origin master
@endtask

@task('clear')
    {{ $cd }}
    {{ $art }} clear-compiled
@endtask

@task('composer')
    {{ $cd }}

    export PATH=/usr/local/bin

    composer.phar install
    composer.phar dump-autoload -o
@endtask

@task('migrate')
    {{ $cd }}

    @if(isset($seed) && strlen($seed))
        {{ $art }} migrate:refresh --env={{$env}} --seeder={{$seed}}
    @else
        {{ $art }} migrate --env={{$env}}
    @endif

    echo {{ 'DB Migration complete.' . ((isset($seed) && strlen($seed)) ? ' Seeded with ' . $seed : '') }}
@endtask

@task('optimize')
    {{ $cd }}
    {{ $art }} optimize
@endtask

@task('up')
    {{ $cd }}
    {{ $art }} up
@endtask

@task('deploy-complete')
    echo {{ 'Deployment to ' . strtoupper($env) . ' complete.' }}
@endtask

@macro('deploy')
    down
    git
    clear
    composer
    migrate
    optimize
    up
    deploy-complete
@endmacro

@macro('pull')
    git
    deploy-complete
@endmacro

Please or to participate in this conversation.