Skip to content

Commit 03d7ae9

Browse files
committed
feat: #52 support the 'release' step
1 parent a3d1f50 commit 03d7ae9

File tree

7 files changed

+77
-6
lines changed

7 files changed

+77
-6
lines changed

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ RUN apt-get update \
77
&& docker-php-ext-configure pgsql \
88
&& docker-php-ext-install pdo pdo_pgsql pgsql \
99
&& docker-php-source delete \
10-
&& 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 \
11-
&& mv /etc/caddy/Caddyfile.tmp /etc/caddy/Caddyfile
10+
&& awk 'NR==1 {print; print "\tservers {\n\t\ttrusted_proxies static private_ranges\n\t}\n"; next} 1' /etc/caddy/Caddyfile > /etc/caddy/Caddyfile
1211

1312
WORKDIR /app
1413

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

2827
COPY . .
2928

30-
RUN php composer.phar install
31-
32-
RUN npm run build \
29+
RUN php composer.phar install \
30+
&& npm run build \
31+
&& php artisan optimize \
32+
&& php artisan data:cache-structures \
3333
&& apt-get -y remove npm unzip \
3434
&& apt-get -y clean \
3535
&& apt-get -y autoremove \

app/Http/Controllers/SwarmTaskController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Requests\NodeTask\InitClusterFormRequest;
66
use App\Models\DeploymentData;
77
use App\Models\DeploymentData\LaunchMode;
8+
use App\Models\DeploymentData\ReleaseCommand;
89
use App\Models\Network;
910
use App\Models\Node;
1011
use App\Models\NodeTaskGroup;
@@ -118,6 +119,9 @@ public function initCluster(InitClusterFormRequest $request)
118119
'launchMode' => LaunchMode::Daemon->value,
119120
'dockerRegistryId' => null,
120121
'dockerImage' => 'caddy:2.8-alpine',
122+
'releaseCommand' => [
123+
'command' => null,
124+
],
121125
'command' => 'sh /start.sh',
122126
'envVars' => [
123127
[

app/Models/DeploymentData.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\DeploymentData\LaunchMode;
66
use App\Models\DeploymentData\Process;
7+
use App\Models\DeploymentData\ReleaseCommand;
78
use App\Models\DeploymentData\SecretVars;
89
use App\Util\Arrays;
910
use Illuminate\Validation\ValidationException;
@@ -33,6 +34,9 @@ public static function make(array $attributes): static
3334
'name' => 'svc',
3435
'dockerRegistry' => null,
3536
'dockerImage' => '',
37+
'releaseCommand' => ReleaseCommand::from([
38+
'command' => null,
39+
]),
3640
'command' => '',
3741
'launchMode' => LaunchMode::Daemon->value,
3842
'envVars' => [],

app/Models/DeploymentData/Process.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct(
2323
public ?string $dockerName,
2424
public ?string $dockerRegistry,
2525
public string $dockerImage,
26+
public ReleaseCommand $releaseCommand,
2627
public ?string $command,
2728
#[Enum(LaunchMode::class)]
2829
public string $launchMode,
@@ -186,6 +187,7 @@ public function asNodeTasks(Deployment $deployment): array
186187
'meta' => $actionUpdate ? UpdateServiceMeta::from($serviceTaskMeta) : CreateServiceMeta::from($serviceTaskMeta),
187188
'payload' => [
188189
'AuthConfigName' => $this->dockerRegistry,
190+
'ReleaseCommand' => $this->getReleaseCommandPayload($deployment, $labels),
189191
'SecretVars' => (object) $this->getSecretVars($previous, $labels),
190192
'SwarmServiceSpec' => [
191193
'Name' => $this->dockerName,
@@ -298,4 +300,26 @@ public function makeResourceName(string $name): string
298300
{
299301
return dockerize_name($this->dockerName . '_' . $name);
300302
}
303+
304+
private function getReleaseCommandPayload(Deployment $deployment, array $labels): array
305+
{
306+
if (!$this->releaseCommand->command) {
307+
return [
308+
'ConfigName' => '',
309+
'ConfigLabels' => (object) [],
310+
'Command' => '',
311+
];
312+
}
313+
314+
// Always create a new config, as the command may be the same, but the image/entrypoint may be different.
315+
$this->releaseCommand->dockerName = $deployment->makeResourceName('release_command');
316+
return [
317+
'ConfigName' => $this->releaseCommand->dockerName,
318+
'ConfigLabels' => dockerize_labels([
319+
...$labels,
320+
'kind' => 'release-command',
321+
]),
322+
'Command' => $this->releaseCommand->command,
323+
];
324+
}
301325
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Models\DeploymentData;
4+
5+
use Spatie\LaravelData\Data;
6+
7+
class ReleaseCommand extends Data
8+
{
9+
public function __construct(
10+
public ?string $dockerName,
11+
public ?string $command
12+
)
13+
{
14+
//
15+
}
16+
}

resources/js/Pages/Nodes/Partials/AgentStatus.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function upgradeAgent() {
4646
</div>
4747
</template>
4848

49-
<template v-if="$props.lastAgentVersion !== $props.node.data.version && $props.node.online" #submit>
49+
<template v-if="$props.node.online && $props.lastAgentVersion !== $props.node.data.version" #submit>
5050
<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>
5151
<PrimaryButton type="button" @click="upgradeAgent">Upgrade to {{$props.lastAgentVersion}}</PrimaryButton>
5252
</template>

resources/js/Pages/Services/Partials/DeploymentData.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,29 @@ const submitProcessRemoval = () => {
310310
<TextInput v-model="model.processes[state.selectedProcessIndex['processes']].replicas" class="w-full" />
311311
</FormField>
312312

313+
<FormField class="col-span-6" :error="props.errors[`processes.${state.selectedProcessIndex['processes']}.releaseCommand.command`]">
314+
<template #label>
315+
<fwb-tooltip class="">
316+
<template #trigger>
317+
<div class="flex items-center">
318+
Release Command
319+
320+
<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">
321+
<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"/>
322+
</svg>
323+
</div>
324+
325+
</template>
326+
327+
<template #content>
328+
This command will be executed right before the Docker Image's entrypoint. You can leave it empty.
329+
</template>
330+
</fwb-tooltip>
331+
</template>
332+
333+
<TextInput v-model="model.processes[state.selectedProcessIndex['processes']].releaseCommand.command" class="block w-full" placeholder="php artisan migrate --no-interaction --verbose --ansi --step --force"/>
334+
</FormField>
335+
313336
<FormField class="col-span-6" :error="props.errors[`processes.${state.selectedProcessIndex['processes']}.command`]">
314337
<template #label>
315338
<fwb-tooltip class="">

0 commit comments

Comments
 (0)