andres-montanez / Magallanes

The PHP Deployment Tool
https://magephp.com
MIT License
691 stars 169 forks source link

Cleaning up old Releases ... FAIL #430

Closed panosru closed 3 years ago

panosru commented 5 years ago

I'm testing mage, it seems cool, but it does not remove old releases:

image

.mage.yml:

magephp:
  log_dir: /root/test/mage-logs
  environments:
    production:
      user: root
      branch: develop
      from: ./src
      host_path: /root/projects/fault-manager
      releases: 2
      exclude:
        - ./Traits
      hosts:
        - droplet-tecfinity

      post-release:
        - fs/copy: { from: 'Fault.php', to: 'Fault2.php' }

The log result:

root@c061b4c256fc:~/test/fault-manager# cat ../mage-logs/20190205_205032.log
[2019-02-05 20:50:32] magephp.DEBUG: Environment: production [] []
[2019-02-05 20:50:32] magephp.DEBUG: Release ID: 20190205205032 [] []
[2019-02-05 20:50:32] magephp.DEBUG: Running task [Git] Change Branch (develop) (git/change-branch) [] []
[2019-02-05 20:50:32] magephp.INFO: git branch | grep "*" [] []
[2019-02-05 20:50:32] magephp.DEBUG: * develop  [] []
[2019-02-05 20:50:32] magephp.DEBUG: Task [Git] Change Branch (develop) (git/change-branch) finished with SKIPPED, thrown SkipException [] []
[2019-02-05 20:50:32] magephp.DEBUG: Running task [Deploy] Preparing Tar file (deploy/tar/prepare) [] []
[2019-02-05 20:50:32] magephp.INFO: tar cfzp /tmp/mageFZqwDp --exclude=".git" --exclude="./Traits" ./src [] []
[2019-02-05 20:50:32] magephp.DEBUG:  [] []
[2019-02-05 20:50:32] magephp.DEBUG: Task [Deploy] Preparing Tar file (deploy/tar/prepare) finished with OK [] []
[2019-02-05 20:50:32] magephp.DEBUG: Running task [Release] Preparing Release (deploy/release/prepare) [] []
[2019-02-05 20:50:32] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "mkdir -p /root/projects/fault-manager/releases/20190205205032" [] []
[2019-02-05 20:50:33] magephp.DEBUG:  [] []
[2019-02-05 20:50:33] magephp.DEBUG: Task [Release] Preparing Release (deploy/release/prepare) finished with OK [] []
[2019-02-05 20:50:33] magephp.DEBUG: Running task [Deploy] Copying files with Tar (deploy/tar/copy) [] []
[2019-02-05 20:50:33] magephp.INFO: scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageFZqwDp root@droplet-tecfinity:/root/projects/fault-manager/releases/20190205205032/mageFZqwDp [] []
[2019-02-05 20:50:33] magephp.DEBUG:  [] []
[2019-02-05 20:50:33] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "cd /root/projects/fault-manager/releases/20190205205032 && tar xfzop mageFZqwDp" [] []
[2019-02-05 20:50:34] magephp.DEBUG:  [] []
[2019-02-05 20:50:34] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "rm /root/projects/fault-manager/releases/20190205205032/mageFZqwDp" [] []
[2019-02-05 20:50:35] magephp.DEBUG:  [] []
[2019-02-05 20:50:35] magephp.DEBUG: Task [Deploy] Copying files with Tar (deploy/tar/copy) finished with OK [] []
[2019-02-05 20:50:35] magephp.DEBUG: Running task [Release] Creating Symlink (deploy/release) [] []
[2019-02-05 20:50:35] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "cd /root/projects/fault-manager && ln -snf releases/20190205205032 current" [] []
[2019-02-05 20:50:35] magephp.DEBUG:  [] []
[2019-02-05 20:50:35] magephp.DEBUG: Task [Release] Creating Symlink (deploy/release) finished with OK [] []
[2019-02-05 20:50:35] magephp.DEBUG: Running task [Release] Cleaning up old Releases (deploy/release/cleanup) [] []
[2019-02-05 20:50:35] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "ls -1 /root/projects/fault-manager/releases" [] []
[2019-02-05 20:50:36] magephp.DEBUG:  [] []
[2019-02-05 20:50:36] magephp.ERROR:  [] []
[2019-02-05 20:50:36] magephp.DEBUG: Task [Release] Cleaning up old Releases (deploy/release/cleanup) finished with FAIL [] []

