Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set variables for stages #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function prepare(bool $configureBuildStage, bool $configureServers, stri
$config->setLogger($this->log);

if ($configureBuildStage) {
$this->initializeBuildStage($config);
$this->initializeBuildStage($config, $stage);
}

if ($configureServers) {
Expand Down Expand Up @@ -204,17 +204,20 @@ private function configureStageServer(Stage $stage, Server $server, Configuratio
$host->setSshArguments($sshOptions);
}

foreach ($config->getVariables() as $key => $value) {
$this->log->debug(
sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $stage->getName())
);
$host->set($key, $value);
}
foreach ($config->getVariables('deploy') as $key => $value) {
$this->log->debug(
sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $stage->getName())
);
$host->set($key, $value);
$variableSections = [
'all',
'all:' . $stage->getName(),
'deploy',
'deploy:' . $stage->getName(),
];

foreach ($variableSections as $section) {
foreach ($config->getVariables($section) as $key => $value) {
$this->log->debug(
sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $section)
);
$host->set($key, $value);
}
}
}

Expand Down Expand Up @@ -265,26 +268,28 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche
/**
* Initialize build stage
*/
private function initializeBuildStage(Configuration $config): void
private function initializeBuildStage(Configuration $config, string $stage): void
{
$host = localhost('build');
$host->set('labels', ['stage' => 'build']);
$host->set('bin/php', 'php');
$host->set('deploy_path', '.');
$host->set('release_or_current_path', '.');

foreach ($config->getVariables() as $key => $value) {
$this->log->debug(
sprintf('Setting var "%s" to %s for stage "build"', $key, json_encode($value))
);
$host->set($key, $value);
}

foreach ($config->getVariables('build') as $key => $value) {
$this->log->debug(
sprintf('Setting var "%s" to %s for stage "build"', $key, json_encode($value))
);
$host->set($key, $value);
$variableSections = [
'all',
'all:' . $stage,
'build',
'build:' . $stage,
];

foreach ($variableSections as $section) {
foreach ($config->getVariables() as $key => $value) {
$this->log->debug(
sprintf('Setting var "%s" to %s for stage "%s"', $key, json_encode($value), $section),
);
$host->set($key, $value);
}
}
}

Expand Down