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

Commit

Permalink
Merge pull request #32 from ipunkt/feature-use-environment-vars-for-a…
Browse files Browse the repository at this point in the history
…ccess

feature-use-environment-vars-for-access
  • Loading branch information
justb81 authored Aug 24, 2017
2 parents 4f7432c + f515e33 commit f8d69c8
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 111 deletions.
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ RUN apk update \
&& apk add --no-cache \
git \
docker \
py-pip

COPY [".", "/opt/rancherize"]
WORKDIR /opt/rancherize
py-pip \
# install docker-compose
&& pip install docker-compose==$DOCKER_COMPOSE_VERSION \
&& apk del py-pip

# load rancher-compose
RUN curl -SL "https://github.com/rancher/rancher-compose/releases/download/v$RANCHER_COMPOSE_VERSION/rancher-compose-linux-amd64-v$RANCHER_COMPOSE_VERSION.tar.gz" \
| tar xz \
&& mv rancher-compose-*/rancher-compose /usr/local/bin/ && cp /usr/local/bin/rancher-compose /usr/local/bin/rancher-compose-$RANCHER_COMPOSE_VERSION
&& mv rancher-compose-*/rancher-compose /usr/local/bin/ \
&& cp /usr/local/bin/rancher-compose /usr/local/bin/rancher-compose-$RANCHER_COMPOSE_VERSION

COPY [".", "/opt/rancherize"]
WORKDIR /opt/rancherize

# install composer packages
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& ./composer.phar install && rm composer.phar

# install docker-compose
RUN pip install docker-compose==$DOCKER_COMPOSE_VERSION
&& ./composer.phar install --no-dev && rm composer.phar

ENTRYPOINT ["/opt/rancherize/rancherize"]
#ENTRYPOINT ["/bin/sh"]
4 changes: 2 additions & 2 deletions app/Commands/EnvironmentVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Rancherize\Commands\Traits\ValidateTrait;
use Rancherize\Configuration\Traits\EnvironmentConfigurationTrait;
use Rancherize\Configuration\Traits\LoadsConfigurationTrait;
use Rancherize\RancherAccess\RancherAccessService;
use Rancherize\RancherAccess\RancherAccessConfigService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$configuration = $this->loadConfiguration();
$config = $this->environmentConfig($configuration, $environment);

$rancherConfiguration = new RancherAccessService($configuration);
$rancherConfiguration = new RancherAccessConfigService($configuration);
$account = $rancherConfiguration->getAccount( $config->get('rancher.account') );

$rancher = $this->getRancher();
Expand Down
8 changes: 4 additions & 4 deletions app/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Rancherize\Configuration\Configurable;
use Rancherize\Configuration\Services\ConfigWrapper;
use Rancherize\Configuration\Traits\LoadsConfigurationTrait;
use Rancherize\Docker\DockerAccessService;
use Rancherize\RancherAccess\RancherAccessService;
use Rancherize\Docker\DockerAccessConfigService;
use Rancherize\RancherAccess\RancherAccessConfigService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -51,15 +51,15 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$blueprint = $this->getBlueprintService()->load($blueprintName, $input->getOptions());

$configuration->set('project.blueprint', $blueprintName);
$rancherAccessService = new RancherAccessService($configuration);
$rancherAccessService = new RancherAccessConfigService($configuration);

$accounts = $rancherAccessService->availableAccounts();
if (!$configuration->has('project.default.rancher.account'))
$configuration->set('project.default.rancher.account', reset($accounts));


