This commit is contained in:
Andras Bacsai 2023-03-28 20:59:42 +02:00
parent 4df66ebf00
commit 593f1acf10
5 changed files with 47 additions and 17 deletions

View File

@ -19,11 +19,19 @@ class DemoDeployApplication extends Component
public Application $application;
public $destination;
public string $deployment_id;
public string $workdir;
public CoolifyInstanceSettings $coolify_instance_settings;
public $wildcard_domain;
protected $command;
private function dockerPreCommand($command)
{
return $this->command[] = "docker exec {$this->deployment_id} sh -c '{$command}'";
}
public function deploy()
{
$this->isKeepAliveOn = true;
@ -36,22 +44,24 @@ public function deploy()
$this->wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null;
$source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first();
$deployment_id = new Cuid2(10);
$this->deployment_id = new Cuid2(10);
$workdir = $this->get_workdir('application', $this->application->uuid, $deployment_id);
$this->workdir = "/tmp/{$this->deployment_id}";
$command[] = "echo 'Starting deployment of {$this->application->name} ({$this->application->uuid})'";
$command[] = 'mkdirs -p ' . $workdir;
$command[] = "git clone -b {$this->application->git_branch} {$source->html_url}/{$this->application->git_repository}.git {$workdir}";
$this->command[] = "echo 'Starting deployment of {$this->application->name} ({$this->application->uuid})'";
$this->command[] = "docker run -d --name {$this->deployment_id} --rm -v /var/run/docker.sock:/var/run/docker.sock coolify-builder >/dev/null";
if (!file_exists($workdir) && $workdir != "/") {
$command[] = "echo 'Removing {$workdir}'";
$command[] = "rm -rf {$workdir}";
}
$this->activity = remoteProcess(implode("\n", $command), $this->destination->server->name);
$this->dockerPreCommand('hostname');
$this->dockerPreCommand("mkdir -p {$this->workdir}");
$this->dockerPreCommand("ls -ld {$this->workdir}");
$this->dockerPreCommand("git clone -b {$this->application->git_branch} {$source->html_url}/{$this->application->git_repository}.git {$this->workdir}");
$this->dockerPreCommand("ls -l {$this->workdir}");
$this->command[] = "docker stop -t 0 {$this->deployment_id} >/dev/null";
$this->activity = remoteProcess(implode("\n", $this->command), $this->destination->server->name);
Deployment::create([
'uuid' => $deployment_id,
'uuid' => $this->deployment_id,
'type_id' => $this->application->id,
'type_type' => Application::class,
'activity_log_id' => $this->activity->id,

View File

@ -22,7 +22,6 @@ function remoteProcess(
$temp_file = 'id.rsa_' . 'root' . '@' . $found_server->ip;
Storage::disk('local')->put($temp_file, $found_server->privateKey->private_key, 'private');
$private_key_location = '/var/www/html/storage/app/' . $temp_file;
return resolve(DispatchRemoteProcess::class, [
'remoteProcessArgs' => new RemoteProcessArgs(
destination: $found_server->ip,

View File

@ -37,7 +37,7 @@ public function run(): void
'id' => 3,
'name' => "localhost",
'description' => "This is the local machine",
'user' => 'ab',
'user' => 'andrasbacsai',
'ip' => "172.17.0.1",
'team_id' => $root_team->id,
'private_key_id' => $private_key_1->id,

25
docker/builder/Dockerfile Normal file
View File

@ -0,0 +1,25 @@
FROM alpine:3.17
ARG TARGETPLATFORM
# https://download.docker.com/linux/static/stable/
ARG DOCKER_VERSION=20.10.18
# https://github.com/docker/compose/releases
# Reverted to 2.6.1 because of this https://github.com/docker/compose/issues/9704. 2.9.0 still has a bug.
ARG DOCKER_COMPOSE_VERSION=2.6.1
# https://github.com/buildpacks/pack/releases
ARG PACK_VERSION=0.27.0
# https://github.com/railwayapp/nixpacks/releases
ARG NIXPACKS_VERSION=1.6.0
USER root
RUN apk add --no-cache bash curl git git-lfs openssh-client tar tini
RUN mkdir -p ~/.docker/cli-plugins
RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-$DOCKER_VERSION -o /usr/bin/docker
RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-compose-linux-$DOCKER_COMPOSE_VERSION -o ~/.docker/cli-plugins/docker-compose
RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/pack-v$PACK_VERSION -o /usr/local/bin/pack
RUN curl -sSL https://nixpacks.com/install.sh | bash
RUN chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["sh", "-c", "while true; do sleep 1000; done"]

View File

@ -4,10 +4,6 @@
Activity: <span>{{ $activity?->id ?? 'waiting' }}</span>
</div>
<pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>{{ data_get($activity, 'description') }}</pre>
{{-- <div>
<div>Details:</div>
<pre style="width: 100%;overflow-y: scroll;">{{ json_encode(data_get($activity, 'properties'), JSON_PRETTY_PRINT) }}</pre>
</div> --}}
@endisset
<button wire:click='deploy'>Deploy</button>
</div>