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

Commit

Permalink
added mount-workdir support for nginx snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Speckmaier committed Jul 13, 2017
1 parent 454428b commit fd934fe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ class NginxSnippetExtraInformation implements ServiceExtraInformation {

const IDENTIFIER = 'nginx-snippet';

/**
* @var array
*/
protected $snippets = [];

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

/**
* @return mixed
*/
Expand All @@ -32,4 +40,18 @@ public function addSnippet( $path ) {
public function getSnippets(): array {
return $this->snippets;
}

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

/**
* @param bool $mountWorkdir
*/
public function setMountWorkdir( bool $mountWorkdir ) {
$this->mountWorkdir = $mountWorkdir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function parse( Service $service, Configuration $configuration ) {
if( empty($snippets) )
return;

if( $configuration->get('mount-workdir', false) )
$extraInformation->setMountWorkdir(true);

foreach( $snippets as $snippet )
$extraInformation->addSnippet($snippet);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Rancherize\Blueprint\NginxSnippets\NginxSnippetService;

use Rancherize\Blueprint\Infrastructure\Dockerfile\Dockerfile;
use Rancherize\Blueprint\Infrastructure\Infrastructure;
use Rancherize\Blueprint\Infrastructure\Service\ExtraInformationNotFoundException;
use Rancherize\Blueprint\Infrastructure\Service\Service;
Expand Down Expand Up @@ -31,8 +32,36 @@ public function addToInfrastructure( Infrastructure $infrastructure, Service $se
if( empty($snippets) )
return;

$dockerfile->addVolume('/etc/nginx/server.d');
foreach($snippets as $snippet)
$dockerfile->copy($snippet, '/etc/nginx/server.d/');
if( $information->isMountWorkdir() ) {

$this->addSnippetsToService( $service, $snippets );

return;
}

$this->addSnippetsToImage( $dockerfile, $snippets );

}

/**
* @param $dockerfile
* @param $snippets
*/
protected function addSnippetsToImage( Dockerfile $dockerfile, $snippets ) {
$dockerfile->addVolume( '/etc/nginx/server.d' );
foreach ( $snippets as $snippet )
$dockerfile->copy( $snippet, '/etc/nginx/server.d/' );
}

/**
* @param Service $service
* @param $snippets
*/
protected function addSnippetsToService( Service $service, $snippets ) {
foreach ( $snippets as $snippet ) {
$filename = basename( $snippet );
$service->addVolume( getcwd() . DIRECTORY_SEPARATOR . $snippet, '/etc/nginx/server.d/' . $filename );

}
}
}

0 comments on commit fd934fe

Please sign in to comment.