feat(Application): add networkAliases attribute for handling network aliases as JSON or comma-separated values
This commit is contained in:
@@ -1361,7 +1361,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->application_deployment_queue->addLogEntry("Preparing container with helper image: $helperImage.");
|
$this->application_deployment_queue->addLogEntry("Preparing container with helper image: $helperImage.");
|
||||||
$this->application_deployment_queue->addLogEntry("Starting graceful shutdown container: {$this->deployment_uuid}");
|
|
||||||
$this->graceful_shutdown_container($this->deployment_uuid);
|
$this->graceful_shutdown_container($this->deployment_uuid);
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
[
|
[
|
||||||
@@ -1710,6 +1709,11 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
]);
|
]);
|
||||||
$this->application->parseHealthcheckFromDockerfile($this->saved_outputs->get('dockerfile_from_repo'));
|
$this->application->parseHealthcheckFromDockerfile($this->saved_outputs->get('dockerfile_from_repo'));
|
||||||
}
|
}
|
||||||
|
$network_aliases = [];
|
||||||
|
if (is_array($this->application->network_aliases) && count($this->application->network_aliases) > 0) {
|
||||||
|
$network_aliases = $this->application->network_aliases;
|
||||||
|
}
|
||||||
|
ray($network_aliases);
|
||||||
$docker_compose = [
|
$docker_compose = [
|
||||||
'services' => [
|
'services' => [
|
||||||
$this->container_name => [
|
$this->container_name => [
|
||||||
@@ -1721,7 +1725,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
$this->destination->network => [
|
$this->destination->network => [
|
||||||
'aliases' => array_merge(
|
'aliases' => array_merge(
|
||||||
[$this->container_name],
|
[$this->container_name],
|
||||||
$this->application->network_aliases ? explode(',', $this->application->network_aliases) : []
|
$network_aliases
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -118,6 +118,66 @@ class Application extends BaseModel
|
|||||||
|
|
||||||
protected $casts = ['network_aliases' => 'array'];
|
protected $casts = ['network_aliases' => 'array'];
|
||||||
|
|
||||||
|
public function networkAliases(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
set: function ($value) {
|
||||||
|
if (is_null($value) || $value === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's already a JSON string, decode it
|
||||||
|
if (is_string($value) && $this->isJson($value)) {
|
||||||
|
$value = json_decode($value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a string but not JSON, treat it as a comma-separated list
|
||||||
|
if (is_string($value) && ! is_array($value)) {
|
||||||
|
$value = explode(',', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = collect($value)
|
||||||
|
->map(function ($alias) {
|
||||||
|
if (is_string($alias)) {
|
||||||
|
return str_replace(' ', '-', trim($alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
->filter()
|
||||||
|
->unique() // Remove duplicate values
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return empty($value) ? null : json_encode($value);
|
||||||
|
},
|
||||||
|
get: function ($value) {
|
||||||
|
if (is_null($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($value) && $this->isJson($value)) {
|
||||||
|
return json_decode($value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_array($value) ? $value : [];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a string is a valid JSON
|
||||||
|
*/
|
||||||
|
private function isJson($string)
|
||||||
|
{
|
||||||
|
if (! is_string($string)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
json_decode($string);
|
||||||
|
|
||||||
|
return json_last_error() === JSON_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::addGlobalScope('withRelations', function ($builder) {
|
static::addGlobalScope('withRelations', function ($builder) {
|
||||||
|
|||||||
Reference in New Issue
Block a user