Skip to content

Commit

Permalink
Merge pull request #19 from studio24/hotfix/parse-legacy-date-format
Browse files Browse the repository at this point in the history
Parse legacy date format for showing last build info
  • Loading branch information
simonrjones authored Jun 4, 2024
2 parents 441af8a + c58226b commit 6058f9d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
42 changes: 42 additions & 0 deletions docs/common-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,45 @@ To remove any global installation run:
composer global remove deployer/deployer
sudo rm /usr/local/bin/dep
```

## Fixing permission issues for deploy:writeable
When updating projects to use v2 of Deployer Recipes we have encountered issues wih the ```deploy:writeable``` and ```deploy:shared``` tasks failing to re-assign correct permissions.
For example:
```
task deploy:writable
[staging] error in writable.php on line 121:
[staging] run cd /data/var/www/HOSTNAME/staging/releases/3 && (setfacl -L -m u:"apache":rwX -m u:deploy:rwX storage/app/public)
[staging] err setfacl: storage/app/: Operation not permitted
[staging] exit code 1 (General error)
ERROR: Task deploy:writable failed!
```

To fix this on a **staging** site we followed the below process:
* Renamed the shared dir with `mv /data/var/www/HOSTNAME/staging/shared /data/var/www/HOSTNAME/staging/shared-original`
* Re-run the `shared` and `writable` deployment tasks to re-create these shared folders with the correct permissions:
```
./vendor/bin/dep deploy:shared staging
./vendor/bin/dep deploy:writable staging
```
* Copy any required shared files from the `shared-original` to the `shared` dir

### Check permissions
To check the permissions on the dir use `getfacl shared/storage/app/`

If a sub-directory has permission issues and needs to be the same as its parent, e.g.

```
# Writable
/data/var/www/HOSTNAME/staging/shared/uploads
# Non-writable
/data/var/www/HOSTNAME/staging/shared/uploads/2024
```

Then you can run:

```
cd /data/var/www/HOSTNAME/staging/shared/uploads/2024
setfacl -m m::rwx .
```

2 changes: 2 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Many recipes contain predefined settings for `shared_files`, `shared_dirs`, `wri

You can view these settings in the source code for the recipe.

Please note we have some common settings in [recipe/common.php](../recipe/common.php) (e.g. http_user, remote_user).

To add a setting to your `deploy.php` file, you can use the [add()](https://deployer.org/docs/7.x/api#add) function. This will add to the predefined settings.

To completely replace the settings in your `deploy.php` file, you can use the [set()](https://deployer.org/docs/7.x/api#set) function. This will replace the predefined settings.
Expand Down
10 changes: 10 additions & 0 deletions docs/tasks/check-disk-space.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require 'vendor/studio24/deployer-recipes/tasks/check-disk-space.php';
```

## Configuration

### disk_space_filesystem
If you set the filesystem mount this check can review disk capacity and warn if it is too low.

```
Expand All @@ -20,6 +22,14 @@ set('disk_space_filesystem', '/data');
set('disk_space_filesystem', '/');
```

### disk_space_threshold

Set the disk space available (%) threshold to issue a disk space warning, by default this is 80.

### disk_space_max

Set the disk space available (%) threshold to halt deployment due to not enough server space, by default this is 97.

## Tasks

- `check:disk-space` – checks the disk usage of the target server and displays the results
Expand Down
7 changes: 5 additions & 2 deletions tasks/check-disk-space.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
task('check:disk-space', function () {
$filesystem = get('disk_space_filesystem', '');
$threshold = (int) get('disk_space_threshold', 80);
$max = (int) get('disk_space_max', 97);

if (!empty($filesystem)) {
// Run for a specific filesystem volume
Expand All @@ -27,8 +28,10 @@
// One filesystem volume returned
if (count($m[1]) === 1) {
$used = $m[1][0];
if ($used > $threshold) {
writeln(sprintf("<error>Server disk space is almost full: %d%% used</error>", $used));
if ($used >= $max) {
throw new \Exception(sprintf('Server disk space is too full to deploy to (%d%% used)', $used));
} elseif ($used >= $threshold) {
writeln(sprintf("<warning>Server disk space is almost full: %d%% used</warning>", $used));
} else {
writeln(sprintf("<info>Server disk space is OK: %d%% used</info>", $used));
}
Expand Down
7 changes: 6 additions & 1 deletion tasks/show-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@
}

// Output last build info
$date = new \DateTimeImmutable($buildData['deploy_datetime']);
try {
$date = new \DateTimeImmutable($buildData['deploy_datetime']);
} catch (\Exception $e) {
// Try old legacy format "20240415_094357"
$date = \DateTimeImmutable::createFromFormat('Ymd_His', $buildData['deploy_datetime']);
}
$summary = sprintf(
'<options=bold>Last build:</> <info>%s</> deployed <info>%s</> branch to <info>%s</> environment on <info>%s</>',
$buildData['deployed_by'],
Expand Down

0 comments on commit 6058f9d

Please sign in to comment.