Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: add dockerfile location

Andras Bacsai0be8ffbdc943
diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php
index 93fcd250b8..afe1b62dd8 100644
--- a/app/Http/Livewire/Project/Application/General.php
+++ b/app/Http/Livewire/Project/Application/General.php
@@ -51,6 +51,7 @@ class General extends Component
'application.dockerfile' => 'nullable',
'application.docker_registry_image_name' => 'nullable',
'application.docker_registry_image_tag' => 'nullable',
+ 'application.dockerfile_location' => 'nullable',
];
protected $validationAttributes = [
'application.name' => 'name',
@@ -71,6 +72,7 @@ class General extends Component
'application.dockerfile' => 'Dockerfile',
'application.docker_registry_image_name' => 'Docker registry image name',
'application.docker_registry_image_tag' => 'Docker registry image tag',
+ 'application.dockerfile_location' => 'Dockerfile location',
];
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index a1dff9c93b..f4b839ec31 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -57,6 +57,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
private string|null $currently_running_container_name = null;
private string $basedir;
private string $workdir;
+ private ?string $build_pack = null;
private string $configuration_dir;
private string $build_image_name;
private string $production_image_name;
@@ -65,6 +66,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
private $env_args;
private $docker_compose;
private $docker_compose_base64;
+ private string $dockerfile_location = '/Dockerfile';
private $log_model;
private Collection $saved_outputs;
@@ -76,6 +78,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$this->application_deployment_queue = ApplicationDeploymentQueue::find($application_deployment_queue_id);
$this->log_model = $this->application_deployment_queue;
$this->application = Application::find($this->application_deployment_queue->application_id);
+ $this->build_pack = data_get($this->application, 'build_pack');
$this->application_deployment_queue_id = $application_deployment_queue_id;
$this->deployment_uuid = $this->application_deployment_queue->deployment_uuid;
@@ -140,6 +143,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$this->deploy_simple_dockerfile();
} else if ($this->application->build_pack === 'dockerimage') {
$this->deploy_dockerimage();
+ } else if ($this->application->build_pack === 'dockerfile') {
+ $this->deploy_dockerfile();
} else {
if ($this->pull_request_id !== 0) {
$this->deploy_pull_request();
@@ -178,6 +183,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
);
}
}
+
private function deploy_docker_compose()
{
$dockercompose_base64 = base64_encode($this->application->dockercompose);
@@ -265,6 +271,35 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$this->generate_compose_file();
$this->rolling_update();
}
+
+ private function deploy_dockerfile()
+ {
+ if (data_get($this->application, 'dockerfile_location')) {
+ $this->dockerfile_location = $this->application->dockerfile_location;
+ }
+ $this->execute_remote_command(
+ [
+ "echo 'Starting deployment of {$this->application->git_repository}:{$this->application->git_branch}.'"
+ ],
+ );
+ $this->prepare_builder_image();
+ $this->clone_repository();
+ $this->set_base_dir();
+ $tag = Str::of("{$this->commit}-{$this->application->id}-{$this->pull_request_id}");
+ if (strlen($tag) > 128) {
+ $tag = $tag->substr(0, 128);
+ }
+
+ $this->build_image_name = Str::lower("{$this->application->git_repository}:{$tag}-build");
+ $this->production_image_name = Str::lower("{$this->application->uuid}:{$tag}");
+ // ray('Build Image Name: ' . $this->build_image_name . ' & Production Image Name: ' . $this->production_image_name)->green();
+ $this->cleanup_git();
+ $this->generate_compose_file();
+ $this->generate_build_env_variables();
+ $this->add_build_env_variables_to_dockerfile();
+ // $this->build_image();
+ $this->rolling_update();
+ }
private function deploy()
{
$this->execute_remote_command(
@@ -629,6 +664,12 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
if (count($volume_names) > 0) {
$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,
+ ];
+ }
$this->docker_compose = Yaml::dump($docker_compose, 10);
$this->docker_compose_base64 = base64_encode($this->docker_compose);
$this->execute_remote_command([executeInDocker($this->deployment_uuid, "echo '{$this->docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml"), "hidden" => true]);
@@ -785,7 +826,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
{
$this->execute_remote_command(
["echo -n 'Starting application (could take a while).'"],
- [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up -d >/dev/null"), "hidden" => true],
+ [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up --build -d >/dev/null"), "hidden" => true],
);
}
diff --git a/app/Models/Application.php b/app/Models/Application.php
index cd3b43e052..634569c0fe 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -101,7 +101,21 @@ class Application extends BaseModel
}
);
}
-
+ public function dockerfileLocation(): Attribute
+ {
+ return Attribute::make(
+ set: function ($value) {
+ if (is_null($value) || $value === '') {
+ return '/Dockerfile';
+ } else {
+ if ($value !== '/') {
+ return Str::start(Str::replaceEnd('/', '', $value), '/');
+ }
+ return Str::start($value, '/');
+ }
+ }
+ );
+ }
public function baseDirectory(): Attribute
{
return Attribute::make(
@@ -259,14 +273,14 @@ class Application extends BaseModel
if ($this->dockerfile) {
return false;
}
- if ($this->build_pack === 'dockerimage'){
+ if ($this->build_pack === 'dockerimage') {
return false;
}
return true;
}
public function isHealthcheckDisabled(): bool
{
- if (data_get($this, 'dockerfile') || data_get($this, 'build_pack') === 'dockerfile' || data_get($this, 'health_check_enabled') === false) {
+ if (data_get($this, 'health_check_enabled') === false) {
return true;
}
return false;
diff --git a/database/migrations/2023_10_10_113144_add_dockerfile_location_applications_table.php b/database/migrations/2023_10_10_113144_add_dockerfile_location_applications_table.php
new file mode 100644
index 0000000000..39956a9edb
--- /dev/null
+++ b/database/migrations/2023_10_10_113144_add_dockerfile_location_applications_table.php
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('applications', function (Blueprint $table) {
+ $table->string('dockerfile_location')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('applications', function (Blueprint $table) {
+ $table->dropColumn('dockerfile_location');
+ });
+ }
+};
diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php
index 89c748aedc..4492c81924 100644
--- a/resources/views/livewire/project/application/general.blade.php
+++ b/resources/views/livewire/project/application/general.blade.php
@@ -56,6 +56,11 @@
<div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input placeholder="/" id="application.base_directory" label="Base Directory"
helper="Directory to use as root. Useful for monorepos." />
+ @if ($application->build_pack === 'dockerfile')
+ <x-forms.input placeholder="/Dockerfile" id="application.dockerfile_location"
+ label="Dockerfile Location"
+ helper="It is calculated together with the Base Directory: {{ Str::start($application->base_directory . $application->dockerfile_location, '/') }}" />
+ @endif
@if ($application->could_set_build_commands())
@if ($application->settings->is_static)
<x-forms.input placeholder="/dist" id="application.publish_directory"