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

meriial's avatar

How to reproduce Capistrano deploy/rollback with Envoy

I'm trying to recreate some of Capistrano's functionality with Envoy, namely deploy and rollback.

The trick is that Capistrano is able to capture results from the remote server commands and use those in other tasks. For example: (from https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/deploy.rake)

task :rollback_release_path do
    on release_roles(:all) do
      releases = capture(:ls, '-xt', releases_path).split
      if releases.count < 2
        error t(:cannot_rollback)
        exit 1
      end
      last_release = releases[1]
      set_release_path(last_release)
      set(:rollback_timestamp, last_release)
    end
  end

Notice the capture(:ls)....

Is that possible with Envoy? Is it possible to extend Envoy to do something like that?

Thanks!

0 likes
1 reply
bachilli's avatar

I do this with bash array:

@task('rollback')
    lastReleases=($((ls -tr {{ $home }}/{{ $domain }}/releases)|tail -2)))
    if [ ${#lastReleases[@]} -gt 1 ]; then
        sudo rm -rf {{ $home }}/{{ $domain }}/releases/${lastReleases[1]}
        rm {{ $home }}/{{ $domain }}/current
        ln -s {{ $home }}/{{ $domain }}/releases/${lastRelease[0]} {{ $home }}/{{ $domain }}/current
        ./slack-message.sh "Rollback realizado para o domínio {{ $domain }}. Versão atual: ${lastRelease[0]}."
    fi
@endtask

So, I list my releases folder ordering by date and make an array with the last two releases (actual and the last one who will be rollbacked).

Please or to participate in this conversation.