Skip to content

Commit 89f3514

Browse files
authored
Merge pull request #22 from ZanichelliEditore/develop
Develop
2 parents b663181 + d23e40b commit 89f3514

42 files changed

Lines changed: 3088 additions & 3457 deletions

Some content is hidden

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

.github/workflows/codecov.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ jobs:
2121
docker compose -f docker-compose.dev.yml up --build -d
2222
docker exec -i -u root buzzer_app composer install
2323
docker exec -i -u root buzzer_app php artisan key:generate
24-
docker exec -i -u root buzzer_app php artisan migrate
24+
- name: Init database
25+
run: docker exec -i -u root buzzer_app php artisan migrate
26+
env:
27+
DB_HOST: buzzer_db
28+
DB_PORT: ${{ job.services.mysql.ports['33064'] }}
2529
- name: Run tests and generate xml report
2630
run: docker exec -i -u root buzzer_app vendor/bin/phpunit --coverage-clover=coverage.xml
31+
env:
32+
DB_HOST: buzzer_db
33+
DB_PORT: ${{ job.services.mysql.ports['33064'] }}
2734
- name: Upload coverage reports to Codecov
2835
uses: codecov/codecov-action@v3
2936
env:

README.md

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,77 @@
1+
# Buzzer
2+
13
[![codecov](https://codecov.io/gh/ZanichelliEditore/buzzer/graph/badge.svg?token=8SXK5GTU0I)](https://codecov.io/gh/ZanichelliEditore/buzzer)
24

3-
# About the project
5+
## About the project
46

57
Buzzer is a Laravel app that establishes a mean of communication between different projects by leveraging the [publish/subscribe pattern](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern).
68

79
At the moment buzzer's authentication is setup to rely on Zanichelli's own IDP for authentication, but you can still test the app without authenticating.
810

9-
# Table of Contents
11+
## Table of Contents
1012

11-
- [Setup](#setup)
12-
- [GUI](#gui)
13-
- [Usage](#usage)
14-
- [Testing](#testing)
15-
- [API Documentation](#api-documentation)
16-
- [Logs](#logs)
17-
- [Infrastructure as Code](#infrastructure-as-code)
18-
- [How to contribute](#how-to-contribute)
13+
- [Setup](#setup)
14+
- [GUI](#gui)
15+
- [Usage](#usage)
16+
- [Testing](#testing)
17+
- [API Documentation](#api-documentation)
18+
- [Logs](#logs)
19+
- [Infrastructure as Code](#infrastructure-as-code)
20+
- [How to contribute](#how-to-contribute)
1921

20-
# Setup
22+
## Setup
2123

2224
Please note that **steps 2 to 5** are **optional** (but recommended). Follow them if you want to use **Docker containers** for local development.
2325

24-
1. Git clone the repository into your folder.
26+
1. Git clone the repository into your folder.
2527

26-
`git clone git@github.com:ZanichelliEditore/buzzer.git`
28+
`git clone git@github.com:ZanichelliEditore/buzzer.git`
2729

28-
2. Copy env.example to .env and fill the empty fields.
30+
2. Copy env.example to .env and fill the empty fields.
2931

3032
1. If you want to try the app without authenticating, set `USE_ZANICHELLI_IDP=false`
3133

3234
3. From the project's root folder, build your Docker images with `make rebuild` or:
3335

34-
`docker-compose -f docker-compose.dev.yml up --build -d`
36+
`docker-compose -f docker-compose.dev.yml up --build -d`
3537

36-
4. You must run the next few commands _inside_ the app's container. To enter the container, use `make shell` or:
38+
4. You must run the next few commands _inside_ the app's container. To enter the container, use `make shell` or:
3739

38-
`docker exec -it buzzer_app bash`
40+
`docker exec -it buzzer_app bash`
3941

40-
5. Install the required dependencies with composer
42+
5. Install the required dependencies with composer
4143

42-
`composer install`
44+
`composer install`
4345

44-
6. Generate a random application key
46+
6. Generate a random application key
4547

46-
`php artisan key:generate`
48+
`php artisan key:generate`
4749

4850
7. Generate passport keys
4951

50-
`php artisan passport:keys`
52+
`php artisan passport:keys`
5153

5254
8. To aid with development, you can also publish telescope assets
5355

54-
`php artisan telescope:publish`
56+
`php artisan telescope:publish`
5557

5658
9. Launch migrations and seeders to create and populate the database tables
5759

58-
`php artisan migrate --seed`
60+
`php artisan migrate --seed`
5961

60-
10. Exit the container shell with *ctrl+D* / *cmd+D* then run:
62+
10. Exit the container shell with _ctrl+D_ / _cmd+D_ then run:
6163
- `make npm_install`
6264
- `make npm_run`
6365

64-
## Accessing services
66+
### Accessing services
6567

66-
- **Web** the frontend admin app: http://localhost:8085
68+
- **Web** the frontend admin app: <http://localhost:8085>
6769

68-
- **phpMyAdmin**: http://localhost:8086
70+
- **phpMyAdmin**: <http://localhost:8086>
6971

70-
- **Telescope**: http://localhost:8085/telescope
72+
- **Telescope**: <http://localhost:8085/telescope>
7173

72-
## Starting and stopping containers
74+
### Starting and stopping containers
7375

7476
Once created, the containers can be **started** anytime with `make up` or with the following command:
7577

@@ -83,123 +85,123 @@ To off and remove container services, use `make down` or:
8385

8486
`docker-compose -f docker-compose.dev.yml down`
8587

86-
# GUI
88+
## GUI
8789

8890
The app consists of four main views
8991

90-
## Publishers
92+
### Publishers
9193

9294
Here you can manage all the publishers authorized to use your app. To create a publisher you need to provide:
9395

94-
- a meaningful name
95-
- the host from which the publisher will call buzzer
96-
- a username for the basic auth protecting incoming calls
96+
- a meaningful name
97+
- the host from which the publisher will call buzzer
98+
- a username for the basic auth protecting incoming calls
9799

98100
Once you create a publisher the app will provide you with a password for the basic auth.
99101

100-
## Subscribers
102+
### Subscribers
101103

102104
Here you can manage all the subscribers buzzer can contact. To create a subscriber you need to provide:
103105

104-
- a menaningful name
105-
- the host buzzer needs to call.
106+
- a menaningful name
107+
- the host buzzer needs to call.
106108

107109
Please note you only need to specify the host at this time, not the full endpoint.
108110

109-
## Channels
111+
### Channels
110112

111113
Here you can find and inspect all the configured channels. To create a channel you need to provide:
112114

113-
- a meaningful name
114-
- the channel's priority. Buzzer will look at this value to determine in what order it needs to dispatch incoming messages.
115+
- a meaningful name
116+
- the channel's priority. Buzzer will look at this value to determine in what order it needs to dispatch incoming messages.
115117

116118
By hitting the edit button on an existing channel you can access and manage the full list of publishers and subscribers interacting with the channel.
117119
Here is where you can configure the exact endpoints for your subscribers.
118120

119-
## Failed Jobs
121+
### Failed Jobs
120122

121123
Here you'll find a list of all failed jobs, with an option to retry or delete them. You can do this either for single jobs or for all failed jobs at once.
122124

123-
# Usage
125+
## Usage
124126

125127
To get a feel for how the app works, you can follow the next few steps for a quick test run from the GUI.
126128
The following guide assumes you already completed the steps outlined in the [Setup](#setup) section and buzzer is currently running.
127129

128-
1. if you open the app at http://localhost:8085, you'll notice there's already one channel, named "me". We'll send our message to this channel.
129-
2. open another terminal in the project root and use either `make shell` or `docker exec -it buzzer_app bash` to enter the app's container.
130-
1. run `php artisan queue:work` and leave the terminal open. This will ensure our message gets processed.
131-
3. inside /storage/logs you will find a file with today's date. Open it; we'll need it later. If you don't see it, don't worry. It will materialize as soon as the first log is generated.
132-
4. open http://localhost:8085/api/documentation
133-
1. search for /api/sendMessage and open it
134-
2. hit "Try it out" and a few more fields and controls will appear
135-
3. edit the request body so that the value for `"channel"` matches an existing channel. In our case, `"channel": "me"`
136-
4. hit "Execute"
137-
5. fill out the basic auth form using credentials from the test publisher: "test" and "pwd"
138-
5. we just sent our message to the three test APIs listed as subscribers for our channel!
139-
6. looking at the log file from step 3, notice how three logs have appeared. They're the result of a call to three different APIs. See the [#channels](#channels) section of the GUI for more information.
140-
141-
# Testing
130+
1. if you open the app at <http://localhost:8085>, you'll notice there's already one channel, named "me". We'll send our message to this channel.
131+
2. open another terminal in the project root and use either `make shell` or `docker exec -it buzzer_app bash` to enter the app's container.
132+
1. run `php artisan queue:work` and leave the terminal open. This will ensure our message gets processed.
133+
3. inside /storage/logs you will find a file with today's date. Open it; we'll need it later. If you don't see it, don't worry. It will materialize as soon as the first log is generated.
134+
4. open <http://localhost:8085/api/documentation>
135+
1. search for /api/sendMessage and open it
136+
2. hit "Try it out" and a few more fields and controls will appear
137+
3. edit the request body so that the value for `"channel"` matches an existing channel. In our case, `"channel": "me"`
138+
4. hit "Execute"
139+
5. fill out the basic auth form using credentials from the test publisher: "test" and "pwd"
140+
5. we just sent our message to the three test APIs listed as subscribers for our channel!
141+
6. looking at the log file from step 3, notice how three logs have appeared. They're the result of a call to three different APIs. See the [#channels](#channels) section of the GUI for more information.
142+
143+
## Testing
142144

143145
You can run tests using the PHPUnit binary located in the vendor directory
144146

145147
- Run all tests
146-
- `docker exec -it buzzer_app vendor/bin/phpunit` or `make run_tests`
148+
- `docker exec -it buzzer_app vendor/bin/phpunit` or `make run_tests`
147149

148150
- Run every method of a specific test class
149-
- `docker exec -it buzzer_app vendor/bin/phpunit tests/Feature/TestClassName` or `make run_tests tests/Feature/TestClassName`
151+
- `docker exec -it buzzer_app vendor/bin/phpunit tests/Feature/TestClassName` or `make run_tests tests/Feature/TestClassName`
150152

151153
- Run a single method of a specific test class
152-
- `docker exec -it buzzer_app vendor/bin/phpunit --filter testMethodName tests/Feature/TestClassName` or `make run_tests --filter testMethodName tests/Feature/TestClassName`
154+
- `docker exec -it buzzer_app vendor/bin/phpunit --filter testMethodName tests/Feature/TestClassName` or `make run_tests --filter testMethodName tests/Feature/TestClassName`
153155

154156
- To generate the HTML code coverage report pass the following option: `--coverage-html tmp/coverage`
155-
- `docker exec buzzer_app vendor/bin/phpunit --coverage-html tmp/coverage` or `make run_coverage`
157+
- `docker exec buzzer_app vendor/bin/phpunit --coverage-html tmp/coverage` or `make run_coverage`
156158
- navigate to tmp/coverage and open the included `index.html` file in your browser
157159

158-
- To generate the HTML code coverage report pass the following option: `--coverage-html tmp/coverage`
159-
- `docker exec --coverage-html tmp/coverage appContainerName vendor/bin/phpunit tests/Feature/TestClassName` or `make run_coverage`
160+
- To generate the HTML code coverage report pass the following option: `--coverage-html tmp/coverage`
161+
- `docker exec --coverage-html tmp/coverage appContainerName vendor/bin/phpunit tests/Feature/TestClassName` or `make run_coverage`
160162

161-
# API Documentation
163+
## API Documentation
162164

163-
## Generate documentation
165+
### Generate documentation
164166

165167
This project uses Swagger-php to generate API documentation, following the OpenAPI specifications.
166168

167-
- Swagger-PHP reference: http://zircote.com/swagger-php/Getting-started.html
169+
- Swagger-PHP reference: <http://zircote.com/swagger-php/Getting-started.html>
168170

169-
- OpenAPI specification: https://swagger.io/docs/specification/basic-structure/
171+
- OpenAPI specification: <https://swagger.io/docs/specification/basic-structure/>
170172

171-
## View documentation
173+
### View documentation
172174

173-
Once you've built your containers, the swagger documentation is available at http://localhost:8085/api/documentation
175+
Once you've built your containers, the swagger documentation is available at <http://localhost:8085/api/documentation>
174176

175-
# Logs
177+
## Logs
176178

177179
Buzzer includes a filebeat instance that is set up to communicate with a logstash pipeline.
178180
If you or your organization have a running logstash instance, you can connect it by changing the `hosts` IP/port inside the .yml files in `docker/filebeat`
179181

180-
# Infrastructure as Code
182+
## Infrastructure as Code
181183

182184
We use terraform, jenkins and ansible to manage our infrastructure on AWS via code.
183185

184186
As terraform configurations were highly customized to address our specific needs, we decided to exclude them from the current repository to avoid unnecessary clutter.
185187

186-
## Jenkins
188+
### Jenkins
187189

188190
You need to add the following build parameters to your jenkins pipeline:
189191

190-
- `deploy_branch`: the branch you're deploying
191-
- `aws_account`: the ID of your AWS account
192+
- `deploy_branch`: the branch you're deploying
193+
- `aws_account`: the ID of your AWS account
192194

193195
Our pipelines are configured to act on AWS through the `ContinuousIntegrationAccessRole` role on the provided account. You should set up a similar role or change the name inside the jenkinsfiles.
194196

195197
Feel free to also change the region, which is currently setup as `eu-west-1`.
196198

197-
# How to Contribute
199+
## How to Contribute
198200

199-
## Did you find a bug?
201+
### Did you find a bug?
200202

201-
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/ZanichelliEditore/buzzer/issues).
203+
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/ZanichelliEditore/buzzer/issues).
202204

203-
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/ZanichelliEditore/buzzer/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible and, wherever possible, a **code sample** demonstrating the expected behavior that is not occurring.
205+
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/ZanichelliEditore/buzzer/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible and, wherever possible, a **code sample** demonstrating the expected behavior that is not occurring.
204206

205-
- We expect all who interact with the project to follow the [Contributor Covenant Code of Conduct](https://github.com/ZanichelliEditore/buzzer/blob/master/CODE-OF-CONDUCT.md)
207+
- We expect all who interact with the project to follow the [Contributor Covenant Code of Conduct](https://github.com/ZanichelliEditore/buzzer/blob/master/CODE-OF-CONDUCT.md)

app-prod.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.1-fpm
1+
FROM php:8.4-fpm
22

33
RUN apt-get update && apt-get install -y wget libmcrypt-dev mariadb-client \
44
xvfb libfontconfig wkhtmltopdf libxslt1-dev libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 gnupg libcanberra-gtk-module\

app/Http/Middleware/RedirectIfAuthenticated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RedirectIfAuthenticated
1515
* @param string|null $guard
1616
* @return mixed
1717
*/
18-
public function handle($request, Closure $next, $guard = null)
18+
public function handle(\Illuminate\Http\Request $request, Closure $next, ?string $guard = null)
1919
{
2020
if (Auth::guard($guard)->check()) {
2121
return redirect('/home');

app/Models/User.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class User extends Authenticatable
1515
* @var array
1616
*/
1717
protected $fillable = [
18-
'name', 'email', 'password',
18+
'name',
19+
'email',
20+
'password',
1921
];
2022

2123
/**
@@ -24,15 +26,19 @@ class User extends Authenticatable
2426
* @var array
2527
*/
2628
protected $hidden = [
27-
'password', 'remember_token',
29+
'password',
30+
'remember_token',
2831
];
2932

3033
/**
31-
* The attributes that should be cast to native types.
34+
* Get the attributes that should be cast.
3235
*
33-
* @var array
36+
* @return array<string, string>
3437
*/
35-
protected $casts = [
36-
'email_verified_at' => 'datetime',
37-
];
38+
protected function casts(): array
39+
{
40+
return [
41+
'email_verified_at' => 'datetime',
42+
];
43+
}
3844
}

app/Providers/EventServiceProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Providers;
44

55
use Illuminate\Auth\Events\Registered;
6-
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
76
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
87

98
class EventServiceProvider extends ServiceProvider
@@ -14,9 +13,7 @@ class EventServiceProvider extends ServiceProvider
1413
* @var array
1514
*/
1615
protected $listen = [
17-
Registered::class => [
18-
SendEmailVerificationNotification::class,
19-
],
16+
Registered::class => [],
2017
'App\Events\SendMessageEvent' => [
2118
'App\Listeners\SendMessageListener',
2219
],

0 commit comments

Comments
 (0)