Skip to content

Commit d3bbd8b

Browse files
committed
Devlink local
1 parent 36d3fc0 commit d3bbd8b

File tree

9 files changed

+191
-109
lines changed

9 files changed

+191
-109
lines changed

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ composer.json-deploy
3636
3. When running `php init.php`
3737

3838
- Creates a `.env` file from `.env.example`
39-
- Copies `composer.json-deploy` to `composer.json`
40-
- Runs `composer install`
39+
- Copies `composer.json-linked` to `composer.json`
40+
- Runs `composer update`
4141

4242
4. When running `devlink:status`:
4343

@@ -50,7 +50,7 @@ composer.json-deploy
5050
- Creates the packages folder, if it does not exist
5151
- Creates symlinks for all configured packages
5252
- Updates composer.json with development configuration
53-
- Creates composer.json-deploy for production use
53+
- Creates composer.json-linked for production use
5454
- Asks to run `composer install`
5555
- Asks to run `php artisan optimize:clear`
5656
- Asks to run `php artisan queue:restart`
@@ -59,25 +59,23 @@ composer.json-deploy
5959

6060
- Removes all symlinks
6161
- Deletes the packages folder, if empty
62-
- Restores production-ready composer.json from composer.json-deploy
62+
- Restores production-ready composer.json from composer.json-linked
6363
- Asks to run `composer install`
6464
- Asks to run `php artisan optimize:clear`
6565
- Asks to run `php artisan queue:restart`
6666

6767
7. CI Safety Net - `deploy.sh`:
6868

69-
- If composer.json-deploy exists in the repository:
69+
- If composer.json-linked exists in the repository:
7070
- Remove all symlinks from /packages
71-
- rename composer.json-deploy to composer.json
71+
- rename composer.json-linked to composer.json
7272
- Commit and push the change in your GitHub Action
7373

74-
## Mac
75-
76-
Mac works out of the box. You can have local packages mixed with the symlinked packages in your `/packages` folder.
74+
Mac and Linux work out of the box. You can have local packages mixed with the symlinked packages in your `/packages` folder.
7775

7876
![Moox Devlink](./devlink-mix.jpg)
7977

80-
## Windows
78+
### Windows
8179

8280
On Windows there are most probably some issues with ignoring symlinks. If you run into issues, you can either globally or project-wise disable the symlinks or do the following:
8381

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ We are working on the following tasks from top to bottom. Please don't forget to
1010

1111
## Ideas
1212

13-
- [ ] Deploy: new feature: last version for all packages instead of \*
13+
- [ ] Deploy feature: last version for all packages instead of \*

