Skip to content

Commit f0d7aa7

Browse files
committed
Datetime deployment naming option
Refactoring and readme updates
1 parent 92e0279 commit f0d7aa7

File tree

9 files changed

+115
-95
lines changed

9 files changed

+115
-95
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ return [
6969
'build-limit' => 10,
7070

7171
/**
72-
* Migrate files|folders from the outgoing production build to your new release using a relative path and pattern.
72+
* Logic used when creating a deployment directory.
7373
*
74-
* @see https://www.php.net/manual/en/function.glob.php
74+
* Default => git - uses hash for current HEAD
75+
* Options: [ git, rand ]
76+
*
77+
* If your build does not use git, use rand.
7578
*/
76-
'migrate' => [
77-
// 'storage/framework/sessions/*',
78-
],
79+
'directory-naming' => 'git',
7980

8081
/**
8182
* Deployment class used.
@@ -86,14 +87,13 @@ return [
8687
'deployment-class' => \JTMcC\AtomicDeployments\Services\Deployment::class,
8788

8889
/**
89-
* Logic used when creating a deployment directory
90-
*
91-
* Default => git - uses hash for current HEAD
92-
* Options: [ git, rand ]
90+
* Migrate files|folders from the outgoing production build to your new release using a relative path and pattern.
9391
*
94-
* If your build does not use git, use rand.
92+
* @see https://www.php.net/manual/en/function.glob.php
9593
*/
96-
'directory-naming' => 'git'
94+
'migrate' => [
95+
// 'storage/framework/sessions/*',
96+
],
9797

9898
];
9999
```

config/atomic-deployments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* Logic used when creating a deployment directory.
3232
*
3333
* Default => git - uses hash for current HEAD
34-
* Options: [ git, rand ]
34+
* Options: [ git, datetime, rand ]
3535
*
36-
* If your build does not use git, use rand.
36+
* If your build does not use git, use datetime or rand.
3737
*/
3838
'directory-naming' => 'git',
3939

src/Commands/DeployCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function handle()
4040
);
4141

4242
try {
43-
$atomicDeployment->getDeployment()->linkDeployment();
43+
$atomicDeployment->getDeployment()->link();
4444
$atomicDeployment->confirmSymbolicLink();
4545
DeploymentSuccessful::dispatch($atomicDeployment, $deploymentModel);
4646
} catch (\Throwable $e) {
47-
$atomicDeployment->failed();
47+
$atomicDeployment->fail();
4848
Output::throwable($e);
4949
}
5050
}
@@ -56,11 +56,11 @@ public function handle()
5656
try {
5757
if ($deployDir = trim($this->option('directory'))) {
5858
Output::info("Deployment directory option set - Deployment will use directory: {$deployDir} ");
59-
$atomicDeployment->getDeployment()->setDeploymentDirectory($deployDir);
59+
$atomicDeployment->getDeployment()->setDirectory($deployDir);
6060
}
6161
$atomicDeployment->deploy(fn () => $atomicDeployment->cleanBuilds(config('atomic-deployments.build-limit')));
6262
} catch (\Throwable $e) {
63-
$atomicDeployment->failed();
63+
$atomicDeployment->fail();
6464
Output::throwable($e);
6565
}
6666
}

src/Interfaces/DeploymentInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ interface DeploymentInterface
66
{
77
public function getBuildPath();
88

9-
public function setDeploymentDirectory(string $name = '');
9+
public function setDirectory(string $name = '');
1010

11-
public function setDeploymentPath();
11+
public function setPath();
1212

13-
public function getDeploymentPath();
13+
public function getPath();
1414

15-
public function getCurrentDeploymentPath();
15+
public function getCurrentPath();
1616

1717
public function copyContents();
1818

19-
public function linkDeployment();
19+
public function link();
2020

21-
public function getDeploymentLink();
21+
public function getLink();
2222

2323
public function getModel();
2424

25-
public function updateDeploymentStatus(int $status);
25+
public function updateStatus(int $status);
2626
}

src/Services/AtomicDeploymentService.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use JTMcC\AtomicDeployments\Exceptions\ExecuteFailedException;
1313
use JTMcC\AtomicDeployments\Helpers\FileHelper;
1414
use JTMcC\AtomicDeployments\Interfaces\DeploymentInterface;
15-
use JTMcC\AtomicDeployments\Models\AtomicDeployment as Model;
15+
use JTMcC\AtomicDeployments\Models\AtomicDeployment;
1616
use JTMcC\AtomicDeployments\Models\Enums\DeploymentStatus;
1717

1818
class AtomicDeploymentService
@@ -47,7 +47,7 @@ public function __construct(DeploymentInterface $deployment, array $migrate = []
4747

4848
register_shutdown_function([$this, 'shutdown']);
4949

50-
$this->initialDeploymentPath = $deployment->getCurrentDeploymentPath();
50+
$this->initialDeploymentPath = $deployment->getCurrentPath();
5151
}
5252

5353
/**
@@ -69,10 +69,10 @@ public function getInitialDeploymentPath(): string
6969
/**
7070
* Run full deployment.
7171
*
72-
* @param Closure|null $success
73-
* @param Closure|null $failed
72+
* @param Closure|null $successCallback
73+
* @param Closure|null $failedCallback
7474
*/
75-
public function deploy(?Closure $success = null, ?Closure $failed = null): void
75+
public function deploy(?Closure $successCallback = null, ?Closure $failedCallback = null): void
7676
{
7777
try {
7878
if ($this->isDryRun()) {
@@ -98,14 +98,14 @@ public function deploy(?Closure $success = null, ?Closure $failed = null): void
9898

9999
DeploymentSuccessful::dispatch($this, $this->deployment->getModel());
100100

101-
if ($success) {
102-
$success($this);
101+
if ($successCallback) {
102+
$successCallback($this);
103103
}
104104
} catch (\Throwable $e) {
105-
$this->failed();
105+
$this->fail();
106106
Output::throwable($e);
107-
if ($failed) {
108-
$failed($this);
107+
if ($failedCallback) {
108+
$failedCallback($this);
109109
}
110110
}
111111
}
@@ -120,18 +120,18 @@ public function updateDeploymentStatus(int $status): void
120120

121121
return;
122122
}
123-
$this->deployment->updateDeploymentStatus($status);
123+
$this->deployment->updateStatus($status);
124124
}
125125

126126
public function linkDeployment(): void
127127
{
128-
Output::info("Creating symbolic link: {$this->deployment->getDeploymentLink()} -> {$this->deployment->getDeploymentPath()}");
128+
Output::info("Creating symbolic link: {$this->deployment->getLink()} -> {$this->deployment->getPath()}");
129129
if ($this->isDryRun()) {
130130
Output::warn('Dry run - Skipping symbolic link deployment');
131131

132132
return;
133133
}
134-
$this->deployment->linkDeployment();
134+
$this->deployment->link();
135135
Output::info('Link created');
136136
}
137137

@@ -153,8 +153,8 @@ public function confirmSymbolicLink(): bool
153153
if (!$this->deployment->isDeployed()) {
154154
throw new ExecuteFailedException(
155155
'Expected deployment link to direct to '.
156-
$this->deployment->getDeploymentPath().' but found '.
157-
$this->deployment->getCurrentDeploymentPath()
156+
$this->deployment->getPath().' but found '.
157+
$this->deployment->getCurrentPath()
158158
);
159159
}
160160

@@ -165,7 +165,7 @@ public function confirmSymbolicLink(): bool
165165

166166
public function createDeploymentDirectory(): void
167167
{
168-
Output::info("Creating directory at {$this->deployment->getDeploymentPath()}");
168+
Output::info("Creating directory at {$this->deployment->getPath()}");
169169

170170
if ($this->isDryRun()) {
171171
Output::warn('Dry run - Skipping creating deployment directory');
@@ -209,7 +209,7 @@ public function copyMigrationContents(): void
209209
}
210210

211211
$rootFrom = rtrim($this->initialDeploymentPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
212-
$rootTo = rtrim($this->deployment->getDeploymentPath(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
212+
$rootTo = rtrim($this->deployment->getPath(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
213213

214214
foreach (File::glob($rootFrom.$pattern) as $from) {
215215
$dir = $from;
@@ -254,7 +254,7 @@ public function updateSymlinks()
254254

255255
FileHelper::recursivelyUpdateSymlinks(
256256
$this->getDeployment()->getBuildPath(),
257-
$this->getDeployment()->getDeploymentPath()
257+
$this->getDeployment()->getPath()
258258
);
259259

260260
Output::info('Finished correcting symlinks');
@@ -265,7 +265,7 @@ public function rollback(): void
265265
Output::warn('Atomic deployment rollback has been requested');
266266

267267
if (!$this->isDryRun()) {
268-
$currentPath = $this->deployment->getCurrentDeploymentPath();
268+
$currentPath = $this->deployment->getCurrentPath();
269269

270270
if (
271271
//confirm if we need to revert the link
@@ -276,8 +276,8 @@ public function rollback(): void
276276

277277
try {
278278
//attempt to revert link to our original path
279-
Exec::ln($this->deployment->getDeploymentLink(), $this->initialDeploymentPath);
280-
if ($this->deployment->getCurrentDeploymentPath() === $this->initialDeploymentPath) {
279+
Exec::ln($this->deployment->getLink(), $this->initialDeploymentPath);
280+
if ($this->deployment->getCurrentPath() === $this->initialDeploymentPath) {
281281
Output::info('Successfully rolled back symbolic link');
282282

283283
return;
@@ -300,7 +300,7 @@ public function isDryRun(): bool
300300
return $this->dryRun;
301301
}
302302

303-
public function failed(): void
303+
public function fail(): void
304304
{
305305
$this->rollback();
306306
DeploymentFailed::dispatch($this, $this->deployment->getModel());
@@ -311,7 +311,7 @@ public function shutdown(): void
311311
{
312312
if ($error = error_get_last()) {
313313
Output::error('Error detected during shutdown, requesting rollback');
314-
$this->failed();
314+
$this->fail();
315315
}
316316
}
317317

@@ -320,16 +320,16 @@ public function cleanBuilds(int $limit): void
320320
Output::alert('Running Build Cleanup');
321321
Output::info("Max deployment directories allowed set to {$limit}");
322322

323-
$buildIDs = Model::successful()
323+
$buildIDs = AtomicDeployment::successful()
324324
->orderBy('id', 'desc')
325325
->limit($limit)
326326
->pluck('id');
327327

328-
$buildsToRemove = Model::whereNotIn('id', $buildIDs)->get();
328+
$buildsToRemove = AtomicDeployment::whereNotIn('id', $buildIDs)->get();
329329

330-
$found = $buildsToRemove->count();
330+
$countOfBuildsToRemove = $buildsToRemove->count();
331331

332-
Output::info('Found '.$found.' '.Pluralizer::plural('folder', $found).' to be removed');
332+
Output::info('Found '.$countOfBuildsToRemove.' '.Pluralizer::plural('folder', $countOfBuildsToRemove).' to be removed');
333333

334334
foreach ($buildsToRemove as $deployment) {
335335
if ($deployment->isCurrentlyDeployed) {

0 commit comments

Comments
 (0)