/**
* @var DockerAccessService $dockerAccessService
* @var DockerAccessConfigService $dockerAccessService
*/
$dockerAccessService = container('docker-access-service');
$dockerAccessService->parse($configuration);
Expand Down
11 changes: 8 additions & 3 deletions app/Commands/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
use Rancherize\Configuration\Configuration;
use Rancherize\Configuration\Traits\EnvironmentConfigurationTrait;
use Rancherize\Configuration\Traits\LoadsConfigurationTrait;
use Rancherize\Docker\DockerAccessService;
use Rancherize\Docker\DockerAccessConfigService;
use Rancherize\Docker\DockerAccount;
use Rancherize\RancherAccess\Exceptions\NoActiveServiceException;
use Rancherize\RancherAccess\Exceptions\StackNotFoundException;
use Rancherize\RancherAccess\HealthStateMatcher;
use Rancherize\RancherAccess\InServiceCheckerTrait;
use Rancherize\RancherAccess\RancherAccessConfigService;
use Rancherize\RancherAccess\RancherAccessService;
use Rancherize\RancherAccess\SingleStateMatcher;
use Rancherize\Services\DockerService;
Expand Down Expand Up @@ -64,7 +65,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$configuration = $this->loadConfiguration();
$config = $this->environmentConfig($configuration, $environment);

$rancherConfiguration = new RancherAccessService($configuration);
/**
* @var RancherAccessService $rancherConfiguration
*/
$rancherConfiguration = container('rancher-access-service');
$rancherConfiguration->parse($configuration);
$account = $rancherConfiguration->getAccount( $config->get('rancher.account') );

