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 cloudflare tunnel support

Andras Bacsaic46eeac4b5a1
diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php
index 9794610fed..029d029a3e 100644
--- a/app/Http/Livewire/Server/Form.php
+++ b/app/Http/Livewire/Server/Form.php
@@ -23,6 +23,7 @@ class Form extends Component
'server.ip' => 'required',
'server.user' => 'required',
'server.port' => 'required',
+ 'server.settings.is_cloudflare_tunnel' => 'required',
'server.settings.is_reachable' => 'required',
'server.settings.is_part_of_swarm' => 'required',
'wildcard_domain' => 'nullable|url',
@@ -33,6 +34,7 @@ class Form extends Component
'server.ip' => 'ip',
'server.user' => 'user',
'server.port' => 'port',
+ 'server.settings.is_cloudflare_tunnel' => 'Cloudflare Tunnel',
'server.settings.is_reachable' => 'is reachable',
'server.settings.is_part_of_swarm' => 'is part of swarm'
];
@@ -42,7 +44,9 @@ class Form extends Component
$this->wildcard_domain = $this->server->settings->wildcard_domain;
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
}
-
+ public function instantSave() {
+ $this->server->settings->save();
+ }
public function installDocker()
{
$this->dockerInstallationStarted = true;
diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php
index 706be1e1bd..f1efe397e5 100644
--- a/bootstrap/helpers/remoteProcess.php
+++ b/bootstrap/helpers/remoteProcess.php
@@ -85,6 +85,9 @@ function generateSshCommand(Server $server, string $command, bool $isMux = true)
if ($isMux && config('coolify.mux_enabled')) {
$ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/ssh/mux/%h_%p_%r ';
}
+ if (data_get($server,'settings.is_cloudflare_tunnel')) {
+ $ssh_command .= '-o ProxyCommand="/usr/local/bin/cloudflared access ssh --hostname %h" ';
+ }
$command = "PATH=\$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/host/usr/local/sbin:/host/usr/local/bin:/host/usr/sbin:/host/usr/bin:/host/sbin:/host/bin && $command";
$ssh_command .= "-i {$privateKeyLocation} "
. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
@@ -98,7 +101,7 @@ function generateSshCommand(Server $server, string $command, bool $isMux = true)
. " 'bash -se' << \\$delimiter" . PHP_EOL
. $command . PHP_EOL
. $delimiter;
- // ray($ssh_command);
+ ray($ssh_command);
return $ssh_command;
}
function instant_remote_process(Collection|array $command, Server $server, $throwError = true)
diff --git a/database/migrations/2023_09_23_111808_update_servers_with_cloudflared.php b/database/migrations/2023_09_23_111808_update_servers_with_cloudflared.php
new file mode 100644
index 0000000000..c2609d4142
--- /dev/null
+++ b/database/migrations/2023_09_23_111808_update_servers_with_cloudflared.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('server_settings', function (Blueprint $table) {
+ $table->boolean('is_cloudflare_tunnel')->default(false);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('server_settings', function (Blueprint $table) {
+ $table->dropColumn('is_cloudflare_tunnel');
+ });
+ }
+};
diff --git a/docker/coolify-helper/Dockerfile b/docker/coolify-helper/Dockerfile
index 45834de787..5ff46888bb 100644
--- a/docker/coolify-helper/Dockerfile
+++ b/docker/coolify-helper/Dockerfile
@@ -10,7 +10,7 @@ ARG DOCKER_BUILDX_VERSION=0.11.2
# https://github.com/buildpacks/pack/releases
ARG PACK_VERSION=0.30.0
# https://github.com/railwayapp/nixpacks/releases
-ARG NIXPACKS_VERSION=1.14.0
+ARG NIXPACKS_VERSION=1.16.0
USER root
WORKDIR /artifacts
diff --git a/docker/dev-ssu/Dockerfile b/docker/dev-ssu/Dockerfile
index afc606d67a..58941b73ff 100644
--- a/docker/dev-ssu/Dockerfile
+++ b/docker/dev-ssu/Dockerfile
@@ -1,5 +1,9 @@
FROM serversideup/php:8.2-fpm-nginx
+ARG TARGETPLATFORM
+# https://github.com/cloudflare/cloudflared/releases
+ARG CLOUDFLARED_VERSION=2023.8.2
+
ARG POSTGRES_VERSION=15
RUN apt-get update
# Postgres version requirements
@@ -13,15 +17,23 @@ RUN apt-get install postgresql-client-$POSTGRES_VERSION -y
# Coolify requirements
RUN apt-get install -y php-pgsql openssh-client git git-lfs jq lsof
-
RUN apt-get -y autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
+COPY --chmod=755 docker/dev-ssu/etc/s6-overlay/ /etc/s6-overlay/
COPY docker/dev-ssu/nginx.conf /etc/nginx/conf.d/custom.conf
RUN echo "alias ll='ls -al'" >>/etc/bash.bashrc
RUN echo "alias a='php artisan'" >>/etc/bash.bashrc
-RUN echo "alias mfs='php artisan migrate:fresh --seed'" >>/etc/bash.bashrc
-RUN echo "alias cda='composer dump-autoload'" >>/etc/bash.bashrc
-RUN echo "alias run='./scripts/run'" >>/etc/bash.bashrc
-COPY --chmod=755 docker/dev-ssu/etc/s6-overlay/ /etc/s6-overlay/
+RUN mkdir -p /usr/local/bin
+
+RUN /bin/bash -c "if [[ ${TARGETPLATFORM} == 'linux/amd64' ]]; then \
+ echo 'amd64' && \
+ curl -sSL https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared \
+ ;fi"
+
+RUN /bin/bash -c "if [[ ${TARGETPLATFORM} == 'linux/arm64' ]]; then \
+ echo 'arm64' && \
+ curl -L https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/cloudflared-linux-arm64 -o /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared \
+ ;fi"
+
diff --git a/docker/prod-ssu/Dockerfile b/docker/prod-ssu/Dockerfile
index 0804ee076f..dac8c56a91 100644
--- a/docker/prod-ssu/Dockerfile
+++ b/docker/prod-ssu/Dockerfile
@@ -12,9 +12,14 @@ RUN npm install
RUN npm run build
FROM serversideup/php:8.2-fpm-nginx
-WORKDIR /var/www/html
+
+ARG TARGETPLATFORM
+# https://github.com/cloudflare/cloudflared/releases
+ARG CLOUDFLARED_VERSION=2023.8.2
ARG POSTGRES_VERSION=15
+WORKDIR /var/www/html
+
RUN apt-get update
# Postgres version requirements
RUN apt install dirmngr ca-certificates software-properties-common gnupg gnupg2 apt-transport-https curl -y
@@ -44,7 +49,16 @@ RUN php artisan view:cache
RUN echo "alias ll='ls -al'" >>/etc/bash.bashrc
RUN echo "alias a='php artisan'" >>/etc/bash.bashrc
-RUN echo "alias mfs='php artisan migrate:fresh --seed'" >>/etc/bash.bashrc
-RUN echo "alias cda='composer dump-autoload'" >>/etc/bash.bashrc
-RUN echo "alias run='./scripts/run'" >>/etc/bash.bashrc
RUN echo "alias logs='tail -f storage/logs/laravel.log'" >>/etc/bash.bashrc
+
+RUN mkdir -p /usr/local/bin
+
+RUN /bin/bash -c "if [[ ${TARGETPLATFORM} == 'linux/amd64' ]]; then \
+ echo 'amd64' && \
+ curl -sSL https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared \
+ ;fi"
+
+RUN /bin/bash -c "if [[ ${TARGETPLATFORM} == 'linux/arm64' ]]; then \
+ echo 'arm64' && \
+ curl -L https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/cloudflared-linux-arm64 -o /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared \
+ ;fi"
diff --git a/docker/testing-host/Dockerfile b/docker/testing-host/Dockerfile
index 3a1e053a5e..d78b6f03ee 100644
--- a/docker/testing-host/Dockerfile
+++ b/docker/testing-host/Dockerfile
@@ -7,10 +7,6 @@ ARG DOCKER_VERSION=24.0.5
ARG DOCKER_COMPOSE_VERSION=2.21.0
# https://github.com/docker/buildx/releases
ARG DOCKER_BUILDX_VERSION=0.11.2
-# https://github.com/buildpacks/pack/releases
-ARG PACK_VERSION=0.30.0
-# https://github.com/railwayapp/nixpacks/releases
-ARG NIXPACKS_VERSION=1.14.0
USER root
WORKDIR /root
diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php
index 4f3df85c2f..2ade05c9df 100644
--- a/resources/views/livewire/server/form.blade.php
+++ b/resources/views/livewire/server/form.blade.php
@@ -41,6 +41,10 @@
<x-forms.input type="number" id="server.port" label="Port" required />
</div>
</div>
+ <div class="w-64">
+ <x-forms.checkbox instantSave helper="If you are using Cloudflare Tunnels, enable this"
+ id="server.settings.is_cloudflare_tunnel" label="Cloudflare Tunnel" />
+ </div>
</div>
@if (!$server->settings->is_reachable)
<x-forms.button class="mt-8 mb-4 box" wire:click.prevent='validateServer'>