Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
php-commands: added share-network option
Browse files Browse the repository at this point in the history
  • Loading branch information
svensp committed Aug 22, 2019
1 parent 7e8dfa8 commit bd496de
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php namespace Rancherize\Blueprint\PhpCommands\EventHandler;

use Rancherize\Blueprint\Cron\CronService\CronService;
use Rancherize\Blueprint\Cron\Schedule\Exceptions\NoScheduleConfiguredException;
use Rancherize\Blueprint\Cron\Schedule\ScheduleParser;
use Rancherize\Blueprint\Events\MainServiceBuiltEvent;
use Rancherize\Blueprint\Events\ServiceBuiltEvent;
use Rancherize\Blueprint\Events\SidekickBuiltEvent;
use Rancherize\Blueprint\Infrastructure\Service\Maker\PhpFpm\PhpFpmMaker;
use Rancherize\Blueprint\Infrastructure\Service\NetworkMode\ShareNetworkMode;
use Rancherize\Blueprint\Infrastructure\Service\Service;
use Rancherize\Blueprint\Keepalive\KeepaliveService;
use Rancherize\Blueprint\PhpCommands\Parser\PhpCommandsParser;
Expand Down Expand Up @@ -88,6 +88,10 @@ public function mainServiceBuilt( MainServiceBuiltEvent $event ) {
'start-once' => Service::RESTART_START_ONCE,
];

$isSidekick = !$command->isService();
if( $isSidekick && $command->isNetworkShared() )
$service->setNetworkMode(new ShareNetworkMode($mainService));

if ( array_key_exists( $command->getRestart(), $restart ) )
$service->setRestart( $restart[$command->getRestart()] );

Expand Down
4 changes: 4 additions & 0 deletions app/Blueprint/PhpCommands/Parser/ArrayParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ public function parse( string $name, $data, $version ) {
if(array_key_exists('is-service', $data) && is_bool($data['is-service']) )
$isService = $data['is-service'];


$command = $data['command'];

$phpCommand = new PhpCommand( $commandName, $command, $isService );

if(array_key_exists('share-network', $data) && is_bool($data['share-network']) )
$phpCommand->setNetworkShared($data['share-network']);

if ( array_key_exists( 'restart', $data ) )
$phpCommand->setRestart( $data['restart'] );

Expand Down
23 changes: 23 additions & 0 deletions app/Blueprint/PhpCommands/PhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class PhpCommand {
*/
protected $configuration;

/**
* @var bool
*/
protected $networkShared = false;

/**
* PhpCommand constructor.
* @param string $name
Expand Down Expand Up @@ -133,4 +138,22 @@ public function hasKeepaliveService(): bool
return $this->keepaliveService;
}

/**
* @param bool $networkShared
* @return PhpCommand
*/
public function setNetworkShared(bool $networkShared): PhpCommand
{
$this->networkShared = $networkShared;
return $this;
}

/**
* @return bool
*/
public function isNetworkShared(): bool
{
return $this->networkShared;
}

}
1 change: 1 addition & 0 deletions app/Blueprint/PhpCommands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Use for commands that need to be run periodically
}
```

- `share-network` share the network of the main container. Only available when running as sidekick
- `keepalive` adds a dummy container which does nothing but stays active. The commands then join the network of this active container.
This helps with problems with the rancher dns service taking a few seconds after the container start to work. It also
improves reliability of sidekick services joining the network of your container because they don't have to restart with your original command.

0 comments on commit bd496de

Please sign in to comment.