Also, shouldn't it rename the file Fault.php to Fault2.php? image

Thanks!

panosru commented 5 years ago

If I var_dump the $process variable here https://github.com/andres-montanez/Magallanes/blob/e30de6b719c923d70917a9f9364efdb29b7e9362/src/Task/BuiltIn/Deploy/Release/CleanupTask.php#L42

I receive:

/root/.composer/vendor/andres-montanez/magallanes/src/Task/BuiltIn/Deploy/Release/CleanupTask.php:43:
class Symfony\Component\Process\Process#72 (25) {
  private $callback =>
  NULL
  private $hasCallback =>
  bool(false)
  private $commandline =>
  string(141) "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "ls -1 /root/projects/fault-manager/releases""
  private $cwd =>
  string(24) "/root/test/fault-manager"
  private $env =>
  NULL
  private $input =>
  NULL
  private $starttime =>
  double(1549405586.8632)
  private $lastOutputTime =>
  double(1549405586.8632)
  private $timeout =>
  double(120)
  private $idleTimeout =>
  NULL
  private $exitcode =>
  int(255)
  private $fallbackStatus =>
  array(0) {
  }
  private $processInformation =>
  array(8) {
    'command' =>
    string(141) "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@droplet-tecfinity "ls -1 /root/projects/fault-manager/releases""
    'pid' =>
    int(1258)
    'running' =>
    bool(false)
    'signaled' =>
    bool(false)
    'stopped' =>
    bool(false)
    'exitcode' =>
    int(255)
    'termsig' =>
    int(0)
    'stopsig' =>
    int(0)
  }
  private $outputDisabled =>
  bool(false)
  private $stdout =>
  resource(204) of type (stream)
  private $stderr =>
  resource(206) of type (stream)
  private $process =>
  resource(211) of type (Unknown)
  private $status =>
  string(10) "terminated"
  private $incrementalOutputOffset =>
  int(0)
  private $incrementalErrorOutputOffset =>
  int(0)
  private $tty =>
  NULL
  private $pty =>
  bool(false)
  private $useFileHandles =>
  bool(false)
  private $processPipes =>
  class Symfony\Component\Process\Pipes\UnixPipes#74 (8) {
    private $ttyMode =>
    NULL
    private $ptyMode =>
    bool(false)
    private $haveReadSupport =>
    bool(true)
    public $pipes =>
    array(0) {
    }
    private $inputBuffer =>
    string(0) ""
    private $input =>
    NULL
    private $blocked =>
    bool(false)
    private $lastError =>
    NULL
  }
  private $latestSignal =>
  NULL
}

$process->isSuccessful(); returns false

but if I run the command manually, it works fine: image

aurimasval commented 2 years ago

Still relevant on version 5

[2022-06-13T22:23:11.522611+00:00] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /var/www/html/deploy_key/key test@test.com "cd /var/www && ln -snf releases/20220613222242 laravel" [] []
[2022-06-13T22:23:12.643536+00:00] magephp.DEBUG:  [] []
[2022-06-13T22:23:12.644664+00:00] magephp.DEBUG: Task [Release] Creating Symlink (deploy/release) finished with OK [] []
[2022-06-13T22:23:12.645473+00:00] magephp.DEBUG: Running task [Exec] Rm env (exec) [] []
[2022-06-13T22:23:12.646186+00:00] magephp.INFO: ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /var/www/html/deploy_key/key test@test.com "cd /var/www/releases/20220613222242 && rm .env && mv .env.prod .env" [] []
[2022-06-13T22:23:12.726123+00:00] magephp.DEBUG:  [] []
[2022-06-13T22:23:12.726598+00:00] magephp.ERROR:  [] []
[2022-06-13T22:23:12.727400+00:00] magephp.DEBUG: Task [Exec] Rm env (exec) finished with FAIL [] []
aurimasval commented 2 years ago

It looks like problem is with Rate limiting with UFW not with php code itself.