$rancher = $this->getRancher();
Expand Down Expand Up @@ -132,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
protected function login(Configuration $configuration, Configuration $config) {

/**
* @var DockerAccessService $dockerAccessService
* @var DockerAccessConfigService $dockerAccessService
*/
$dockerAccessService = container('docker-access-service');
$dockerAccessService->parse($configuration);
Expand Down
34 changes: 34 additions & 0 deletions app/Configuration/Loader/NullLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rancherize\Configuration\Loader;
use Rancherize\Configuration\Configurable;

/**
* Class NullLoader
*
*
*
* @package Rancherize\Configuration\Loader
*/
class NullLoader implements Loader
{

/**
* @param Configurable $configurable
* @param string $path
*/
function load(Configurable $configurable, string $path)
{
// do nothing
}

/**
* @param string|null $prefix
* @return $this
*/
function setPrefix(string $prefix = null): Loader
{
$this->prefix = $prefix;
return $this;
}
}
64 changes: 64 additions & 0 deletions app/Docker/DockerAccessConfigService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php namespace Rancherize\Docker;
use Rancherize\Configuration\Configuration;
use Rancherize\Docker\Events\DockerRetrievingAccountEvent;
use Rancherize\Docker\Exceptions\AccountNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
* Class DockerAccessConfigService
* @package Rancherize\Docker
*
* Reads the DockerAccounts from the configuration
*/
class DockerAccessConfigService implements DockerAccessService
{

/**
* @var array
*/
protected $accounts = [];
/**
* @var EventDispatcher
*/
private $eventDispatcher;

/**
* DockerAccessConfigService constructor.
* @param EventDispatcher $eventDispatcher
*/
public function __construct(EventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}

/**
* @return array
*/
public function availableAccounts() {
return array_keys($this->accounts);
}

/**
* @param string $name
* @return DockerAccount
*/
public function getAccount(string $name) : DockerAccount {
if(!array_key_exists($name, $this->accounts))
throw new AccountNotFoundException($name);

$dockerAccount = new ArrayDockerAccount($this->accounts[$name]);
$retrievingEvent = new DockerRetrievingAccountEvent($name, $this->accounts[$name], $dockerAccount);

$this->eventDispatcher->dispatch(DockerRetrievingAccountEvent::NAME, $retrievingEvent);
$dockerAccount = $retrievingEvent->getDockerAccount();

return $dockerAccount;
}

/**
* @param $configuration
*/
public function parse( Configuration $configuration ) {
$this->accounts = $configuration->get('global.docker');
}

}
83 changes: 28 additions & 55 deletions app/Docker/DockerAccessService.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,36 @@
<?php namespace Rancherize\Docker;
<?php
/**
* rancherize
*
* @author bastian
* @since 24.08.17
*/

namespace Rancherize\Docker;
use Rancherize\Configuration\Configuration;
use Rancherize\Docker\Events\DockerRetrievingAccountEvent;
use Rancherize\Docker\Exceptions\AccountNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcher;


/**
* Class DockerAccessService
* Class DockerAccessConfigService
* @package Rancherize\Docker
*
* Reads the DockerAccounts from the configuration
*/
class DockerAccessService {

/**
* @var array
*/
protected $accounts = [];
/**
* @var EventDispatcher
*/
private $eventDispatcher;

/**
* DockerAccessService constructor.
* @param EventDispatcher $eventDispatcher
*/
public function __construct(EventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}

/**
* @return array
*/
public function availableAccounts() {
return array_keys($this->accounts);
}

/**
* @param string $name
* @return DockerAccount
*/
public function getAccount(string $name) : DockerAccount {
if(!array_key_exists($name, $this->accounts))
throw new AccountNotFoundException($name);

$dockerAccount = new ArrayDockerAccount($this->accounts[$name]);
$retrievingEvent = new DockerRetrievingAccountEvent($name, $this->accounts[$name], $dockerAccount);

$this->eventDispatcher->dispatch(DockerRetrievingAccountEvent::NAME, $retrievingEvent);
$dockerAccount = $retrievingEvent->getDockerAccount();

return $dockerAccount;
}

/**
* @param $configuration
*/
public function parse( Configuration $configuration ) {
$this->accounts = $configuration->get('global.docker');
}

interface DockerAccessService
{
/**
* @return array
*/
public function availableAccounts();

/**
* @param string $name
* @return DockerAccount
*/
public function getAccount(string $name): DockerAccount;

/**
* @param $configuration
*/
public function parse(Configuration $configuration);
}
2 changes: 1 addition & 1 deletion app/Docker/DockerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DockerProvider implements Provider {
*/
public function register() {
$this->container['docker-access-service'] = function($c) {
return new DockerAccessService($c['event']);
return new DockerAccessConfigService($c['event']);
};
}

Expand Down
69 changes: 69 additions & 0 deletions app/EnvironmentAccessConfig/DockerAccessEnvironmentService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php namespace Rancherize\EnvironmentAccessConfig;
use Rancherize\Configuration\Configuration;
use Rancherize\Docker\ArrayDockerAccount;
use Rancherize\Docker\DockerAccessService;
use Rancherize\Docker\DockerAccount;
use Rancherize\Docker\Events\DockerRetrievingAccountEvent;
use Rancherize\Docker\Exceptions\AccountNotFoundException;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
* Class DockerConfigAccessService
* @package Rancherize\Docker
*
* Reads the DockerAccounts from the configuration
*/
class DockerAccessEnvironmentService implements DockerAccessService
{

/**
* @var array
*/
protected $account = [];
/**
* @var EventDispatcher
*/
private $eventDispatcher;

/**
* DockerConfigAccessService constructor.
* @param EventDispatcher $eventDispatcher
*/
public function __construct(EventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}

/**
* @return array
*/
public function availableAccounts() {
return ['default'];
}

/**
* @param string $name
* @return DockerAccount
*/
public function getAccount(string $name) : DockerAccount {
$dockerAccount = new ArrayDockerAccount($this->account);

$retrievingEvent = new DockerRetrievingAccountEvent($name, $this->account, $dockerAccount);

$this->eventDispatcher->dispatch(DockerRetrievingAccountEvent::NAME, $retrievingEvent);
$dockerAccount = $retrievingEvent->getDockerAccount();

return $dockerAccount;
}

/**
* @param $configuration
*/
public function parse( Configuration $configuration ) {
$this->account = [
'user' => getenv('DOCKER_USER'),
'password' => getenv('DOCKER_PASSWORD'),
'ecr' => getenv('DOCKER_ECR') ?: false
];
}

}
Loading

0 comments on commit f8d69c8

Please sign in to comment.