config/devlink.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,37 @@
3838
| Packages
3939
|--------------------------------------------------------------------------
4040
|
41-
| The packages that should be linked into the project.
41+
| These packages are symlinked (or if local, just added) into the project.
4242
|
4343
| Active:
4444
| Toggle the package on and off. By default all packages are disabled.
4545
|
46-
| Linked:
47-
| Toggle the package off for linking, for example devlink itself.
48-
|
4946
| Path:
5047
| The path to the package in the packages directory.
5148
|
49+
| Repo-URL:
50+
| The URL of the private repository (Satis).
51+
|
5252
| Types:
5353
| - public = installed from Packagist
54-
| - private = copied into the project
54+
| - private = installed from Satis
55+
| - local = local package
5556
|
56-
| Deploy:
57-
| Toggle the package on and off for deployment. Better would be to use
58-
| require-dev in composer.json, but this also works.
57+
| Dev:
58+
| The package is only installed in the dev environment (require-dev).
5959
|
6060
*/
6161
'packages' => [
6262

63-
// Moox
63+
// Public
6464
'audit' => [
6565
'active' => false,
6666
'path' => $public_base_path.'/audit',
6767
'type' => 'public',
6868
],
6969
'backup-server-ui' => [
7070
'active' => false,
71-
'path' => $public_base_path.'/backup-server-ui',
71+
'path' => '../moox-server/packages/backup-server-ui',
7272
'type' => 'public',
7373
],
7474
'builder' => [
@@ -94,7 +94,7 @@
9494
],
9595
'devops' => [
9696
'active' => false,
97-
'path' => $public_base_path.'/devops',
97+
'path' => '../moox-server/packages/devops',
9898
'type' => 'public',
9999
],
100100
'expiry' => [
@@ -168,7 +168,7 @@
168168
'type' => 'public',
169169
],
170170

171-
// Moox Pro
171+
// Private
172172
'media' => [
173173
'active' => false,
174174
'path' => $private_base_path.'/media',

deploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
if [ -f "composer.json-deploy" ]; then
3+
if [ -f "composer.json-linked" ]; then
44
find packages -type l -delete
5-
cp composer.json-deploy composer.json
5+
cp composer.json-linked composer.json
66
fi

init.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
file_put_contents('.env', $env);
1818

1919
if (file_exists('composer.json-deploy')) {
20-
copy('composer.json-deploy', 'composer.json');
20+
copy('composer.json-linked', 'composer.json');
2121
}
2222

23-
exec('composer install');
23+
exec('composer update');

src/Console/Traits/Check.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,41 @@ private function check(): array
3535

3636
foreach ($config['packages'] as $name => $package) {
3737
$packagePath = "packages/{$name}";
38+
$isLocal = ($package['type'] ?? '') === 'local';
39+
$isPrivate = ($package['type'] ?? '') === 'private';
3840

39-
// Check if package is in repositories
41+
// Check if package is linked
4042
$isLinked = false;
41-
foreach ($repositories as $repo) {
42-
if (($repo['type'] ?? '') === 'path' && ($repo['url'] ?? '') === $packagePath) {
43-
$isLinked = true;
44-
break;
43+
if ($isLocal) {
44+
// Local packages: check for path entry in composer.json
45+
foreach ($repositories as $repo) {
46+
if (($repo['type'] ?? '') === 'path' && ($repo['url'] ?? '') === $packagePath) {
47+
$isLinked = true;
48+
break;
49+
}
4550
}
51+
} else {
52+
// Public and Private packages: check for symlink
53+
$isLinked = is_link($packagePath);
4654
}
4755

4856
$packagesArray[$name] = $package;
57+
4958
$realPackages[$name] = [
5059
'name' => $name,
5160
'type' => $package['type'] ?? 'unknown',
5261
'active' => $package['active'] ?? false,
5362
'link' => $package['linked'] ?? true,
5463
'deploy' => $package['deploy'] ?? false,
55-
'valid' => is_dir($package['path']),
64+
'valid' => match (true) {
65+
$isLocal => is_dir($packagePath),
66+
$isPrivate => is_dir($package['path'] ?? ''),
67+
default => is_dir($package['path'] ?? ''),
68+
},
5669
'linked' => $isLinked,
5770
];
5871

59-
if (str_contains($package['path'], 'disabled')) {
72+
if (! $isPrivate && isset($package['path']) && str_contains($package['path'], 'disabled')) {
6073
unset($realPackages[$name]);
6174
}
6275
}

src/Console/Traits/Deploy.php

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ private function deploy(): void
1111
{
1212
$this->unlink();
1313
$this->cleanup();
14-
$this->restore();
15-
$this->createDeployComposerJson();
14+
$this->moveComposerFiles();
1615
}
1716

1817
/**
@@ -41,69 +40,24 @@ private function cleanup(): void
4140
if (is_dir($this->packagesPath) && count(scandir($this->packagesPath)) === 2) {
4241
info('Removing packages directory...');
4342
rmdir($this->packagesPath);
44-
} else {
45-
$this->errorMessage = 'Packages directory not found!';
46-
error($this->errorMessage);
4743
}
4844
}
4945

50-
/**
51-
* Restore the composer.json file from the backup.
52-
*/
53-
private function restore(): void
46+
private function moveComposerFiles(): void
5447
{
55-
$source = $this->composerJsonPath.'-deploy';
56-
$destination = $this->composerJsonPath;
48+
$linked = $this->composerJsonPath.'-linked';
49+
$deploy = $this->composerJsonPath.'-deploy';
5750

58-
if (file_exists($source)) {
59-
unlink($destination);
60-
copy($source, $destination);
61-
info('Restored composer.json from composer.json-deploy');
62-
} else {
63-
$this->errorMessage = 'composer.json-deploy not found!';
51+
if (! file_exists($linked)) {
52+
$this->errorMessage = 'composer.json-linked not found!';
6453
error($this->errorMessage);
65-
}
66-
}
67-
68-
private function createDeployComposerJson(): void
69-
{
70-
if (! file_exists($this->composerJsonPath)) {
71-
$this->error('composer.json not found!');
7254

7355
return;
7456
}
7557

76-
$composerContent = file_get_contents($this->composerJsonPath);
77-
$composerJson = json_decode($composerContent, true);
78-
79-
if (json_last_error() !== JSON_ERROR_NONE) {
80-
$this->error('Invalid composer.json format: '.json_last_error_msg());
81-
82-
return;
83-
}
84-
85-
$deployJson = $composerJson;
86-
$repositories = $deployJson['repositories'] ?? [];
87-
$filteredRepos = [];
88-
89-
foreach ($repositories as $repo) {
90-
if (($repo['type'] ?? '') !== 'path') {
91-
$filteredRepos[] = $repo;
92-
}
93-
}
94-
95-
if (empty($filteredRepos)) {
96-
unset($deployJson['repositories']);
97-
} else {
98-
$deployJson['repositories'] = $filteredRepos;
99-
}
100-
101-
$deployPath = dirname($this->composerJsonPath).'/composer.json-deploy';
102-
file_put_contents(
103-
$deployPath,
104-
json_encode($deployJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"
105-
);
106-
107-
info('Created composer.json-deploy with non-path repositories');
58+
rename($this->composerJsonPath, $deploy);
59+
rename($linked, $this->composerJsonPath);
60+
info('Moved composer.json to composer.json-deploy');
61+
info('Moved composer.json-linked to composer.json');
10862
}
10963
}

0 commit comments

Comments
 (0)