deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Only the last defined stage is found

Open greatwitenorth opened this issue 9 years ago • 6 comments

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>]

greatwitenorth avatar Nov 29 '17 16:11 greatwitenorth

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');

jvandesande avatar Dec 11 '17 10:12 jvandesande

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.

antonmedv avatar Dec 11 '17 10:12 antonmedv

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 ^^

skarnl avatar Jan 03 '18 07:01 skarnl

Any intention to solve this?

RdeWilde avatar Aug 30 '18 09:08 RdeWilde

bump- hitting this issue as well..

alyssenko avatar Sep 13 '18 07:09 alyssenko

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

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

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

antonmedv avatar Sep 13 '18 11:09 antonmedv