Skip to content

Commit

Permalink
feat: gzip enabled & stipprefix setting
Browse files Browse the repository at this point in the history
refactor: code
  • Loading branch information
andrasbacsai committed Mar 4, 2024
1 parent cee6b54 commit 8385bbb
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 62 deletions.
2 changes: 1 addition & 1 deletion app/Actions/Database/StartMariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function handle(StandaloneMariadb $database)
if (!is_null($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
if ($this->database->destination->server->is_log_drain_enabled() && $this->database->is_log_drain_enabled()) {
$docker_compose['services'][$container_name]['logging'] = [
'driver' => 'fluentd',
'options' => [
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Database/StartMongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function handle(StandaloneMongodb $database)
if (!is_null($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
if ($this->database->destination->server->is_log_drain_enabled() && $this->database->is_log_drain_enabled()) {
$docker_compose['services'][$container_name]['logging'] = [
'driver' => 'fluentd',
'options' => [
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Database/StartMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function handle(StandaloneMysql $database)
if (!is_null($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
if ($this->database->destination->server->is_log_drain_enabled() && $this->database->is_log_drain_enabled()) {
$docker_compose['services'][$container_name]['logging'] = [
'driver' => 'fluentd',
'options' => [
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Database/StartPostgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function handle(StandalonePostgresql $database)
if (!is_null($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
if ($this->database->destination->server->is_log_drain_enabled() && $this->database->is_log_drain_enabled()) {
ray('Log Drain Enabled');
$docker_compose['services'][$container_name]['logging'] = [
'driver' => 'fluentd',
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Database/StartRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function handle(StandaloneRedis $database)
if (!is_null($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
if ($this->database->destination->server->is_log_drain_enabled() && $this->database->is_log_drain_enabled()) {
$docker_compose['services'][$container_name]['logging'] = [
'driver' => 'fluentd',
'options' => [
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function check_resources($schedule)
// ray('dispatching container status job in ' . $randomSeconds . ' seconds');
// dispatch($job);
// })->name('container-status-' . $server->id)->everyMinute()->onOneServer();
if ($server->isLogDrainEnabled()) {
if ($server->is_log_drain_enabled()) {
$schedule->job(new CheckLogDrainContainerJob($server))->everyMinute()->onOneServer();
// $schedule
// ->call(function () use ($server) {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ private function generate_compose_file()
} else {
$docker_compose['services'][$this->container_name]['labels'] = $labels;
}
if ($this->server->isLogDrainEnabled() && $this->application->isLogDrainEnabled()) {
if ($this->server->is_log_drain_enabled() && $this->application->is_log_drain_enabled()) {
$docker_compose['services'][$this->container_name]['logging'] = [
'driver' => 'fluentd',
'options' => [
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/DatabaseBackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function handle(): void
private function backup_standalone_mongodb(string $databaseWithCollections): void
{
try {
$url = $this->database->getDbUrl(useInternal: true);
$url = $this->database->get_db_url(useInternal: true);
if ($databaseWithCollections === 'all') {
$commands[] = "mkdir -p " . $this->backup_dir;
$commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --gzip --archive > $this->backup_location";
Expand Down
18 changes: 16 additions & 2 deletions app/Livewire/Project/Application/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Advanced extends Component
{
public Application $application;
public bool $is_force_https_enabled;
public bool $is_gzip_enabled;
public bool $is_stripprefix_enabled;
protected $rules = [
'application.settings.is_git_submodules_enabled' => 'boolean|required',
'application.settings.is_git_lfs_enabled' => 'boolean|required',
Expand All @@ -19,18 +21,22 @@ class Advanced extends Component
'application.settings.is_gpu_enabled' => 'boolean|required',
'application.settings.is_build_server_enabled' => 'boolean|required',
'application.settings.is_consistent_container_name_enabled' => 'boolean|required',
'application.settings.is_gzip_enabled' => 'boolean|required',
'application.settings.is_stripprefix_enabled' => 'boolean|required',
'application.settings.gpu_driver' => 'string|required',
'application.settings.gpu_count' => 'string|required',
'application.settings.gpu_device_ids' => 'string|required',
'application.settings.gpu_options' => 'string|required',
];
public function mount() {
$this->is_force_https_enabled = $this->application->settings->is_force_https_enabled;
$this->is_gzip_enabled = $this->application->settings->is_gzip_enabled;
$this->is_stripprefix_enabled = $this->application->settings->is_stripprefix_enabled;
}
public function instantSave()
{
if ($this->application->isLogDrainEnabled()) {
if (!$this->application->destination->server->isLogDrainEnabled()) {
if ($this->application->is_log_drain_enabled()) {
if (!$this->application->destination->server->is_log_drain_enabled()) {
$this->application->settings->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on this server.');
return;
Expand All @@ -40,6 +46,14 @@ public function instantSave()
$this->application->settings->is_force_https_enabled = $this->is_force_https_enabled;
$this->dispatch('resetDefaultLabels', false);
}
if ($this->application->settings->is_gzip_enabled !== $this->is_gzip_enabled) {
$this->application->settings->is_gzip_enabled = $this->is_gzip_enabled;
$this->dispatch('resetDefaultLabels', false);
}
if ($this->application->settings->is_stripprefix_enabled !== $this->is_stripprefix_enabled) {
$this->application->settings->is_stripprefix_enabled = $this->is_stripprefix_enabled;
$this->dispatch('resetDefaultLabels', false);
}
$this->application->settings->save();
$this->dispatch('success', 'Settings saved.');
}
Expand Down
8 changes: 4 additions & 4 deletions app/Livewire/Project/Database/Mariadb/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class General extends Component

public function mount()
{
$this->db_url = $this->database->getDbUrl(true);
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
}
}
public function instantSaveAdvanced() {
try {
if (!$this->database->destination->server->isLogDrainEnabled()) {
if (!$this->database->destination->server->is_log_drain_enabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand Down Expand Up @@ -93,7 +93,7 @@ public function instantSave()
return;
}
StartDatabaseProxy::run($this->database);
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
$this->dispatch('success', 'Database is now publicly accessible.');
} else {
StopDatabaseProxy::run($this->database);
Expand Down
8 changes: 4 additions & 4 deletions app/Livewire/Project/Database/Mongodb/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class General extends Component

public function mount()
{
$this->db_url = $this->database->getDbUrl(true);
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
}
}
public function instantSaveAdvanced()
{
try {
if (!$this->database->destination->server->isLogDrainEnabled()) {
if (!$this->database->destination->server->is_log_drain_enabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function instantSave()
return;
}
StartDatabaseProxy::run($this->database);
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
$this->dispatch('success', 'Database is now publicly accessible.');
} else {
StopDatabaseProxy::run($this->database);
Expand Down
8 changes: 4 additions & 4 deletions app/Livewire/Project/Database/Mysql/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class General extends Component

public function mount()
{
$this->db_url = $this->database->getDbUrl(true);
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
}
}
public function instantSaveAdvanced()
{
try {
if (!$this->database->destination->server->isLogDrainEnabled()) {
if (!$this->database->destination->server->is_log_drain_enabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand Down Expand Up @@ -94,7 +94,7 @@ public function instantSave()
return;
}
StartDatabaseProxy::run($this->database);
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
$this->dispatch('success', 'Database is now publicly accessible.');
} else {
StopDatabaseProxy::run($this->database);
Expand Down
8 changes: 4 additions & 4 deletions app/Livewire/Project/Database/Postgresql/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class General extends Component
];
public function mount()
{
$this->db_url = $this->database->getDbUrl(true);
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
}
}
public function instantSaveAdvanced() {
try {
if (!$this->database->destination->server->isLogDrainEnabled()) {
if (!$this->database->destination->server->is_log_drain_enabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand All @@ -87,7 +87,7 @@ public function instantSave()
return;
}
StartDatabaseProxy::run($this->database);
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
$this->dispatch('success', 'Database is now publicly accessible.');
} else {
StopDatabaseProxy::run($this->database);
Expand Down
8 changes: 4 additions & 4 deletions app/Livewire/Project/Database/Redis/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class General extends Component
];
public function mount()
{
$this->db_url = $this->database->getDbUrl(true);
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
}
}
public function instantSaveAdvanced() {
try {
if (!$this->database->destination->server->isLogDrainEnabled()) {
if (!$this->database->destination->server->is_log_drain_enabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand Down Expand Up @@ -86,7 +86,7 @@ public function instantSave()
return;
}
StartDatabaseProxy::run($this->database);
$this->db_url_public = $this->database->getDbUrl();
$this->db_url_public = $this->database->get_db_url();
$this->dispatch('success', 'Database is now publicly accessible.');
} else {
StopDatabaseProxy::run($this->database);
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Service/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function mount()
}
public function instantSaveAdvanced()
{
if (!$this->database->service->destination->server->isLogDrainEnabled()) {
if (!$this->database->service->destination->server->is_log_drain_enabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand Down
3 changes: 2 additions & 1 deletion app/Livewire/Project/Service/ServiceApplicationView.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ServiceApplicationView extends Component
'application.required_fqdn' => 'required|boolean',
'application.is_log_drain_enabled' => 'nullable|boolean',
'application.is_gzip_enabled' => 'nullable|boolean',
'application.is_stripprefix_enabled' => 'nullable|boolean',
];
public function render()
{
Expand All @@ -29,7 +30,7 @@ public function instantSave()
}
public function instantSaveAdvanced()
{
if (!$this->application->service->destination->server->isLogDrainEnabled()) {
if (!$this->application->service->destination->server->is_log_drain_enabled()) {
$this->application->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Server/LogDrains.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function configureLogDrain()
{
try {
InstallLogDrain::run($this->server);
if (!$this->server->isLogDrainEnabled()) {
if (!$this->server->is_log_drain_enabled()) {
$this->dispatch('serverRefresh');
$this->dispatch('success', 'Log drain service stopped.');
return;
Expand Down
14 changes: 13 additions & 1 deletion app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public function is_github_based(): bool
}
return false;
}
public function is_force_https_enabled()
{
return data_get($this, 'settings.is_force_https_enabled', false);
}
public function is_stripprefix_enabled()
{
return data_get($this, 'settings.is_stripprefix_enabled', true);
}
public function is_gzip_enabled()
{
return data_get($this, 'settings.is_gzip_enabled', true);
}
public function link()
{
if (data_get($this, 'environment.project.uuid')) {
Expand Down Expand Up @@ -481,7 +493,7 @@ public function workdir()
{
return application_configuration_dir() . "/{$this->uuid}";
}
public function isLogDrainEnabled()
public function is_log_drain_enabled()
{
return data_get($this, 'settings.is_log_drain_enabled', false);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function isFunctional()
{
return $this->settings->is_reachable && $this->settings->is_usable && !$this->settings->force_disabled;
}
public function isLogDrainEnabled()
public function is_log_drain_enabled()
{
return $this->settings->is_logdrain_newrelic_enabled || $this->settings->is_logdrain_highlight_enabled || $this->settings->is_logdrain_axiom_enabled || $this->settings->is_logdrain_custom_enabled;
}
Expand Down
8 changes: 6 additions & 2 deletions app/Models/ServiceApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ protected static function booted()
$service->fileStorages()->delete();
});
}
public function isLogDrainEnabled()
public function is_log_drain_enabled()
{
return data_get($this, 'is_log_drain_enabled', false);
}
public function isGzipEnabled()
public function is_stripprefix_enabled()
{
return data_get($this, 'is_stripprefix_enabled', true);
}
public function is_gzip_enabled()
{
return data_get($this, 'is_gzip_enabled', true);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/ServiceDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ protected static function booted()
$service->fileStorages()->delete();
});
}
public function isLogDrainEnabled()
public function is_log_drain_enabled()
{
return data_get($this, 'is_log_drain_enabled', false);
}
public function isGzipEnabled()
public function is_gzip_enabled()
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/StandaloneMariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function link()
}
return null;
}
public function isLogDrainEnabled()
public function is_log_drain_enabled()
{
return data_get($this, 'is_log_drain_enabled', false);
}
Expand All @@ -126,7 +126,7 @@ public function portsMappingsArray(): Attribute
);
}

public function getDbUrl(bool $useInternal = false): string
public function get_db_url(bool $useInternal = false): string
{
if ($this->is_public && !$useInternal) {
return "mysql://{$this->mariadb_user}:{$this->mariadb_password}@{$this->destination->server->getIp}:{$this->public_port}/{$this->mariadb_database}";
Expand Down
4 changes: 2 additions & 2 deletions app/Models/StandaloneMongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function team()
{
return data_get($this, 'environment.project.team');
}
public function isLogDrainEnabled()
public function is_log_drain_enabled()
{
return data_get($this, 'is_log_drain_enabled', false);
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public function type(): string
{
return 'standalone-mongodb';
}
public function getDbUrl(bool $useInternal = false)
public function get_db_url(bool $useInternal = false)
{
if ($this->is_public && !$useInternal) {
return "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true";
Expand Down
Loading

0 comments on commit 8385bbb

Please sign in to comment.