Skip to content

Commit

Permalink
fix: remove build & tag options
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Oct 6, 2023
1 parent 2912e89 commit 6a42621
Showing 1 changed file with 1 addition and 80 deletions.
81 changes: 1 addition & 80 deletions src/controllers/BuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@

namespace SamIT\Yii2\StaticAssets\controllers;

use Docker\API\Model\AuthConfig;
use Docker\API\Model\BuildInfo;
use Docker\API\Model\PushImageInfo;
use Docker\Docker;
use Docker\Stream\BuildStream;
use Docker\Stream\PushStream;
use Psr\Http\Message\ResponseInterface;
use SamIT\Docker\Context;
use SamIT\Yii2\StaticAssets\Module;
use Symfony\Component\Filesystem\Filesystem;
use yii\base\InvalidConfigException;
use yii\console\Controller;
use yii\helpers\Console;

Expand All @@ -27,32 +18,6 @@ class BuildController extends Controller
{
public $defaultAction = 'build';

/**
* @var string The name of the created image
* If not explicitly set will take its default from module config.
*/
public $image;

/**
* @var string The tag of the created image
* If not explicitly set will take its default from module config.
*/
public $tag;

/**
* @var bool whether to push the image after a successful build.
* If not explicitly set will take its default from module config.
*/
public $push;

public function init(): void
{
parent::init();
$this->push = $this->module->push;
$this->image = $this->module->image;
$this->tag = $this->module->tag;
}

/**
* @param string $targetPath The path where the docker build context should be stored
*/
Expand All @@ -67,51 +32,7 @@ public function actionCreateContext(string $targetPath): void
$filesystem->mirror($context->getDirectory(), $targetPath);
}

public function actionBuild(): void
{
if ($this->push && !isset($this->image)) {
throw new InvalidConfigException("When using the push option, you must configure or provide image");
}

$name = "{$this->image}:{$this->tag}";

$docker = new \SamIT\Docker\Docker();
$context = $this->module->createBuildContext();
$this->color = true;
$docker->build($context, $name);



if ($this->push) {
$docker->push($name);
}
}


public function options($actionID)
{
$result = parent::options($actionID);
switch ($actionID) {
case 'create-context':
case 'build':
$result[] = 'push';
$result[] = 'image';
$result[] = 'tag';
break;
}
return $result;
}

public function optionAliases()
{
$result = parent::optionAliases();
$result['p'] = 'push';
$result['t'] = 'tag';
$result['i'] = 'image';
return $result;
}

public function stdout($string)
public function stdout($string): int
{
if ($this->isColorEnabled()) {
$args = \func_get_args();
Expand Down

0 comments on commit 6a42621

Please sign in to comment.