Skip to content

Commit

Permalink
Merge pull request coollabsio#3457 from coollabsio/next
Browse files Browse the repository at this point in the history
v4.0.0-beta.337
  • Loading branch information
andrasbacsai authored Sep 16, 2024
2 parents 0c4ce55 + 7b4559c commit b2bab45
Show file tree
Hide file tree
Showing 24 changed files with 154 additions and 95 deletions.
4 changes: 2 additions & 2 deletions app/Actions/Service/StartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function handle(Service $service)
$service->saveComposeConfigs();
$commands[] = 'cd '.$service->workdir();
$commands[] = "echo 'Saved configuration files to {$service->workdir()}.'";
if($service->networks()->count() > 0){
if ($service->networks()->count() > 0) {
$commands[] = "echo 'Creating Docker network.'";
$commands[] = "docker network inspect $service->uuid >/dev/null 2>&1 || docker network create --attachable $service->uuid";
}
Expand All @@ -31,7 +31,7 @@ public function handle(Service $service)
$network = $service->destination->network;
$serviceNames = data_get(Yaml::parse($compose), 'services', []);
foreach ($serviceNames as $serviceName => $serviceConfig) {
$commands[] = "docker network connect --alias {$serviceName}-{$service->uuid} $network {$serviceName}-{$service->uuid} || true";
$commands[] = "docker network connect --alias {$serviceName}-{$service->uuid} $network {$serviceName}-{$service->uuid} >/dev/null 2>&1 || true";
}
}
$activity = remote_process($commands, $service->server, type_uuid: $service->uuid, callEventOnFinish: 'ServiceStatusChanged');
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private function deploy_docker_compose_buildpack()
'hidden' => true,
'ignore_errors' => true,
], [
"docker network connect {$networkId} coolify-proxy || true",
"docker network connect {$networkId} coolify-proxy >/dev/null 2>&1 || true",
'hidden' => true,
'ignore_errors' => true,
]);
Expand Down
72 changes: 40 additions & 32 deletions app/Livewire/Project/Shared/ExecuteContainerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ExecuteContainerCommand extends Component
{
public string $container;
public $container;

public Collection $containers;

Expand Down Expand Up @@ -57,24 +57,13 @@ public function mount()
if ($this->resource->destination->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->destination->server);
}
$this->container = $this->resource->uuid;
$this->containers->push($this->container);
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource->applications()->get()->each(function ($application) {
$this->containers->push(data_get($application, 'name').'-'.data_get($this->resource, 'uuid'));
});
$this->resource->databases()->get()->each(function ($database) {
$this->containers->push(data_get($database, 'name').'-'.data_get($this->resource, 'uuid'));
});
if ($this->resource->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->server);
}
}
if ($this->containers->count() > 0) {
$this->container = $this->containers->first();
}
}

public function loadContainers()
Expand All @@ -97,37 +86,56 @@ public function loadContainers()
];
$this->containers = $this->containers->push($payload);
}
}
}
if ($this->containers->count() > 0) {
if (data_get($this->parameters, 'application_uuid')) {
$this->container = data_get($this->containers->first(), 'container.Names');
} elseif (data_get($this->parameters, 'database_uuid')) {
$this->container = $this->containers->first();
if ($this->resource->isRunning()) {
$this->containers = $this->containers->push([
'server' => $server,
'container' => [
'Names' => $this->resource->uuid,
],
]);
}
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->container = $this->containers->first();
}
if ($this->containers->count() === 1) {
$this->dispatch('connectToContainer');
$this->resource->applications()->get()->each(function ($application) {
ray($application);
if ($application->isRunning()) {
$this->containers->push([
'server' => $this->resource->server,
'container' => [
'Names' => data_get($application, 'name').'-'.data_get($this->resource, 'uuid'),
],
]);
}
});
$this->resource->databases()->get()->each(function ($database) {
if ($database->isRunning()) {
$this->containers->push([
'server' => $this->resource->server,
'container' => [
'Names' => data_get($database, 'name').'-'.data_get($this->resource, 'uuid'),
],
]);
}
});
}

}
if ($this->containers->count() > 0) {
$this->container = $this->containers->first();
}
}

