Skip to content

Commit

Permalink
Devlink V1 (#744)
Browse files Browse the repository at this point in the history
* Devlink wip

* Devlink wip

* Devlink v1

* Docs
  • Loading branch information
adrolli authored Feb 15, 2025
1 parent 2027389 commit c3502be
Show file tree
Hide file tree
Showing 24 changed files with 1,267 additions and 619 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"wikimedia/composer-merge-plugin": "^2.1"
},
"require-dev": {
"moox/devlink": "*",
"fakerphp/faker": "^1.23.1",
"larastan/larastan": "^3.0",
"laravel/pint": "^1.0",
Expand Down Expand Up @@ -145,4 +146,4 @@
},
"minimum-stability": "dev",
"prefer-stable": false
}
}
29 changes: 29 additions & 0 deletions packages/devlink/CLASSES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Classes

## Commands

- `DeployCommand`: Deploy the packages
- `UnlinkCommand`: Unlink the packages
- `LinkCommand`: Link the packages
- `StatusCommand`: Show the status of Devlink

## Traits

- `Art`: Artistic output
- `Backup`: Backup composer.json
- `Check`: Check the status of Devlink
- `Cleanup`: Cleanup the packages
- `Deploy`: Deploy the packages
- `Finalize`: Finalize the packages
- `Link`: Create symlinks for the packages
- `Prepare`: Prepare the folder
- `Restore`: Restore composer.json
- `Show`: Read the JSON and show the status
- `Status`: Write the JSON status file
- `Unlink`: Remove symlinks for the packages

## Other

- `devlink.php`: The config file
- `devlink.json`: The generated status file
- `deploy.sh`: The shell script
62 changes: 41 additions & 21 deletions packages/devlink/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Moox Devlink

This package is only for internal use.

It is used to link the packages from the `moox` monorepo into a project. It runs on MacOS, Linux and Windows.
Moox Devlink is used to link packages a monorepo into any project and to deploy a production-ready composer.json. That allows us to develop Moox packages in any project. It runs on MacOS and Linux, Windows with special configuration.

## Installation

```bash
cp .env.example .env
composer require moox/devlink
php artisan vendor:publish --tag="devlink-config"
```
Expand All @@ -33,10 +30,18 @@ packages/*

```

2. Configure your paths and packages in the `config/devlink.php` file and the `.env` file, if needed (Windows users for example).
2. Configure your paths and packages in the `config/devlink.php` file and change the package path in the `.env` file, if needed (Windows users should set the `DEVLINK_PACKAGES_PATH` variable to `packageslocal`).

3. When running `devlink:status`:

- Lists all packages that are currently devlinked
- Lists all packages that are configured but not devlinked
- Lists all packages that are not configured, but devlinked
- Shows the configuration and the deploy status of each package

3. When running `devlink:link`:
4. When running `devlink:link`:

- Creates the packages folder, if it does not exist
- Creates backup of original composer.json → composer.json.original
- Creates symlinks for all configured packages
- Updates composer.json with development configuration
Expand All @@ -45,15 +50,31 @@ packages/*
- Asks to run `php artisan optimize:clear`
- Asks to run `php artisan queue:restart`

4. When running `devlink:deploy`:
5. When running `devlink:unlink`:

- Removes all symlinks
- Deletes the packages folder, if empty
- Creates a backup of composer.json to composer.json-backup
- Restores original composer.json from composer.json-original
- Asks to run `composer install`
- Asks to run `php artisan optimize:clear`
- Asks to run `php artisan queue:restart`

6. When running `devlink:deploy`:

- Removes all symlinks
- Deletes the packages folder, if empty
- Creates a backup of composer.json to composer.json-backup
- Restores production-ready composer.json from composer.json-deploy
- Asks to run `composer install`
- Asks to run `php artisan optimize:clear`
- Asks to run `php artisan queue:restart`

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

5. CI Safety Net - `deploy.sh`:
- If composer.json-deploy exists in the repository:
- The script will restore it as composer.json
- the script will restore it as composer.json
- rename composer.json-original to composer.json-backup
- Commit and push the change in GH action
- This ensures no development configuration reaches production

Expand All @@ -74,24 +95,23 @@ Mac works out of the box. You can have local packages mixed with the symlinked p

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

```php
```env
DEVLINK_PACKAGES_PATH=packages-linked
```

'packages_path' => 'packages-linked',
Devlink will then link the packages into the `packages-linked` folder instead of mixing them into packages.

```
## Classes

Devlink will then link the packages into the `packages-linked` folder.
Please see the [CLASSES.md](./CLASSES.md) file for a quick class overview.

## Roadmap

- [ ] Test on Mac
- [ ] Test on Windows
- [ ] Test Deployment on Mac
- [ ] Test Deployment on Windows
- [ ] Implement automatic Deployment
- [ ] Implement all 3 types of packages
- [ ] If package is a symlink itself, ...?
- [ ] If package is in multiple base paths...?
Please see the [ROADMAP.md](./ROADMAP.md) file for what is planned.

## Changelog

Please see the [CHANGELOG.md](./CHANGELOG.md) file for what has changed.

## Security Vulnerabilities

Expand Down
8 changes: 8 additions & 0 deletions packages/devlink/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Roadmap

## Current tasks

- [ ] Private packages are not yet handled (copied and wired with path)
- [ ] Need to delete private packages in the link and unlink steps then
- [ ] There is probably an unclear state, because we do not yet use `-backup` yet
- [ ] For the shell script, we also need to check if `-original` and `-backup` are correct
15 changes: 15 additions & 0 deletions packages/devlink/config/devlink.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"status": {
"linked": true,
"deploy": false,
"error": false,
"error_message": "Devlink is active, currently not ready for deployment"
},
"packages": {
"devlink": {
"active": true,
"linked": true,
"deployed": false
}
}
}
Loading

0 comments on commit c3502be

Please sign in to comment.