1

Given:

  • Single-page frontend application(angularJS) & API backend service(Symfony3)
  • One host for one stage which hosts both the front- & the backend
  • Deployer version 6.0.3

The question is: how to be able to deploy both of them using the following format of command: dep deploy [frontend|backend]. The problem now is: you have to describe them as 2 separate hosts, as they use different parameters, repository & deploy_path at least. Then if you keep them in one file you can't just have 2 tasks for backend & frontend described as so:

task('deploy', [
    'deploy:info',
    .
    .
    .
])->onHosts(['[frontend|backend]']);

I mean you can, but then in command line you gonna write dep deploy stage --hosts frontend & dep deploy stage --hosts backend either one of them will fail with error:

  No task will be executed, because the selected hosts do not meet the conditions of the tasks.

My guess is that it overrides the task itself & will execute the one that stands last.


AND OK. I can be have a workaround for that too

task('deploy:frontend', [
    'deploy:info',
    .
    .
    .
]);
task('deploy:backend', [
    'deploy:info',
    .
    .
    .
]);

This way, will be logical to run it with dep deploy:[frontend|backend] stage, BUT since both frontend & backend live on the same server & they both have deploy_path parameters for instance, it just overrides the deploy parameters with the last host's configuration in the file.


For that matter what I've used is onHosts() function with some tweaking on hosts declarations;

host('backend')
    ->hostname('host.com')
host('frontend')
    ->hostname('host.com')

& 2 tasks defined:

task('deploy:[frontend|backend]', [
    'deploy:info',
    .
    .
    .
])->onHosts(['[frontend|backend]']);

this way you'll have to deploy as so: dep deploy:[frontend|backend] stage --hosts [frontend|backend] which you all agree is nonsensical.

My further guess is to separate deploys into 2 files as backend.php & frontend.php. dep deploy stage -f [frontend|backend].php, but for everyday operations it is inconvenient, like database import/export...

Please share your opinions or solutions to this problem

Den Rolya
  • 29
  • 5

1 Answers1

0

Define tasks: frontend and backend, then you can simply do: dep backend hostname/stage or dep frontend.

The second parameter of the dep command is a task name, not the fixed word deploy.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
  • not an option, since you'll have to either override tasks you want to use in both scenarios with different names or you have to specify '--hosts' – Den Rolya Nov 07 '17 at 15:42