Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 26, 2024
1 parent e20fe34 commit 234ac29
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions web/app/Filament/Enums/ServerApplicationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum ServerApplicationType: string implements HasLabel, HasDescriptions, HasIcon
case APACHE_NODEJS = 'apache_nodejs';
case APACHE_PYTHON = 'apache_python';
case APACHE_RUBY = 'apache_ruby';
case APACHE_DOCKER = 'apache_docker';

public function getLabel(): ?string
{
Expand All @@ -20,6 +21,7 @@ public function getLabel(): ?string
self::APACHE_NODEJS => 'Apache + Node.js (Passenger)',
self::APACHE_PYTHON => 'Apache + Python (Passenger)',
self::APACHE_RUBY => 'Apache + Ruby (Passenger)',
self::APACHE_DOCKER => 'Docker',
};
}

Expand All @@ -30,6 +32,7 @@ public function getDescriptions(): ?string
self::APACHE_NODEJS => 'Install applications like Ghost, KeystoneJS, and more.',
self::APACHE_PYTHON => 'Install applications like Django, Flask, and more.',
self::APACHE_RUBY => 'Install applications like Ruby on Rails, Sinatra, and more.',
self::APACHE_DOCKER => 'Run your own Docker containers.',
};
}

Expand All @@ -40,6 +43,7 @@ public function getIcons(): ?string
self::APACHE_NODEJS => 'phyre-nodejs',
self::APACHE_PYTHON => 'phyre-python',
self::APACHE_RUBY => 'phyre-ruby',
self::APACHE_DOCKER => 'docker-logo',
};
}
}
24 changes: 22 additions & 2 deletions web/app/Filament/Resources/DomainResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use JaOcero\RadioDeck\Forms\Components\RadioDeck;
use Modules\Docker\App\Models\DockerContainer;

class DomainResource extends Resource
{
Expand All @@ -33,8 +34,17 @@ public static function form(Form $form): Form
{
$hostingSubscriptions = [];
$getHostingSubscriptions = \App\Models\HostingSubscription::all();
foreach ($getHostingSubscriptions as $hostingSubscription) {
$hostingSubscriptions[$hostingSubscription->id] = $hostingSubscription->domain . ' - '.$hostingSubscription->customer->name;
if (!$getHostingSubscriptions) {
foreach ($getHostingSubscriptions as $hostingSubscription) {
$hostingSubscriptions[$hostingSubscription->id] = $hostingSubscription->domain . ' - ' . $hostingSubscription->customer->name;
}
}
$dockerContainers = [];
$getDockerContainers = DockerContainer::all();
if ($getDockerContainers) {
foreach ($getDockerContainers as $dockerContainer) {
$dockerContainers[$dockerContainer->id] = $dockerContainer->name;
}
}

return $form
Expand Down Expand Up @@ -125,6 +135,16 @@ public static function form(Form $form): Form
->options(SupportedApplicationTypes::getRubyVersions())
->columns(6)
->required(),

Select::make('server_application_settings.docker_container_id')
->hidden(function (Get $get) {
return $get('server_application_type') !== 'apache_docker';
})
->label('Docker Contaier')
->options($dockerContainers)
->columns(5)
->required(),

]),
Tabs\Tab::make('Git')
->schema([
Expand Down
14 changes: 14 additions & 0 deletions web/app/Models/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\ShellApi;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Modules\Docker\App\Models\DockerContainer;

class Domain extends Model
{
Expand Down Expand Up @@ -273,8 +274,21 @@ public function configureVirtualHost()
}

}
if ($this->server_application_type == 'apache_docker') {
if (isset($this->server_application_settings['docker_container_id'])) {
$findDockerContainer = DockerContainer::where('id', $this->server_application_settings['docker_container_id'])
->first();
if ($findDockerContainer) {
$apacheVirtualHostBuilder->setProxyPass('http://127.0.0.1:'.$findDockerContainer->external_port);
$apacheVirtualHostBuilder->setAppType('docker');
$apacheVirtualHostBuilder->setAppVersion($appVersion);
}
}
}

$apacheBaseConfig = $apacheVirtualHostBuilder->buildConfig();

dd($apacheBaseConfig);
if (!empty($apacheBaseConfig)) {
file_put_contents('/etc/apache2/sites-available/'.$this->domain.'.conf', $apacheBaseConfig);

Expand Down
8 changes: 8 additions & 0 deletions web/app/VirtualHosts/ApacheVirtualHostBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ApacheVirtualHostBuilder

public $serverAdmin = null;

public $proxyPass = null;

public function setPort($port)
{
$this->port = $port;
Expand Down Expand Up @@ -124,6 +126,11 @@ public function setServerAdmin($email)
$this->serverAdmin = $email;
}

public function setProxyPass($proxyPass)
{
$this->proxyPass = $proxyPass;
}

public function buildConfig()
{
$settings = [
Expand All @@ -145,6 +152,7 @@ public function buildConfig()
'passengerAppRoot' => $this->passengerAppRoot,
'passengerAppType' => $this->passengerAppType,
'passengerStartupFile' => $this->passengerStartupFile,
'proxyPass' => $this->proxyPass,
];

$apacheVirtualHostConfigs = app()->virtualHostManager->getConfigs($this->additionalServices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@

@endif

@if (!empty($proxyPass))

ProxyPass / {{$proxyPass}}

@endif

<Directory {{$domainPublic}}>

Options Indexes FollowSymLinks MultiViews @if($appType == 'php') Includes ExecCGI @endif
Expand Down

0 comments on commit 234ac29

Please sign in to comment.