#[On('connectToContainer')]
public function connectToContainer()
{
try {
if (data_get($this->parameters, 'application_uuid')) {
$container = $this->containers->where('container.Names', $this->container)->first();
$container_name = data_get($container, 'container.Names');
if (is_null($container)) {
throw new \RuntimeException('Container not found.');
}
$server = data_get($container, 'server');
} else {
$container_name = $this->container;
$server = $this->servers->first();
$container_name = data_get($this->container, 'container.Names');
ray($this->container);
if (is_null($container_name)) {
throw new \RuntimeException('Container not found.');
}
$server = data_get($this->container, 'server');

if ($server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Shared/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function sendTerminalCommand($isContainer, $identifier, $serverUuid)
if ($isContainer) {
$status = getContainerStatus($server, $identifier);
if ($status !== 'running') {
return handleError(new \Exception('Container is not running'), $this);
return;
}
$command = generateSshCommand($server, "docker exec -it {$identifier} sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'");
} else {
Expand Down
10 changes: 10 additions & 0 deletions app/Models/ServiceApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public static function ownedByCurrentTeamAPI(int $teamId)
return ServiceApplication::whereRelation('service.environment.project.team', 'id', $teamId)->orderBy('name');
}

public function isRunning()
{
return str($this->status)->contains('running');
}

public function isExited()
{
return str($this->status)->contains('exited');
}

public function isLogDrainEnabled()
{
return data_get($this, 'is_log_drain_enabled', false);
Expand Down
10 changes: 10 additions & 0 deletions app/Models/ServiceDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public function restart()
remote_process(["docker restart {$container_id}"], $this->service->server);
}

public function isRunning()
{
return str($this->status)->contains('running');
}

public function isExited()
{
return str($this->status)->contains('exited');
}

public function isLogDrainEnabled()
{
return data_get($this, 'is_log_drain_enabled', false);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneClickhouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneDragonfly.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneKeydb.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneMariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneMongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandalonePostgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
5 changes: 5 additions & 0 deletions app/Models/StandaloneRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public function isConfigurationChanged(bool $save = false)
}
}

public function isRunning()
{
return (bool) str($this->status)->contains('running');
}

public function isExited()
{
return (bool) str($this->status)->startsWith('exited');
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/helpers/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ function generateServiceSpecificFqdns(ServiceApplication|Application $resource)
}
if (is_null($MINIO_BROWSER_REDIRECT_URL?->value)) {
$MINIO_BROWSER_REDIRECT_URL?->update([
'value' => generateFqdn($server, 'console-'.$uuid),
'value' => generateFqdn($server, 'console-'.$uuid, true),
]);
}
if (is_null($MINIO_SERVER_URL?->value)) {
$MINIO_SERVER_URL?->update([
'value' => generateFqdn($server, 'minio-'.$uuid),
'value' => generateFqdn($server, 'minio-'.$uuid, true),
]);
}
$payload = collect([
Expand Down
5 changes: 4 additions & 1 deletion bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ function data_get_str($data, $key, $default = null): Stringable
return str($str);
}

function generateFqdn(Server $server, string $random): string
function generateFqdn(Server $server, string $random, bool $forceHttps = false): string
{
$wildcard = data_get($server, 'settings.wildcard_domain');
if (is_null($wildcard) || $wildcard === '') {
Expand All @@ -488,6 +488,9 @@ function generateFqdn(Server $server, string $random): string
$host = $url->getHost();
$path = $url->getPath() === '/' ? '' : $url->getPath();
$scheme = $url->getScheme();
if ($forceHttps) {
$scheme = 'https';
}
$finalFqdn = "$scheme://{$random}.$host$path";

return $finalFqdn;
Expand Down
2 changes: 1 addition & 1 deletion config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
'release' => '4.0.0-beta.336',
'release' => '4.0.0-beta.337',
// When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'),

Expand Down
2 changes: 1 addition & 1 deletion config/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

return '4.0.0-beta.336';
return '4.0.0-beta.337';
24 changes: 12 additions & 12 deletions other/nightly/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -e # Exit immediately if a command exits with a non-zero status
## $1 could be empty, so we need to disable this check
#set -u # Treat unset variables as an error and exit
set -o pipefail # Cause a pipeline to return the status of the last command that exited with a non-zero status
CDN="https://cdn.coollabs.io/coolify-nightly"
DATE=$(date +"%Y%m%d-%H%M%S")

VERSION="1.5"
Expand All @@ -21,7 +22,13 @@ INSTALLATION_LOG_WITH_DATE="/data/coolify/source/installation-${DATE}.log"

exec > >(tee -a $INSTALLATION_LOG_WITH_DATE) 2>&1

CDN="https://cdn.coollabs.io/coolify-nightly"
getAJoke() {
JOKES=$(curl -s --max-time 2 https://v2.jokeapi.dev/joke/Programming?format=txt&type=single&amount=1 || true)
if [ "$JOKES" != "" ]; then
echo -e " - Until then, here's a joke for you:\n"
echo -e "$JOKES\n"
fi
}
OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"')
ENV_FILE="/data/coolify/source/.env"

Expand Down Expand Up @@ -202,6 +209,7 @@ fi
echo -e "3. Check Docker Installation. "
if ! [ -x "$(command -v docker)" ]; then
echo " - Docker is not installed. Installing Docker. It may take a while."
getAJoke
case "$OS_TYPE" in
"almalinux")
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo >/dev/null 2>&1
Expand Down Expand Up @@ -477,22 +485,14 @@ chmod -R 700 /data/coolify
echo -e "9. Installing Coolify ($LATEST_VERSION)"
echo -e " - It could take a while based on your server's performance, network speed, stars, etc."
echo -e " - Please wait."
JOKES=$(curl -s https://v2.jokeapi.dev/joke/Programming?format=txt&type=single&amount=1 || true)
if [ "$JOKES" != "" ]; then
echo -e " - Until then, here's a joke for you:\n"
echo -e "$JOKES\n"
fi
getAJoke

bash /data/coolify/source/upgrade.sh "${LATEST_VERSION:-latest}" "${LATEST_HELPER_VERSION:-latest}" >/dev/null 2>&1
echo " - Coolify installed successfully."
rm -f $ENV_FILE-$DATE

echo " - Waiting for 20 seconds for Coolify (database migrations) to be ready."
JOKES=$(curl -s https://v2.jokeapi.dev/joke/Programming?format=txt&type=single&amount=1 || true)
if [ "$JOKES" != "" ]; then
echo -e " - Until then, here's a joke for you:\n"
echo -e "$JOKES\n"
fi
getAJoke

sleep 20
echo -e "\033[0;35m
Expand All @@ -505,5 +505,5 @@ echo -e "\033[0;35m
\033[0m"
echo -e "\nYour instance is ready to use."
echo -e "Please visit http://$(curl -4s https://ifconfig.io):8000 to get started.\n"
echo -e "WARNING: We recommend you backup your /data/coolify/source/.env file to a safe location, outside of this server."
echo -e "WARNING: We recommend you to backup your /data/coolify/source/.env file to a safe location, outside of this server."
cp /data/coolify/source/.env /data/coolify/source/.env.backup
Loading

0 comments on commit b2bab45

Please sign in to comment.