This commit is contained in:
Bozhidar 2024-04-27 20:59:59 +03:00
parent 02e6953022
commit 671399b606
3 changed files with 32 additions and 8 deletions

View file

@ -37,6 +37,9 @@ class DockerContainer extends Model
'external_port', 'external_port',
'volume_mapping', 'volume_mapping',
'environment_variables', 'environment_variables',
'build_type',
'docker_template_id',
'docker_compose'
]; ];
protected $casts = [ protected $casts = [
@ -81,6 +84,10 @@ class DockerContainer extends Model
$dockerContainerApi->setName(Str::slug($model->name.'-phyre-'.$nextId)); $dockerContainerApi->setName(Str::slug($model->name.'-phyre-'.$nextId));
$dockerContainerApi->setExternalPort($model->external_port); $dockerContainerApi->setExternalPort($model->external_port);
if ($model->build_type == 'template') {
$dockerContainerApi->setDockerCompose($model->docker_compose);
}
$createContainer = $dockerContainerApi->run(); $createContainer = $dockerContainerApi->run();
if (!isset($createContainer['ID'])) { if (!isset($createContainer['ID'])) {
return false; return false;

View file

@ -14,6 +14,8 @@ class DockerContainerApi
public $port = ''; public $port = '';
public $externalPort = ''; public $externalPort = '';
public $dockerCompose = '';
public function setName($name) public function setName($name)
{ {
$name = trim($name); $name = trim($name);
@ -47,6 +49,11 @@ class DockerContainerApi
$this->externalPort = $externalPort; $this->externalPort = $externalPort;
} }
public function setDockerCompose($dockerCompose)
{
$this->dockerCompose = $dockerCompose;
}
public function recreate($containerId) public function recreate($containerId)
{ {
shell_exec('docker stop ' . $containerId); shell_exec('docker stop ' . $containerId);
@ -59,14 +66,18 @@ class DockerContainerApi
{ {
$commandId = rand(10000, 99999); $commandId = rand(10000, 99999);
$dockerComposeFileContent = view('docker::actions.docker-compose-yml', [ if (!empty($this->dockerCompose)) {
'name' => $this->name, $dockerComposeFileContent = $this->dockerCompose;
'image' => $this->image, } else {
'port' => $this->port, $dockerComposeFileContent = view('docker::actions.docker-compose-yml', [
'externalPort' => $this->externalPort, 'name' => $this->name,
'environmentVariables' => $this->environmentVariables, 'image' => $this->image,
'volumeMapping' => $this->volumeMapping, 'port' => $this->port,
])->render(); 'externalPort' => $this->externalPort,
'environmentVariables' => $this->environmentVariables,
'volumeMapping' => $this->volumeMapping,
])->render();
}
$dockerContaienrPath = storage_path('docker/'.$this->name); $dockerContaienrPath = storage_path('docker/'.$this->name);
if (!is_dir($dockerContaienrPath)) { if (!is_dir($dockerContaienrPath)) {

View file

@ -144,12 +144,18 @@ class DockerContainerResource extends Resource
Forms\Components\TextInput::make('port') Forms\Components\TextInput::make('port')
->label('Port') ->label('Port')
->hidden(function (Forms\Get $get) {
return $get('build_type') != 'image';
})
// ->disabled() // ->disabled()
->default($defaultPort) ->default($defaultPort)
->columnSpan(1), ->columnSpan(1),
Forms\Components\TextInput::make('external_port') Forms\Components\TextInput::make('external_port')
->label('External Port') ->label('External Port')
->hidden(function (Forms\Get $get) {
return $get('build_type') != 'image';
})
// ->disabled() // ->disabled()
->default($defaultExternalPort) ->default($defaultExternalPort)
->columnSpan(1), ->columnSpan(1),