Skip to content

Commit 771ad22

Browse files
authored
Workbench (#39)
1 parent bb1df38 commit 771ad22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1012
-134
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// https://aka.ms/devcontainer.json
21
{
32
"name": "Existing Docker Compose (Extend)",
43
"dockerComposeFile": [
@@ -9,18 +8,8 @@
98
"settings": {},
109
"extensions": [
1110
"editorconfig.editorconfig",
12-
"ryannaddy.laravel-artisan",
13-
"amiralizadeh9480.laravel-extra-intellisense",
14-
"stef-k.laravel-goto-controller",
15-
"codingyu.laravel-goto-view",
16-
"mikestead.dotenv",
17-
"christian-kohler.path-intellisense",
18-
"esbenp.prettier-vscode",
19-
"CoenraadS.bracket-pair-colorizer"
2011
],
2112
"remoteUser": "sail",
22-
"postCreateCommand": "chown -R 1000:1000 /var/www/html && composer install && php artisan key:generate",
23-
"forwardPorts": [80]
24-
// "runServices": [],
25-
// "shutdownAction": "none",
13+
"postCreateCommand": "chown -R 1000:1000 /var/www/html && composer install",
14+
"forwardPorts": [8000]
2615
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ yarn-error.log
1616
/.idea
1717
/.vscode
1818
.DS_Store
19+
composer.lock
20+
package-lock.json
21+
yarn.lock
22+

README.md

Lines changed: 83 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,83 @@
1-
# Waterline
2-
3-
An elegant UI for monitoring [Laravel Workflows](https://github.com/laravel-workflow/laravel-workflow).
4-
5-
## Installation
6-
7-
This UI is installable via [Composer](https://getcomposer.org).
8-
9-
```bash
10-
composer require laravel-workflow/waterline
11-
12-
php artisan waterline:install
13-
```
14-
15-
## Authorization
16-
17-
Waterline exposes a dashboard at the `/waterline` URL. By default, you will only be able to access this dashboard in the local environment. However, within your `app/Providers/WaterlineServiceProvider.php` file, there is an authorization gate definition. This authorization gate controls access to Waterline in non-local environments.
18-
19-
```
20-
Gate::define('viewWaterline', function ($user) {
21-
return in_array($user->email, [
22-
23-
]);
24-
});
25-
```
26-
27-
This will allow only the single admin user to access the Waterline UI.
28-
29-
30-
## Upgrading Waterline
31-
32-
After upgrading Waterline you must publish the latest assets.
33-
34-
```bash
35-
composer require laravel-workflow/waterline
36-
37-
php artisan waterline:publish
38-
```
39-
40-
## Dashboard View
41-
42-
![waterline_dashboard](https://user-images.githubusercontent.com/1130888/202864399-0bf0a3e7-4454-4a30-8fd2-e330b2460b76.png)
43-
44-
## Workflow View
45-
46-
![workflow](https://user-images.githubusercontent.com/1130888/202864523-edd88fce-0ce9-4e5a-a24c-38afeae4e057.png)
47-
48-
<sub><sup>"Laravel" is a registered trademark of Taylor Otwell. This project is not affiliated, associated, endorsed, or sponsored by Taylor Otwell, nor has it been reviewed, tested, or certified by Taylor Otwell. The use of the trademark "Laravel" is for informational and descriptive purposes only. Laravel Workflow is not officially related to the Laravel trademark or Taylor Otwell.</sup></sub>
1+
# Waterline
2+
3+
An elegant UI for monitoring [Laravel Workflows](https://github.com/laravel-workflow/laravel-workflow).
4+
5+
## Installation
6+
7+
This UI is installable via [Composer](https://getcomposer.org).
8+
9+
```bash
10+
composer require laravel-workflow/waterline
11+
12+
php artisan waterline:install
13+
```
14+
15+
## Authorization
16+
17+
Waterline exposes a dashboard at the `/waterline` URL. By default, you will only be able to access this dashboard in the local environment. However, within your `app/Providers/WaterlineServiceProvider.php` file, there is an authorization gate definition. This authorization gate controls access to Waterline in non-local environments.
18+
19+
```
20+
Gate::define('viewWaterline', function ($user) {
21+
return in_array($user->email, [
22+
23+
]);
24+
});
25+
```
26+
27+
This will allow only the single admin user to access the Waterline UI.
28+
29+
30+
## Upgrading Waterline
31+
32+
After upgrading Waterline you must publish the latest assets.
33+
34+
```bash
35+
composer require laravel-workflow/waterline
36+
37+
php artisan waterline:publish
38+
```
39+
40+
## Dashboard View
41+
42+
![waterline_dashboard](https://user-images.githubusercontent.com/1130888/202864399-0bf0a3e7-4454-4a30-8fd2-e330b2460b76.png)
43+
44+
## Workflow View
45+
46+
![workflow](https://user-images.githubusercontent.com/1130888/202864523-edd88fce-0ce9-4e5a-a24c-38afeae4e057.png)
47+
48+
## Development
49+
50+
1. Install dependencies:
51+
```bash
52+
composer install
53+
npm install
54+
```
55+
2. Build assets:
56+
```bash
57+
npm run production
58+
```
59+
3. Publish assets to testbench:
60+
```bash
61+
./vendor/bin/testbench waterline:publish
62+
```
63+
4. Run migrations:
64+
```bash
65+
./vendor/bin/testbench workbench:create-sqlite-db
66+
./vendor/bin/testbench migrate:fresh --database=sqlite
67+
```
68+
5. Start server:
69+
```bash
70+
composer run serve
71+
```
72+
6. Access dashboard:
73+
- Local: http://localhost:8000/waterline
74+
7. Create test workflow:
75+
```bash
76+
./vendor/bin/testbench workflow:create-test
77+
```
78+
8. Run queue worker:
79+
```bash
80+
./vendor/bin/testbench queue:work
81+
```
82+
83+
<sub><sup>"Laravel" is a registered trademark of Taylor Otwell. This project is not affiliated, associated, endorsed, or sponsored by Taylor Otwell, nor has it been reviewed, tested, or certified by Taylor Otwell. The use of the trademark "Laravel" is for informational and descriptive purposes only. Laravel Workflow is not officially related to the Laravel trademark or Taylor Otwell.</sup></sub>

app/Http/Controllers/WorkflowsController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
class WorkflowsController extends Controller
1111
{
1212
public function completed() {
13-
return config('workflows.stored_workflow_model', StoredWorkflow::class)::whereStatus('completed')
13+
return config('workflows.stored_workflow_model', StoredWorkflow::class)::whereIn('status', [
14+
'completed',
15+
'continued',
16+
])
1417
->orderByDesc('id')
1518
->paginate(50);
1619
}
@@ -33,7 +36,12 @@ public function running() {
3336
}
3437

3538
public function show($id) {
36-
$flow = config('workflows.stored_workflow_model', StoredWorkflow::class)::with(['exceptions', 'logs'])->find($id);
39+
$flow = config('workflows.stored_workflow_model', StoredWorkflow::class)::with([
40+
'continuedWorkflows',
41+
'exceptions',
42+
'logs',
43+
'parents'
44+
])->find($id);
3745

3846
return StoredWorkflowResource::make($flow);
3947
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Waterline\Http\Resources;
5+
6+
use Illuminate\Http\Resources\Json\JsonResource;
7+
8+
/**
9+
* @mixin \Illuminate\Database\Eloquent\Model
10+
*/
11+
class StoredWorkflowRelationshipResource extends JsonResource
12+
{
13+
public static $wrap = null;
14+
15+
public function toArray($request)
16+
{
17+
return [
18+
"id" => $this->id,
19+
"parent_workflow_id" => $this->pivot->parent_workflow_id,
20+
"parent_index" => $this->pivot->parent_index,
21+
"parent_now" => $this->pivot->parent_now,
22+
"child_workflow_id" => $this->pivot->child_workflow_id,
23+
];
24+
}
25+
}

app/Http/Resources/StoredWorkflowResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function toArray($request)
2727
"updated_at" => $this->updated_at,
2828
"logs" => StoredWorkflowLogResource::collection($this->logs),
2929
"exceptions" => StoredWorkflowExceptionResource::collection($this->exceptions),
30+
"parents" => StoredWorkflowRelationshipResource::collection($this->parents),
31+
"continuedWorkflows" => StoredWorkflowRelationshipResource::collection($this->continuedWorkflows),
3032
"chartData" => app(WorkflowToChartDataTransformer::class)->transform($this->resource),
3133
];
3234
}

composer.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"mongodb/laravel-mongodb": "^3.9",
2020
"mongodb/mongodb": "1.11",
2121
"orchestra/testbench": "^7.29",
22+
"orchestra/workbench": "^7.29",
2223
"phpunit/phpunit": "^9.5.10"
2324
},
2425
"autoload": {
@@ -28,16 +29,33 @@
2829
},
2930
"autoload-dev": {
3031
"psr-4": {
31-
"Waterline\\Tests\\": "tests/"
32+
"Waterline\\Tests\\": "tests/",
33+
"Workbench\\App\\": "workbench/app/",
34+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
35+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
3236
}
3337
},
3438
"scripts": {
39+
"post-autoload-dump": [
40+
"@clear",
41+
"@prepare",
42+
"@php ./vendor/bin/testbench package:discover --ansi"
43+
],
44+
"serve": [
45+
"Composer\\Config::disableProcessTimeout",
46+
"@build",
47+
"@php vendor/bin/testbench serve --ansi"
48+
],
49+
"build": "@php vendor/bin/testbench workbench:build --ansi",
3550
"test": "composer test-mongo && composer test-mssql && composer test-mysql && composer test-pgsql && composer test-sqlite",
51+
"test-all": "composer test-mongo && composer test-mssql && composer test-mysql && composer test-pgsql && composer test-sqlite",
3652
"test-mongo": "vendor/bin/phpunit --testdox --configuration=phpunit-mongo.xml",
3753
"test-mssql": "vendor/bin/phpunit --testdox --configuration=phpunit-mssql.xml",
3854
"test-mysql": "vendor/bin/phpunit --testdox --configuration=phpunit-mysql.xml",
3955
"test-pgsql": "vendor/bin/phpunit --testdox --configuration=phpunit-pgsql.xml",
40-
"test-sqlite": "vendor/bin/phpunit --testdox --configuration=phpunit-sqlite.xml"
56+
"test-sqlite": "vendor/bin/phpunit --testdox --configuration=phpunit-sqlite.xml",
57+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
58+
"prepare": "@php vendor/bin/testbench package:discover --ansi"
4159
},
4260
"extra": {
4361
"laravel": {

docker/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ ENV TZ=UTC
1414
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1515

1616
RUN apt-get update \
17-
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils \
17+
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git sqlite3 libcap2-bin libpng-dev python2 dnsutils sudo \
18+
&& apt-get install -y libnspr4 libnss3 libatk1.0-0 libatk-bridge2.0-0 libxkbcommon0 libatspi2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libcairo2 libpango-1.0-0 libasound2 chromium-browser \
1819
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
1920
&& echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
2021
&& apt-get update \
@@ -24,7 +25,7 @@ RUN apt-get update \
2425
php8.2-imap php8.2-mysql php8.2-mbstring \
2526
php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap \
2627
php8.2-intl php8.2-readline \
27-
php8.2-ldap php8.2-mongodb \
28+
php8.2-ldap \
2829
php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole \
2930
php8.2-memcached php8.2-pcov php8.2-xdebug \
3031
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
@@ -47,7 +48,11 @@ RUN apt-get update \
4748
&& echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
4849
&& echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> /etc/profile.d/mssql.sh \
4950
&& apt-get install -y php-pear php8.2-xml php8.2-dev \
51+
&& apt-get remove --purge -y php8.2-mongodb || true \
5052
&& pecl channel-update pecl.php.net \
53+
&& pecl install mongodb-1.15.0 \
54+
&& echo "extension=mongodb.so" > /etc/php/8.2/mods-available/mongodb.ini \
55+
&& phpenmod mongodb \
5156
&& pecl install sqlsrv \
5257
&& pecl install pdo_sqlsrv \
5358
&& echo "extension=sqlsrv.so" > /etc/php/8.2/mods-available/sqlsrv.ini \
@@ -63,9 +68,9 @@ RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.2
6368

6469
RUN groupadd --force -g 1000 sail
6570
RUN useradd -ms /bin/bash --no-user-group -g 1000 -u 1337 sail
71+
RUN echo "sail ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
6672

6773
COPY start-container /usr/local/bin/start-container
68-
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
6974
COPY php.ini /etc/php/8.2/cli/conf.d/99-sail.ini
7075
RUN chmod +x /usr/local/bin/start-container
7176

docker/start-container

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ chmod -R ugo+rw /.composer
1313
if [ $# -gt 0 ]; then
1414
exec gosu $WWWUSER "$@"
1515
else
16-
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
16+
# Just keep the container running
17+
exec sleep infinity
1718
fi

docker/supervisord.conf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ user=root
44
logfile=/var/log/supervisor/supervisord.log
55
pidfile=/var/run/supervisord.pid
66

7-
[program:php]
8-
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
7+
# Keep container running - dummy process
8+
[program:keep-alive]
9+
command=/bin/bash -c "while true; do sleep 3600; done"
910
user=sail
10-
environment=LARAVEL_SAIL="1"
11+
autorestart=true
1112
stdout_logfile=/dev/stdout
1213
stdout_logfile_maxbytes=0
1314
stderr_logfile=/dev/stderr

0 commit comments

Comments
 (0)