Skip to content

Commit

Permalink
feat: #52 support the 'release' step
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Jul 4, 2024
1 parent a3d1f50 commit 03d7ae9
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ RUN apt-get update \
&& docker-php-ext-configure pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql \
&& docker-php-source delete \
&& awk 'NR==1 {print; print "\tservers {\n\t\ttrusted_proxies static private_ranges\n\t}\n"; next} 1' /etc/caddy/Caddyfile > /etc/caddy/Caddyfile.tmp \
&& mv /etc/caddy/Caddyfile.tmp /etc/caddy/Caddyfile
&& awk 'NR==1 {print; print "\tservers {\n\t\ttrusted_proxies static private_ranges\n\t}\n"; next} 1' /etc/caddy/Caddyfile > /etc/caddy/Caddyfile

WORKDIR /app

Expand All @@ -27,9 +26,10 @@ RUN php composer.phar install --no-scripts

COPY . .

RUN php composer.phar install

RUN npm run build \
RUN php composer.phar install \
&& npm run build \
&& php artisan optimize \
&& php artisan data:cache-structures \
&& apt-get -y remove npm unzip \
&& apt-get -y clean \
&& apt-get -y autoremove \
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/SwarmTaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Requests\NodeTask\InitClusterFormRequest;
use App\Models\DeploymentData;
use App\Models\DeploymentData\LaunchMode;
use App\Models\DeploymentData\ReleaseCommand;
use App\Models\Network;
use App\Models\Node;
use App\Models\NodeTaskGroup;
Expand Down Expand Up @@ -118,6 +119,9 @@ public function initCluster(InitClusterFormRequest $request)
'launchMode' => LaunchMode::Daemon->value,
'dockerRegistryId' => null,
'dockerImage' => 'caddy:2.8-alpine',
'releaseCommand' => [
'command' => null,
],
'command' => 'sh /start.sh',
'envVars' => [
[
Expand Down
4 changes: 4 additions & 0 deletions app/Models/DeploymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\DeploymentData\LaunchMode;
use App\Models\DeploymentData\Process;
use App\Models\DeploymentData\ReleaseCommand;
use App\Models\DeploymentData\SecretVars;
use App\Util\Arrays;
use Illuminate\Validation\ValidationException;
Expand Down Expand Up @@ -33,6 +34,9 @@ public static function make(array $attributes): static
'name' => 'svc',
'dockerRegistry' => null,
'dockerImage' => '',
'releaseCommand' => ReleaseCommand::from([
'command' => null,
]),
'command' => '',
'launchMode' => LaunchMode::Daemon->value,
'envVars' => [],
Expand Down
24 changes: 24 additions & 0 deletions app/Models/DeploymentData/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct(
public ?string $dockerName,
public ?string $dockerRegistry,
public string $dockerImage,
public ReleaseCommand $releaseCommand,
public ?string $command,
#[Enum(LaunchMode::class)]
public string $launchMode,
Expand Down Expand Up @@ -186,6 +187,7 @@ public function asNodeTasks(Deployment $deployment): array
'meta' => $actionUpdate ? UpdateServiceMeta::from($serviceTaskMeta) : CreateServiceMeta::from($serviceTaskMeta),
'payload' => [
'AuthConfigName' => $this->dockerRegistry,
'ReleaseCommand' => $this->getReleaseCommandPayload($deployment, $labels),
'SecretVars' => (object) $this->getSecretVars($previous, $labels),
'SwarmServiceSpec' => [
'Name' => $this->dockerName,
Expand Down Expand Up @@ -298,4 +300,26 @@ public function makeResourceName(string $name): string
{
return dockerize_name($this->dockerName . '_' . $name);
}

private function getReleaseCommandPayload(Deployment $deployment, array $labels): array
{
if (!$this->releaseCommand->command) {
return [
'ConfigName' => '',
'ConfigLabels' => (object) [],
'Command' => '',
];
}

// Always create a new config, as the command may be the same, but the image/entrypoint may be different.
$this->releaseCommand->dockerName = $deployment->makeResourceName('release_command');
return [
'ConfigName' => $this->releaseCommand->dockerName,
'ConfigLabels' => dockerize_labels([
...$labels,
'kind' => 'release-command',
]),
'Command' => $this->releaseCommand->command,
];
}
}
16 changes: 16 additions & 0 deletions app/Models/DeploymentData/ReleaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Models\DeploymentData;

use Spatie\LaravelData\Data;

class ReleaseCommand extends Data
{
public function __construct(
public ?string $dockerName,
public ?string $command
)
{
//
}
}
2 changes: 1 addition & 1 deletion resources/js/Pages/Nodes/Partials/AgentStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function upgradeAgent() {
</div>
</template>

<template v-if="$props.lastAgentVersion !== $props.node.data.version && $props.node.online" #submit>
<template v-if="$props.node.online && $props.lastAgentVersion !== $props.node.data.version" #submit>
<a class="text-sm text-blue-700 hover:underline px-8" :href="'https://github.com/ptah-sh/ptah-agent/compare/' + $props.node.data.version + '...' + $props.lastAgentVersion" target="_blank">Compare {{$props.node.data.version}}...{{$props.lastAgentVersion}}</a>
<PrimaryButton type="button" @click="upgradeAgent">Upgrade to {{$props.lastAgentVersion}}</PrimaryButton>
</template>
Expand Down
23 changes: 23 additions & 0 deletions resources/js/Pages/Services/Partials/DeploymentData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,29 @@ const submitProcessRemoval = () => {
<TextInput v-model="model.processes[state.selectedProcessIndex['processes']].replicas" class="w-full" />
</FormField>

<FormField class="col-span-6" :error="props.errors[`processes.${state.selectedProcessIndex['processes']}.releaseCommand.command`]">
<template #label>
<fwb-tooltip class="">
<template #trigger>
<div class="flex items-center">
Release Command

<svg class="ms-1 w-4 h-4 text-blue-600 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.529 9.988a2.502 2.502 0 1 1 5 .191A2.441 2.441 0 0 1 12 12.582V14m-.01 3.008H12M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"/>
</svg>
</div>

</template>

<template #content>
This command will be executed right before the Docker Image's entrypoint. You can leave it empty.
</template>
</fwb-tooltip>
</template>

<TextInput v-model="model.processes[state.selectedProcessIndex['processes']].releaseCommand.command" class="block w-full" placeholder="php artisan migrate --no-interaction --verbose --ansi --step --force"/>
</FormField>

<FormField class="col-span-6" :error="props.errors[`processes.${state.selectedProcessIndex['processes']}.command`]">
<template #label>
<fwb-tooltip class="">
Expand Down

0 comments on commit 03d7ae9

Please sign in to comment.