fix: custom container name will be the container name, not just internal network name

This commit is contained in:
Andras Bacsai 2024-07-02 10:02:43 +02:00
parent da6f2da3d0
commit 1249b1ece9
2 changed files with 28 additions and 44 deletions

View File

@ -194,6 +194,9 @@ public function __construct(int $application_deployment_queue_id)
$this->is_debug_enabled = $this->application->settings->is_debug_enabled; $this->is_debug_enabled = $this->application->settings->is_debug_enabled;
$this->container_name = generateApplicationContainerName($this->application, $this->pull_request_id); $this->container_name = generateApplicationContainerName($this->application, $this->pull_request_id);
if ($this->application->settings->custom_internal_name && ! $this->application->settings->is_consistent_container_name_enabled) {
$this->container_name = $this->application->settings->custom_internal_name;
}
ray('New container name: ', $this->container_name); ray('New container name: ', $this->container_name);
savePrivateKeyToFs($this->server); savePrivateKeyToFs($this->server);
@ -1570,23 +1573,6 @@ private function generate_compose_file()
], ],
], ],
]; ];
if (isset($this->application->settings->custom_internal_name)) {
$docker_compose['services'][$this->container_name]['networks'][$this->destination->network]['aliases'][] = $this->application->settings->custom_internal_name;
}
// if (str($this->saved_outputs->get('dotenv'))->isNotEmpty()) {
// if (data_get($docker_compose, "services.{$this->container_name}.env_file")) {
// $docker_compose['services'][$this->container_name]['env_file'][] = '.env';
// } else {
// $docker_compose['services'][$this->container_name]['env_file'] = ['.env'];
// }
// }
// if ($this->env_filename) {
// if (data_get($docker_compose, "services.{$this->container_name}.env_file")) {
// $docker_compose['services'][$this->container_name]['env_file'][] = $this->env_filename;
// } else {
// $docker_compose['services'][$this->container_name]['env_file'] = [$this->env_filename];
// }
// }
if (! is_null($this->env_filename)) { if (! is_null($this->env_filename)) {
$docker_compose['services'][$this->container_name]['env_file'] = [$this->env_filename]; $docker_compose['services'][$this->container_name]['env_file'] = [$this->env_filename];
} }
@ -1697,16 +1683,11 @@ private function generate_compose_file()
if (count($volume_names) > 0) { if (count($volume_names) > 0) {
$docker_compose['volumes'] = $volume_names; $docker_compose['volumes'] = $volume_names;
} }
// if ($this->build_pack === 'dockerfile') {
// $docker_compose['services'][$this->container_name]['build'] = [
// 'context' => $this->workdir,
// 'dockerfile' => $this->workdir . $this->dockerfile_location,
// ];
// }
if ($this->pull_request_id === 0) { if ($this->pull_request_id === 0) {
$custom_compose = convert_docker_run_to_compose($this->application->custom_docker_run_options); $custom_compose = convert_docker_run_to_compose($this->application->custom_docker_run_options);
if ((bool) $this->application->settings->is_consistent_container_name_enabled) { if ((bool) $this->application->settings->is_consistent_container_name_enabled) {
if (! $this->application->settings->custom_internal_name) {
$docker_compose['services'][$this->application->uuid] = $docker_compose['services'][$this->container_name]; $docker_compose['services'][$this->application->uuid] = $docker_compose['services'][$this->container_name];
if (count($custom_compose) > 0) { if (count($custom_compose) > 0) {
$ipv4 = data_get($custom_compose, 'ip.0'); $ipv4 = data_get($custom_compose, 'ip.0');
@ -1724,6 +1705,7 @@ private function generate_compose_file()
} }
$docker_compose['services'][$this->application->uuid] = array_merge_recursive($docker_compose['services'][$this->application->uuid], $custom_compose); $docker_compose['services'][$this->application->uuid] = array_merge_recursive($docker_compose['services'][$this->application->uuid], $custom_compose);
} }
}
} else { } else {
if (count($custom_compose) > 0) { if (count($custom_compose) > 0) {
$ipv4 = data_get($custom_compose, 'ip.0'); $ipv4 = data_get($custom_compose, 'ip.0');

View File

@ -31,12 +31,14 @@
helper="The deployed container will have the same name ({{ $application->uuid }}). <span class='font-bold dark:text-warning'>You will lose the rolling update feature!</span>" helper="The deployed container will have the same name ({{ $application->uuid }}). <span class='font-bold dark:text-warning'>You will lose the rolling update feature!</span>"
instantSave id="application.settings.is_consistent_container_name_enabled" instantSave id="application.settings.is_consistent_container_name_enabled"
label="Consistent Container Names" /> label="Consistent Container Names" />
@if (!$application->settings->is_consistent_container_name_enabled)
<form class="flex items-end gap-2 pl-2" wire:submit.prevent='saveCustomName'> <form class="flex items-end gap-2 pl-2" wire:submit.prevent='saveCustomName'>
<x-forms.input <x-forms.input
helper="You can add a custom internal name for your container. This name will be used in the internal network. <br><br>The name will be converted to slug format when you save it. <span class='font-bold dark:text-warning'>You will lose the rolling update feature!</span>" helper="You can add a custom name for your container.<br><br>The name will be converted to slug format when you save it. <span class='font-bold dark:text-warning'>You will lose the rolling update feature!</span>"
instantSave id="application.settings.custom_internal_name" label="Add Custom Internal Name" /> instantSave id="application.settings.custom_internal_name" label="Custom Container Name" />
<x-forms.button type="submit">Save</x-forms.button> <x-forms.button type="submit">Save</x-forms.button>
</form> </form>
@endif
@if ($application->build_pack === 'dockercompose') @if ($application->build_pack === 'dockercompose')
<h3>Network</h3> <h3>Network</h3>
<x-forms.checkbox instantSave id="application.settings.connect_to_docker_network" <x-forms.checkbox instantSave id="application.settings.connect_to_docker_network"