refactor: applicationdeploymentjob
This commit is contained in:
parent
668c9e5a64
commit
022762c0c9
@ -17,7 +17,6 @@
|
|||||||
use App\Notifications\Application\DeploymentFailed;
|
use App\Notifications\Application\DeploymentFailed;
|
||||||
use App\Notifications\Application\DeploymentSuccess;
|
use App\Notifications\Application\DeploymentSuccess;
|
||||||
use App\Traits\ExecuteRemoteCommand;
|
use App\Traits\ExecuteRemoteCommand;
|
||||||
use Exception;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -27,12 +26,13 @@
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Sleep;
|
use Illuminate\Support\Sleep;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use RuntimeException;
|
|
||||||
use Spatie\Url\Url;
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use Throwable;
|
|
||||||
use Visus\Cuid2\Cuid2;
|
use Visus\Cuid2\Cuid2;
|
||||||
|
use Spatie\Url\Url;
|
||||||
use Yosymfony\Toml\Toml;
|
use Yosymfony\Toml\Toml;
|
||||||
|
use Exception;
|
||||||
|
use RuntimeException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
|
|
||||||
private int $application_deployment_queue_id;
|
private int $application_deployment_queue_id;
|
||||||
|
|
||||||
private bool $newVersionIsHealthy = false;
|
private bool $is_new_version_healthy = false;
|
||||||
private ApplicationDeploymentQueue $application_deployment_queue;
|
private ApplicationDeploymentQueue $application_deployment_queue;
|
||||||
private Application $application;
|
private Application $application;
|
||||||
private string $deployment_uuid;
|
private string $deployment_uuid;
|
||||||
@ -54,8 +54,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
private bool $force_rebuild;
|
private bool $force_rebuild;
|
||||||
private bool $restart_only;
|
private bool $restart_only;
|
||||||
|
|
||||||
private ?string $dockerImage = null;
|
private ?string $docker_image = null;
|
||||||
private ?string $dockerImageTag = null;
|
private ?string $docker_image_tag = null;
|
||||||
|
|
||||||
private GithubApp|GitlabApp|string $source = 'other';
|
private GithubApp|GitlabApp|string $source = 'other';
|
||||||
private StandaloneDocker|SwarmDocker $destination;
|
private StandaloneDocker|SwarmDocker $destination;
|
||||||
@ -66,7 +66,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
private bool $use_build_server = false;
|
private bool $use_build_server = false;
|
||||||
// Save original server between phases
|
// Save original server between phases
|
||||||
private Server $original_server;
|
private Server $original_server;
|
||||||
private Server $mainServer;
|
private Server $main_server;
|
||||||
private ?ApplicationPreview $preview = null;
|
private ?ApplicationPreview $preview = null;
|
||||||
private ?string $git_type = null;
|
private ?string $git_type = null;
|
||||||
private bool $only_this_server = false;
|
private bool $only_this_server = false;
|
||||||
@ -92,19 +92,19 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
private string $docker_compose_location = '/docker-compose.yml';
|
private string $docker_compose_location = '/docker-compose.yml';
|
||||||
private ?string $docker_compose_custom_start_command = null;
|
private ?string $docker_compose_custom_start_command = null;
|
||||||
private ?string $docker_compose_custom_build_command = null;
|
private ?string $docker_compose_custom_build_command = null;
|
||||||
private ?string $addHosts = null;
|
private ?string $add_hosts = null;
|
||||||
private ?string $buildTarget = null;
|
private ?string $build_target = null;
|
||||||
private Collection $saved_outputs;
|
private Collection $saved_outputs;
|
||||||
private ?string $full_healthcheck_url = null;
|
private ?string $full_healthcheck_url = null;
|
||||||
|
|
||||||
private string $serverUser = 'root';
|
private string $server_user = 'root';
|
||||||
private string $serverUserHomeDir = '/root';
|
private string $server_user_home_dir = '/root';
|
||||||
private string $dockerConfigFileExists = 'NOK';
|
private string $is_docker_config_file_exists = 'NOK';
|
||||||
|
|
||||||
private int $customPort = 22;
|
private int $custom_port = 22;
|
||||||
private ?string $customRepository = null;
|
private ?string $custom_repository = null;
|
||||||
|
|
||||||
private ?string $fullRepoUrl = null;
|
private ?string $full_repository_url = null;
|
||||||
private ?string $branch = null;
|
private ?string $branch = null;
|
||||||
|
|
||||||
private ?string $coolify_variables = null;
|
private ?string $coolify_variables = null;
|
||||||
@ -134,8 +134,8 @@ public function __construct(int $application_deployment_queue_id)
|
|||||||
$this->server = Server::find($this->application_deployment_queue->server_id);
|
$this->server = Server::find($this->application_deployment_queue->server_id);
|
||||||
$this->timeout = $this->server->settings->dynamic_timeout;
|
$this->timeout = $this->server->settings->dynamic_timeout;
|
||||||
$this->destination = $this->server->destinations()->where('id', $this->application_deployment_queue->destination_id)->first();
|
$this->destination = $this->server->destinations()->where('id', $this->application_deployment_queue->destination_id)->first();
|
||||||
$this->server = $this->mainServer = $this->destination->server;
|
$this->server = $this->main_server = $this->destination->server;
|
||||||
$this->serverUser = $this->server->user;
|
$this->server_user = $this->server->user;
|
||||||
$this->basedir = $this->application->generateBaseDir($this->deployment_uuid);
|
$this->basedir = $this->application->generateBaseDir($this->deployment_uuid);
|
||||||
$this->workdir = "{$this->basedir}" . rtrim($this->application->base_directory, '/');
|
$this->workdir = "{$this->basedir}" . rtrim($this->application->base_directory, '/');
|
||||||
$this->configuration_dir = application_configuration_dir() . "/{$this->application->uuid}";
|
$this->configuration_dir = application_configuration_dir() . "/{$this->application->uuid}";
|
||||||
@ -217,17 +217,17 @@ public function handle(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->addHosts = $ips->map(function ($ip, $name) {
|
$this->add_hosts = $ips->map(function ($ip, $name) {
|
||||||
return "--add-host $name:$ip";
|
return "--add-host $name:$ip";
|
||||||
})->implode(' ');
|
})->implode(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->application->dockerfile_target_build) {
|
if ($this->application->dockerfile_target_build) {
|
||||||
$this->buildTarget = " --target {$this->application->dockerfile_target_build} ";
|
$this->build_target = " --target {$this->application->dockerfile_target_build} ";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check custom port
|
// Check custom port
|
||||||
['repository' => $this->customRepository, 'port' => $this->customPort] = $this->application->customRepository();
|
['repository' => $this->custom_repository, 'port' => $this->custom_port] = $this->application->custom_repository();
|
||||||
|
|
||||||
if (data_get($this->application, 'settings.is_build_server_enabled')) {
|
if (data_get($this->application, 'settings.is_build_server_enabled')) {
|
||||||
$teamId = data_get($this->application, 'environment.project.team.id');
|
$teamId = data_get($this->application, 'environment.project.team.id');
|
||||||
@ -355,14 +355,14 @@ private function deploy_simple_dockerfile()
|
|||||||
}
|
}
|
||||||
private function deploy_dockerimage_buildpack()
|
private function deploy_dockerimage_buildpack()
|
||||||
{
|
{
|
||||||
$this->dockerImage = $this->application->docker_registry_image_name;
|
$this->docker_image = $this->application->docker_registry_image_name;
|
||||||
if (str($this->application->docker_registry_image_tag)->isEmpty()) {
|
if (str($this->application->docker_registry_image_tag)->isEmpty()) {
|
||||||
$this->dockerImageTag = 'latest';
|
$this->docker_image_tag = 'latest';
|
||||||
} else {
|
} else {
|
||||||
$this->dockerImageTag = $this->application->docker_registry_image_tag;
|
$this->docker_image_tag = $this->application->docker_registry_image_tag;
|
||||||
}
|
}
|
||||||
ray("echo 'Starting deployment of {$this->dockerImage}:{$this->dockerImageTag} to {$this->server->name}.'");
|
ray("echo 'Starting deployment of {$this->docker_image}:{$this->docker_image_tag} to {$this->server->name}.'");
|
||||||
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->dockerImage}:{$this->dockerImageTag} to {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->docker_image}:{$this->docker_image_tag} to {$this->server->name}.");
|
||||||
$this->generate_image_names();
|
$this->generate_image_names();
|
||||||
$this->prepare_builder_image();
|
$this->prepare_builder_image();
|
||||||
$this->generate_compose_file();
|
$this->generate_compose_file();
|
||||||
@ -382,7 +382,7 @@ private function deploy_docker_compose_buildpack()
|
|||||||
if ($this->pull_request_id === 0) {
|
if ($this->pull_request_id === 0) {
|
||||||
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->application->name} to {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->application->name} to {$this->server->name}.");
|
||||||
} else {
|
} else {
|
||||||
$this->application_deployment_queue->addLogEntry("Starting pull request (#{$this->pull_request_id}) deployment of {$this->customRepository}:{$this->application->git_branch} to {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Starting pull request (#{$this->pull_request_id}) deployment of {$this->custom_repository}:{$this->application->git_branch} to {$this->server->name}.");
|
||||||
}
|
}
|
||||||
$this->prepare_builder_image();
|
$this->prepare_builder_image();
|
||||||
$this->check_git_if_build_needed();
|
$this->check_git_if_build_needed();
|
||||||
@ -464,7 +464,7 @@ private function deploy_docker_compose_buildpack()
|
|||||||
}
|
}
|
||||||
private function deploy_dockerfile_buildpack()
|
private function deploy_dockerfile_buildpack()
|
||||||
{
|
{
|
||||||
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->customRepository}:{$this->application->git_branch} to {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->custom_repository}:{$this->application->git_branch} to {$this->server->name}.");
|
||||||
if ($this->use_build_server) {
|
if ($this->use_build_server) {
|
||||||
$this->server = $this->build_server;
|
$this->server = $this->build_server;
|
||||||
}
|
}
|
||||||
@ -499,7 +499,7 @@ private function deploy_nixpacks_buildpack()
|
|||||||
if ($this->use_build_server) {
|
if ($this->use_build_server) {
|
||||||
$this->server = $this->build_server;
|
$this->server = $this->build_server;
|
||||||
}
|
}
|
||||||
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->customRepository}:{$this->application->git_branch} to {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->custom_repository}:{$this->application->git_branch} to {$this->server->name}.");
|
||||||
$this->prepare_builder_image();
|
$this->prepare_builder_image();
|
||||||
$this->check_git_if_build_needed();
|
$this->check_git_if_build_needed();
|
||||||
$this->set_base_dir();
|
$this->set_base_dir();
|
||||||
@ -532,7 +532,7 @@ private function deploy_static_buildpack()
|
|||||||
if ($this->use_build_server) {
|
if ($this->use_build_server) {
|
||||||
$this->server = $this->build_server;
|
$this->server = $this->build_server;
|
||||||
}
|
}
|
||||||
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->customRepository}:{$this->application->git_branch} to {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->custom_repository}:{$this->application->git_branch} to {$this->server->name}.");
|
||||||
$this->prepare_builder_image();
|
$this->prepare_builder_image();
|
||||||
$this->check_git_if_build_needed();
|
$this->check_git_if_build_needed();
|
||||||
$this->set_base_dir();
|
$this->set_base_dir();
|
||||||
@ -657,7 +657,7 @@ private function generate_image_names()
|
|||||||
$this->production_image_name = "{$this->application->uuid}:latest";
|
$this->production_image_name = "{$this->application->uuid}:latest";
|
||||||
}
|
}
|
||||||
} else if ($this->application->build_pack === 'dockerimage') {
|
} else if ($this->application->build_pack === 'dockerimage') {
|
||||||
$this->production_image_name = "{$this->dockerImage}:{$this->dockerImageTag}";
|
$this->production_image_name = "{$this->docker_image}:{$this->docker_image_tag}";
|
||||||
} else if ($this->pull_request_id !== 0) {
|
} else if ($this->pull_request_id !== 0) {
|
||||||
if ($this->application->docker_registry_image_name) {
|
if ($this->application->docker_registry_image_name) {
|
||||||
$this->build_image_name = "{$this->application->docker_registry_image_name}:pr-{$this->pull_request_id}-build";
|
$this->build_image_name = "{$this->application->docker_registry_image_name}:pr-{$this->pull_request_id}-build";
|
||||||
@ -667,22 +667,22 @@ private function generate_image_names()
|
|||||||
$this->production_image_name = "{$this->application->uuid}:pr-{$this->pull_request_id}";
|
$this->production_image_name = "{$this->application->uuid}:pr-{$this->pull_request_id}";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->dockerImageTag = str($this->commit)->substr(0, 128);
|
$this->docker_image_tag = str($this->commit)->substr(0, 128);
|
||||||
if ($this->application->docker_registry_image_tag) {
|
if ($this->application->docker_registry_image_tag) {
|
||||||
$this->dockerImageTag = $this->application->docker_registry_image_tag;
|
$this->docker_image_tag = $this->application->docker_registry_image_tag;
|
||||||
}
|
}
|
||||||
if ($this->application->docker_registry_image_name) {
|
if ($this->application->docker_registry_image_name) {
|
||||||
$this->build_image_name = "{$this->application->docker_registry_image_name}:{$this->dockerImageTag}-build";
|
$this->build_image_name = "{$this->application->docker_registry_image_name}:{$this->docker_image_tag}-build";
|
||||||
$this->production_image_name = "{$this->application->docker_registry_image_name}:{$this->dockerImageTag}";
|
$this->production_image_name = "{$this->application->docker_registry_image_name}:{$this->docker_image_tag}";
|
||||||
} else {
|
} else {
|
||||||
$this->build_image_name = "{$this->application->uuid}:{$this->dockerImageTag}-build";
|
$this->build_image_name = "{$this->application->uuid}:{$this->docker_image_tag}-build";
|
||||||
$this->production_image_name = "{$this->application->uuid}:{$this->dockerImageTag}";
|
$this->production_image_name = "{$this->application->uuid}:{$this->docker_image_tag}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private function just_restart()
|
private function just_restart()
|
||||||
{
|
{
|
||||||
$this->application_deployment_queue->addLogEntry("Restarting {$this->customRepository}:{$this->application->git_branch} on {$this->server->name}.");
|
$this->application_deployment_queue->addLogEntry("Restarting {$this->custom_repository}:{$this->application->git_branch} on {$this->server->name}.");
|
||||||
$this->prepare_builder_image();
|
$this->prepare_builder_image();
|
||||||
$this->check_git_if_build_needed();
|
$this->check_git_if_build_needed();
|
||||||
$this->set_base_dir();
|
$this->set_base_dir();
|
||||||
@ -879,7 +879,7 @@ private function framework_based_notification()
|
|||||||
$nixpacks_php_fallback_path = $this->application->environment_variables_preview->where('key', 'NIXPACKS_PHP_FALLBACK_PATH')->first();
|
$nixpacks_php_fallback_path = $this->application->environment_variables_preview->where('key', 'NIXPACKS_PHP_FALLBACK_PATH')->first();
|
||||||
$nixpacks_php_root_dir = $this->application->environment_variables_preview->where('key', 'NIXPACKS_PHP_ROOT_DIR')->first();
|
$nixpacks_php_root_dir = $this->application->environment_variables_preview->where('key', 'NIXPACKS_PHP_ROOT_DIR')->first();
|
||||||
}
|
}
|
||||||
if ($nixpacks_php_fallback_path?->value === '/index.php' && $nixpacks_php_root_dir?->value === '/app/public' && $this->newVersionIsHealthy === false) {
|
if ($nixpacks_php_fallback_path?->value === '/index.php' && $nixpacks_php_root_dir?->value === '/app/public' && $this->is_new_version_healthy === false) {
|
||||||
$this->application_deployment_queue->addLogEntry("There was a change in how Laravel is deployed. Please update your environment variables to match the new deployment method. More details here: https://coolify.io/docs/resources/laravel", 'stderr');
|
$this->application_deployment_queue->addLogEntry("There was a change in how Laravel is deployed. Please update your environment variables to match the new deployment method. More details here: https://coolify.io/docs/resources/laravel", 'stderr');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -935,7 +935,7 @@ private function health_check()
|
|||||||
// Implement healthcheck for swarm
|
// Implement healthcheck for swarm
|
||||||
} else {
|
} else {
|
||||||
if ($this->application->isHealthcheckDisabled() && $this->application->custom_healthcheck_found === false) {
|
if ($this->application->isHealthcheckDisabled() && $this->application->custom_healthcheck_found === false) {
|
||||||
$this->newVersionIsHealthy = true;
|
$this->is_new_version_healthy = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($this->application->custom_healthcheck_found) {
|
if ($this->application->custom_healthcheck_found) {
|
||||||
@ -980,13 +980,13 @@ private function health_check()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'healthy') {
|
if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'healthy') {
|
||||||
$this->newVersionIsHealthy = true;
|
$this->is_new_version_healthy = true;
|
||||||
$this->application->update(['status' => 'running']);
|
$this->application->update(['status' => 'running']);
|
||||||
$this->application_deployment_queue->addLogEntry("New container is healthy.");
|
$this->application_deployment_queue->addLogEntry("New container is healthy.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'unhealthy') {
|
if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'unhealthy') {
|
||||||
$this->newVersionIsHealthy = false;
|
$this->is_new_version_healthy = false;
|
||||||
$this->query_logs();
|
$this->query_logs();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1025,9 +1025,9 @@ private function deploy_pull_request()
|
|||||||
if ($this->use_build_server) {
|
if ($this->use_build_server) {
|
||||||
$this->server = $this->build_server;
|
$this->server = $this->build_server;
|
||||||
}
|
}
|
||||||
$this->newVersionIsHealthy = true;
|
$this->is_new_version_healthy = true;
|
||||||
$this->generate_image_names();
|
$this->generate_image_names();
|
||||||
$this->application_deployment_queue->addLogEntry("Starting pull request (#{$this->pull_request_id}) deployment of {$this->customRepository}:{$this->application->git_branch}.");
|
$this->application_deployment_queue->addLogEntry("Starting pull request (#{$this->pull_request_id}) deployment of {$this->custom_repository}:{$this->application->git_branch}.");
|
||||||
$this->prepare_builder_image();
|
$this->prepare_builder_image();
|
||||||
$this->check_git_if_build_needed();
|
$this->check_git_if_build_needed();
|
||||||
$this->clone_repository();
|
$this->clone_repository();
|
||||||
@ -1079,16 +1079,16 @@ private function prepare_builder_image()
|
|||||||
{
|
{
|
||||||
$helperImage = config('coolify.helper_image');
|
$helperImage = config('coolify.helper_image');
|
||||||
// Get user home directory
|
// Get user home directory
|
||||||
$this->serverUserHomeDir = instant_remote_process(["echo \$HOME"], $this->server);
|
$this->server_user_home_dir = instant_remote_process(["echo \$HOME"], $this->server);
|
||||||
$this->dockerConfigFileExists = instant_remote_process(["test -f {$this->serverUserHomeDir}/.docker/config.json && echo 'OK' || echo 'NOK'"], $this->server);
|
$this->is_docker_config_file_exists = instant_remote_process(["test -f {$this->server_user_home_dir}/.docker/config.json && echo 'OK' || echo 'NOK'"], $this->server);
|
||||||
if ($this->use_build_server) {
|
if ($this->use_build_server) {
|
||||||
if ($this->dockerConfigFileExists === 'NOK') {
|
if ($this->is_docker_config_file_exists === 'NOK') {
|
||||||
throw new RuntimeException('Docker config file (~/.docker/config.json) not found on the build server. Please run "docker login" to login to the docker registry on the server.');
|
throw new RuntimeException('Docker config file (~/.docker/config.json) not found on the build server. Please run "docker login" to login to the docker registry on the server.');
|
||||||
}
|
}
|
||||||
$runCommand = "docker run -d --name {$this->deployment_uuid} --rm -v {$this->serverUserHomeDir}/.docker/config.json:/root/.docker/config.json:ro -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}";
|
$runCommand = "docker run -d --name {$this->deployment_uuid} --rm -v {$this->server_user_home_dir}/.docker/config.json:/root/.docker/config.json:ro -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}";
|
||||||
} else {
|
} else {
|
||||||
if ($this->dockerConfigFileExists === 'OK') {
|
if ($this->is_docker_config_file_exists === 'OK') {
|
||||||
$runCommand = "docker run -d --network {$this->destination->network} --name {$this->deployment_uuid} --rm -v {$this->serverUserHomeDir}/.docker/config.json:/root/.docker/config.json:ro -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}";
|
$runCommand = "docker run -d --network {$this->destination->network} --name {$this->deployment_uuid} --rm -v {$this->server_user_home_dir}/.docker/config.json:/root/.docker/config.json:ro -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}";
|
||||||
} else {
|
} else {
|
||||||
$runCommand = "docker run -d --network {$this->destination->network} --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}";
|
$runCommand = "docker run -d --network {$this->destination->network} --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}";
|
||||||
}
|
}
|
||||||
@ -1132,7 +1132,7 @@ private function deploy_to_additional_destinations()
|
|||||||
foreach ($destination_ids as $destination_id) {
|
foreach ($destination_ids as $destination_id) {
|
||||||
$destination = StandaloneDocker::find($destination_id);
|
$destination = StandaloneDocker::find($destination_id);
|
||||||
$server = $destination->server;
|
$server = $destination->server;
|
||||||
if ($server->team_id !== $this->mainServer->team_id) {
|
if ($server->team_id !== $this->main_server->team_id) {
|
||||||
$this->application_deployment_queue->addLogEntry("Skipping deployment to {$server->name}. Not in the same team?!");
|
$this->application_deployment_queue->addLogEntry("Skipping deployment to {$server->name}. Not in the same team?!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1195,7 +1195,7 @@ private function check_git_if_build_needed()
|
|||||||
executeInDocker($this->deployment_uuid, "chmod 600 /root/.ssh/id_rsa")
|
executeInDocker($this->deployment_uuid, "chmod 600 /root/.ssh/id_rsa")
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->customPort} -o Port={$this->customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git ls-remote {$this->fullRepoUrl} {$local_branch}"),
|
executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->custom_port} -o Port={$this->custom_port} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git ls-remote {$this->full_repository_url} {$local_branch}"),
|
||||||
"hidden" => true,
|
"hidden" => true,
|
||||||
"save" => "git_commit_sha"
|
"save" => "git_commit_sha"
|
||||||
],
|
],
|
||||||
@ -1203,7 +1203,7 @@ private function check_git_if_build_needed()
|
|||||||
} else {
|
} else {
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
[
|
[
|
||||||
executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->customPort} -o Port={$this->customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git ls-remote {$this->fullRepoUrl} {$local_branch}"),
|
executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->custom_port} -o Port={$this->custom_port} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git ls-remote {$this->full_repository_url} {$local_branch}"),
|
||||||
"hidden" => true,
|
"hidden" => true,
|
||||||
"save" => "git_commit_sha"
|
"save" => "git_commit_sha"
|
||||||
],
|
],
|
||||||
@ -1220,7 +1220,7 @@ private function clone_repository()
|
|||||||
{
|
{
|
||||||
$importCommands = $this->generate_git_import_commands();
|
$importCommands = $this->generate_git_import_commands();
|
||||||
$this->application_deployment_queue->addLogEntry("\n----------------------------------------");
|
$this->application_deployment_queue->addLogEntry("\n----------------------------------------");
|
||||||
$this->application_deployment_queue->addLogEntry("Importing {$this->customRepository}:{$this->application->git_branch} (commit sha {$this->application->git_commit_sha}) to {$this->basedir}.");
|
$this->application_deployment_queue->addLogEntry("Importing {$this->custom_repository}:{$this->application->git_branch} (commit sha {$this->application->git_commit_sha}) to {$this->basedir}.");
|
||||||
if ($this->pull_request_id !== 0) {
|
if ($this->pull_request_id !== 0) {
|
||||||
$this->application_deployment_queue->addLogEntry("Checking out tag pull/{$this->pull_request_id}/head.");
|
$this->application_deployment_queue->addLogEntry("Checking out tag pull/{$this->pull_request_id}/head.");
|
||||||
}
|
}
|
||||||
@ -1248,7 +1248,7 @@ private function clone_repository()
|
|||||||
|
|
||||||
private function generate_git_import_commands()
|
private function generate_git_import_commands()
|
||||||
{
|
{
|
||||||
['commands' => $commands, 'branch' => $this->branch, 'fullRepoUrl' => $this->fullRepoUrl] = $this->application->generateGitImportCommands(
|
['commands' => $commands, 'branch' => $this->branch, 'full_repository_url' => $this->full_repository_url] = $this->application->generateGitImportCommands(
|
||||||
deployment_uuid: $this->deployment_uuid,
|
deployment_uuid: $this->deployment_uuid,
|
||||||
pull_request_id: $this->pull_request_id,
|
pull_request_id: $this->pull_request_id,
|
||||||
git_type: $this->git_type,
|
git_type: $this->git_type,
|
||||||
@ -1755,10 +1755,10 @@ private function build_image()
|
|||||||
$this->execute_remote_command([executeInDocker($this->deployment_uuid, "rm /artifacts/thegameplan.json"), "hidden" => true]);
|
$this->execute_remote_command([executeInDocker($this->deployment_uuid, "rm /artifacts/thegameplan.json"), "hidden" => true]);
|
||||||
} else {
|
} else {
|
||||||
if ($this->force_rebuild) {
|
if ($this->force_rebuild) {
|
||||||
$build_command = "docker build --no-cache {$this->buildTarget} --network {$this->destination->network} -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}";
|
$build_command = "docker build --no-cache {$this->build_target} --network {$this->destination->network} -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}";
|
||||||
$base64_build_command = base64_encode($build_command);
|
$base64_build_command = base64_encode($build_command);
|
||||||
} else {
|
} else {
|
||||||
$build_command = "docker build {$this->buildTarget} --network {$this->destination->network} -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}";
|
$build_command = "docker build {$this->build_target} --network {$this->destination->network} -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}";
|
||||||
$base64_build_command = base64_encode($build_command);
|
$base64_build_command = base64_encode($build_command);
|
||||||
}
|
}
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
@ -1794,7 +1794,7 @@ private function build_image()
|
|||||||
}
|
}
|
||||||
}");
|
}");
|
||||||
}
|
}
|
||||||
$build_command = "docker build {$this->addHosts} --network host -f {$this->workdir}/Dockerfile {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
$build_command = "docker build {$this->add_hosts} --network host -f {$this->workdir}/Dockerfile {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
||||||
$base64_build_command = base64_encode($build_command);
|
$base64_build_command = base64_encode($build_command);
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
[
|
[
|
||||||
@ -1813,7 +1813,7 @@ private function build_image()
|
|||||||
} else {
|
} else {
|
||||||
// Pure Dockerfile based deployment
|
// Pure Dockerfile based deployment
|
||||||
if ($this->application->dockerfile) {
|
if ($this->application->dockerfile) {
|
||||||
$build_command = "docker build --pull {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
$build_command = "docker build --pull {$this->build_target} {$this->add_hosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
||||||
$base64_build_command = base64_encode($build_command);
|
$base64_build_command = base64_encode($build_command);
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
[
|
[
|
||||||
@ -1839,10 +1839,10 @@ private function build_image()
|
|||||||
$this->execute_remote_command([executeInDocker($this->deployment_uuid, "rm /artifacts/thegameplan.json"), "hidden" => true]);
|
$this->execute_remote_command([executeInDocker($this->deployment_uuid, "rm /artifacts/thegameplan.json"), "hidden" => true]);
|
||||||
} else {
|
} else {
|
||||||
if ($this->force_rebuild) {
|
if ($this->force_rebuild) {
|
||||||
$build_command = "docker build --no-cache {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
$build_command = "docker build --no-cache {$this->build_target} {$this->add_hosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
||||||
$base64_build_command = base64_encode($build_command);
|
$base64_build_command = base64_encode($build_command);
|
||||||
} else {
|
} else {
|
||||||
$build_command = "docker build {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
$build_command = "docker build {$this->build_target} {$this->add_hosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
|
||||||
$base64_build_command = base64_encode($build_command);
|
$base64_build_command = base64_encode($build_command);
|
||||||
}
|
}
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
@ -1862,7 +1862,7 @@ private function build_image()
|
|||||||
private function stop_running_container(bool $force = false)
|
private function stop_running_container(bool $force = false)
|
||||||
{
|
{
|
||||||
$this->application_deployment_queue->addLogEntry("Removing old containers.");
|
$this->application_deployment_queue->addLogEntry("Removing old containers.");
|
||||||
if ($this->newVersionIsHealthy || $force) {
|
if ($this->is_new_version_healthy || $force) {
|
||||||
$containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id);
|
$containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id);
|
||||||
if ($this->pull_request_id === 0) {
|
if ($this->pull_request_id === 0) {
|
||||||
$containers = $containers->filter(function ($container) {
|
$containers = $containers->filter(function ($container) {
|
||||||
|
Loading…
Reference in New Issue
Block a user