Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 27, 2024
1 parent 02e6953 commit 671399b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
7 changes: 7 additions & 0 deletions web/Modules/Docker/App/Models/DockerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DockerContainer extends Model
'external_port',
'volume_mapping',
'environment_variables',
'build_type',
'docker_template_id',
'docker_compose'
];

protected $casts = [
Expand Down Expand Up @@ -81,6 +84,10 @@ public static function boot()
$dockerContainerApi->setName(Str::slug($model->name.'-phyre-'.$nextId));
$dockerContainerApi->setExternalPort($model->external_port);

if ($model->build_type == 'template') {
$dockerContainerApi->setDockerCompose($model->docker_compose);
}

$createContainer = $dockerContainerApi->run();
if (!isset($createContainer['ID'])) {
return false;
Expand Down
27 changes: 19 additions & 8 deletions web/Modules/Docker/DockerContainerApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class DockerContainerApi
public $port = '';
public $externalPort = '';

public $dockerCompose = '';

public function setName($name)
{
$name = trim($name);
Expand Down Expand Up @@ -47,6 +49,11 @@ public function setExternalPort($externalPort)
$this->externalPort = $externalPort;
}

public function setDockerCompose($dockerCompose)
{
$this->dockerCompose = $dockerCompose;
}

public function recreate($containerId)
{
shell_exec('docker stop ' . $containerId);
Expand All @@ -59,14 +66,18 @@ public function run()
{
$commandId = rand(10000, 99999);

$dockerComposeFileContent = view('docker::actions.docker-compose-yml', [
'name' => $this->name,
'image' => $this->image,
'port' => $this->port,
'externalPort' => $this->externalPort,
'environmentVariables' => $this->environmentVariables,
'volumeMapping' => $this->volumeMapping,
])->render();
if (!empty($this->dockerCompose)) {
$dockerComposeFileContent = $this->dockerCompose;
} else {
$dockerComposeFileContent = view('docker::actions.docker-compose-yml', [
'name' => $this->name,
'image' => $this->image,
'port' => $this->port,
'externalPort' => $this->externalPort,
'environmentVariables' => $this->environmentVariables,
'volumeMapping' => $this->volumeMapping,
])->render();
}

$dockerContaienrPath = storage_path('docker/'.$this->name);
if (!is_dir($dockerContaienrPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,18 @@ public static function form(Form $form): Form

Forms\Components\TextInput::make('port')
->label('Port')
->hidden(function (Forms\Get $get) {
return $get('build_type') != 'image';
})
// ->disabled()
->default($defaultPort)
->columnSpan(1),

Forms\Components\TextInput::make('external_port')
->label('External Port')
->hidden(function (Forms\Get $get) {
return $get('build_type') != 'image';
})
// ->disabled()
->default($defaultExternalPort)
->columnSpan(1),
Expand Down

0 comments on commit 671399b

Please sign in to comment.