Deployer: Only the last defined stage is found

Created on 29 Nov 2017  路  6Comments  路  Source: deployphp/deployer

| Q | A
| ----------------- | ---
| Issue Type | Bug
| Deployer Version | v6.0.3
| Local Machine OS | macOS 10.13.1
| Remote Machine OS | Centos 6.9

Description

When I try to deploy to one of my stages I get this error message:

[Deployer\Exception\Exception]
  Hostname or stage `production` was not found.

If I change the order of 'production' to be the last defined host, then it works as expected.

Steps to reproduce

I use the following command and I see the error message:

vendor/bin/dep deploy production

Content of deploy.php

The following produces and error message when deploying to production:

// Configure servers
host('mysite.com')
    ->user('myuser')
    ->set('branch', 'master')
    ->stage('production')
    ->set('phinx.environment', 'production')
    ->set('deploy_path', '/home/mysite/production');

host('mysite.com')
    ->user('myuser')
    ->set('branch', 'dev')
    ->stage('staging')
    ->set('phinx.environment', 'staging')
    ->set('deploy_path', '/home/mysite/staging');

The following works when deploying to production (but breaks deploying to staging):

// Configure servers
host('mysite.com')
    ->user('myuser')
    ->set('branch', 'dev')
    ->stage('staging')
    ->set('phinx.environment', 'staging')
    ->set('deploy_path', '/home/mysite/staging');

host('mysite.com')
    ->user('myuser')
    ->set('branch', 'master')
    ->stage('production')
    ->set('phinx.environment', 'production')
    ->set('deploy_path', '/home/mysite/production');

Output log

  [Deployer\Exception\Exception]
  Hostname or stage `production` was not found.


Exception trace:
 () at /Users/me/Projects/mysite/vendor/deployer/deployer/src/Host/HostSelector.php:59
 Deployer\Host\HostSelector->getHosts() at /Users/me/Projects/mysite/vendor/deployer/deployer/src/Console/TaskCommand.php:118
 Deployer\Console\TaskCommand->execute() at /Users/me/Projects/mysite/vendor/symfony/console/Command/Command.php:240
 Symfony\Component\Console\Command\Command->run() at /Users/me/Projects/mysite/vendor/symfony/console/Application.php:858
 Symfony\Component\Console\Application->doRunCommand() at /Users/me/Projects/mysite/vendor/deployer/deployer/src/Console/Application.php:132
 Deployer\Console\Application->doRunCommand() at /Users/me/Projects/mysite/vendor/symfony/console/Application.php:216
 Symfony\Component\Console\Application->doRun() at /Users/me/Projects/mysite/vendor/symfony/console/Application.php:122
 Symfony\Component\Console\Application->run() at /Users/me/Projects/mysite/vendor/deployer/deployer/src/Deployer.php:324
 Deployer\Deployer::run() at /Users/me/Projects/mysite/vendor/deployer/deployer/bin/dep:120

deploy [-p|--parallel] [-l|--limit LIMIT] [--no-hooks] [--log LOG] [--roles ROLES] [--hosts HOSTS] [-o|--option OPTION] [--] [<stage>]

Most helpful comment

Yes, actually im working on this. Will land in v7. With new stage syntax:

stage('staging', function () {
    host('...');
});

stage('production', function () {
    host('...');
});

All 6 comments

I have encountered the same issue today. I solved it by using a fake hostname in the initial host call. You can set the correct hostname with the hostname function. So in your example it would look like this:

// Configure servers
host('mysite.com')
    ->user('myuser')
    ->set('branch', 'dev')
    ->stage('staging')
    ->set('phinx.environment', 'staging')
    ->set('deploy_path', '/home/mysite/staging');

host('production.mysite.com')
    ->hostname('mysite.com')
    ->user('myuser')
    ->set('branch', 'master')
    ->stage('production')
    ->set('phinx.environment', 'production')
    ->set('deploy_path', '/home/mysite/production');

I have encountered the same issue today. I solved it by using a fake hostname in the initial host call. You can set the correct hostname with the hostname function. So in your example it would look like this:

Yes, this is a way of doing it right now. It's preparation for better functionality in next major release.

I just set it up differently and this made even more sense for me:

host('staging')
    ->hostname('staging.server.address.com')
    ->stage('staging')
    ->user('staging_user')
    ->set('deploy_path', '/home/path/for/staging')
;

host('production')
    ->hostname('production.server.address.com')
    ->stage('production')
    ->user('production_user')
    ->set('deploy_path', '/home/path/for/production')
;

This way, when you don't give a stage for dep ssh you get to pick the environment by it's name and not by the address. Which is even better imho ^^

Any intention to solve this?

bump- hitting this issue as well..

Yes, actually im working on this. Will land in v7. With new stage syntax:

stage('staging', function () {
    host('...');
});

stage('production', function () {
    host('...');
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dima-stefantsov picture dima-stefantsov  路  5Comments

dima-stefantsov picture dima-stefantsov  路  4Comments

lsv picture lsv  路  4Comments

flashios09 picture flashios09  路  4Comments

sweebee picture sweebee  路  3Comments