Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bf0ce36

Browse files
author
José Fernando Cordova
committed
Merge branch 'feature/refactoring' into origin/develop
2 parents 7e1c4ea + 1ba5172 commit bf0ce36

26 files changed

+864
-552
lines changed

‎.docker/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/local-mysql-datadir/
2+
/xdebug.ini

‎.docker/Dockerfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apt-get -y install libmcrypt-dev libzzip-dev zziplib-bin zlib1g-dev
99

1010
# MySQL client for Initial Tasks
1111
RUN apt-get update &&\
12-
apt-get install -y mysql-client
12+
apt-get install -y mysql-client
1313

1414
# docker-php ext-install:
1515
RUN docker-php-ext-install mcrypt
@@ -37,6 +37,20 @@ COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
3737
COPY ./composer.json ./composer.json
3838
COPY ./composer.lock ./composer.lock
3939

40+
RUN composer install --no-dev --no-interaction --no-scripts
41+
42+
# entrypoint
43+
COPY .docker/docker-php-entrypoint /usr/local/bin/
44+
4045
# www-data:
4146
RUN chown -R www-data:www-data ./ && a2enmod rewrite
47+
RUN chown -R www-data:www-data storage
48+
49+
RUN chmod 755 /usr/local/bin/docker-php-entrypoint
50+
51+
# mode-root:
4252
USER root
53+
54+
HEALTHCHECK --interval=50s \
55+
--timeout=600s \
56+
CMD curl -f http://localhost/api/hello || exit 1

‎.docker/docker-php-entrypoint

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# ENVIRONMENT VARIABLES ----------------------------------
4+
cp /docker-laravel-api-dev/.env.example /docker-laravel-api-dev/.env
5+
6+
# Xdebug ----------------------------------------------------
7+
if [ "${XDEBUG_MODE}" == 1 ] ; then
8+
mkdir -p /docker-laravel-api-dev/.docker/local-mysql-datadir
9+
echo 'Installs require-dev dependencies'
10+
composer install --no-scripts
11+
echo 'Permissions'
12+
chmod 777 -R /docker-laravel-api-dev/storage
13+
echo 'Installing XDebug...'
14+
pecl install xdebug && docker-php-ext-enable xdebug
15+
echo 'XDebug installed!'
16+
fi
17+
18+
# WAIT FOR MYSQL READY -----------------------------------
19+
echo 'Checking MySql...'
20+
while !(mysqladmin ping --host=$DB_HOST)
21+
do
22+
sleep 1
23+
echo 'Waiting for MySql...'
24+
done
25+
echo 'MySql ready!'
26+
27+
# MIGRATIONS -----------------------------------
28+
echo 'Running Migrations...'
29+
cd /docker-laravel-api-dev
30+
php artisan key:generate
31+
php artisan jwt:secret -f
32+
php artisan migrate
33+
echo 'Migrations done!'
34+
35+
# APACHE -----------------------------------
36+
# first arg is `-f` or `--some-option`
37+
if [ "${1#-}" != "1ドル" ]; then
38+
set -- apache2-foreground "$@"
39+
fi
40+
exec "$@"

‎.docker/xdebug.ini.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
2+
3+
xdebug.remote_enable=1
4+
xdebug.remote_host=XXX.XXX.XXX.XXX
5+
xdebug.remote_log="/tmp/xdebug.log"

‎.gitignore

100644100755
File mode changed.

‎.travis.yml

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ services:
1111

1212
before_script:
1313
- chmod +x ./scripts/runtests.sh
14-
- docker-compose -f docker-compose.yml up --build -d
14+
- docker-compose -f docker-compose-dev.yml up --build -d
1515
- docker ps -a
1616
- sleep 30 # wait for Mysql to start
1717

1818
script: ./scripts/runtests.sh
1919

2020
after_script:
21-
- docker-compose -f docker-compose.yml down
21+
- docker-compose -f docker-compose-dev.yml down

‎LICENSE.md

100644100755
File mode changed.

‎README.md

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,50 @@
66
* API Laravel Boilerplate 5.5
77
* Apache 2
88
* MySQL
9+
* Xdebug
910
* Docker
10-
11-
## Docker Environments
1211

13-
### Swarm Mode
14-
Clone this respository and run the following commands:
15-
```bash
16-
cd docker-laravel-api-dev/
17-
# Creating mount folder
18-
mkdir .docker/local-mysql-datadir
19-
docker stack deploy -c docker-compose.yml docker-laravel-api-dev
20-
# wait for it and follow the docker instructions!...
21-
```
22-
### Docker Compose
23-
Clone this respository and run the following commands:
24-
```bash
25-
cd docker-laravel-api-dev/
26-
docker-compose -f docker-compose.yml up --build -d
27-
# wait for it to build and follow the docker instructions!...
28-
```
29-
### PWD
30-
With Play with Docker and following the docker instructions, it is easy to deploy and test this environment!
12+
## Environments
13+
14+
To deploy this api boilerplate, there are three options (yaml) and Docker environments with instructions that you should consider:
3115

32-
[![Try in PWD](https://cdn.rawgit.com/play-with-docker/stacks/cff22438/assets/images/button.png)](http://play-with-docker.com?stack=https://raw.githubusercontent.com/jfernancordova/docker-laravel-api-dev/master/docker-compose-pwd.yml)
16+
### Dev or Local Mode
17+
* docker-compose-dev.yml: generate automatically folders and require-dev dependencies on your local workspace including Xdebug, however the yaml file has a key called:
18+
"XDEBUG_MODE", this yaml by default has the value true (1) to install it.
3319

34-
## Docker Instructions
20+
You can appreciate the dependencies generated automatically on your workspace!
21+
22+
### Play with Docker Mode
23+
* docker-compose-pwd.yml: you can [![Play With Docker](https://cdn.rawgit.com/play-with-docker/stacks/cff22438/assets/images/button.png)](http://play-with-docker.com?stack=https://raw.githubusercontent.com/jfernancordova/docker-laravel-api-dev/feature/refactoring/docker-compose-pwd.yml), to visualize this environment and test it, however you should see the container lists to verify the HEALTHCHECK.
3524

36-
### Execute Laravel Pre-requisites
37-
In the root directory:
3825
```bash
3926
# container lists
4027
docker ps
41-
# next, execute an interactive bash shell on the php container.
42-
docker container exec -t -i [dockerlaravelapidev_php_1 or container Id] bash
28+
# make sure that the docker dockerlaravelapidev_php_1 or php container is (healthy),
29+
normally the process begins in starting mode (health: starting),
4330
```
44-
#### Run the following commands:
31+
### Production Mode
32+
* docker-compose-prod.yml: if you are going to use this yaml, make sure to generate the migrations before!, however you can modify the entrypoint to generate them.
33+
34+
## Docker Environments
4535

46-
##### Compose and Swarm Mode
36+
### Swarm Mode
37+
Clone this respository and run the following commands:
4738
```bash
48-
composer install && cp .env.example .env && php artisan key:generate && php artisan migrate
49-
chmod 755 -R storage
50-
# forward to the port 80, go to localhost and enjoy!...
39+
cd docker-laravel-api-dev/
40+
docker stack deploy -c docker-compose-dev.yml docker-laravel-api-dev
41+
# wait for the HEALTHCHECK in healthy mode
5142
```
52-
##### Play With Docker (PWD)
43+
44+
### Docker Compose
45+
Clone this respository and run the following commands:
5346
```bash
54-
composer install && php artisan migrate
55-
# forward to the port 80, go to localhost and enjoy!...
47+
cd docker-laravel-api-dev/
48+
docker-compose -f docker-compose-dev.yml up --build -d
49+
or to see the logs
50+
docker-compose -f docker-compose-dev.yml up
51+
# wait for the HEALTHCHECK in healthy mode
5652
```
5753

58-
### How to fix Error: laravel.log could not be opened?
59-
In the root directory or inside the container php:
60-
<pre><code>chmod -R 775 storage </code></pre>
61-
* 7 - Owner can write
62-
* 7 - Group can write
63-
* 5 - Others cannot write!
64-
Reference:
65-
https://stackoverflow.com/questions/23411520/how-to-fix-error-laravel-log-could-not-be-opened
66-
67-
### API Boilerplate Reference
54+
## API Boilerplate Reference
6855
https://github.com/francescomalatesta/laravel-api-boilerplate-jwt/blob/master/readme.md
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"info": {
3+
"name": "apiLaravelDocker",
4+
"_postman_id": "7d5f25d3-239f-4595-aa94-94380953b7b8",
5+
"description": "",
6+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
7+
},
8+
"item": [
9+
{
10+
"name": "http://127.0.0.1/api/auth/signup",
11+
"request": {
12+
"method": "POST",
13+
"header": [],
14+
"body": {
15+
"mode": "formdata",
16+
"formdata": [
17+
{
18+
"key": "name",
19+
"value": "José Fernando Cordova ",
20+
"description": "",
21+
"type": "text"
22+
},
23+
{
24+
"key": "email",
25+
"value": "jfernancordova@gmail.com",
26+
"description": "",
27+
"type": "text"
28+
},
29+
{
30+
"key": "password",
31+
"value": "apiLaravelDocker",
32+
"description": "",
33+
"type": "text"
34+
}
35+
]
36+
},
37+
"url": {
38+
"raw": "http://127.0.0.1/api/auth/signup",
39+
"protocol": "http",
40+
"host": [
41+
"127",
42+
"0",
43+
"0",
44+
"1"
45+
],
46+
"path": [
47+
"api",
48+
"auth",
49+
"signup"
50+
]
51+
},
52+
"description": ""
53+
},
54+
"response": []
55+
},
56+
{
57+
"name": "http://127.0.0.1/api/auth/login",
58+
"request": {
59+
"method": "POST",
60+
"header": [],
61+
"body": {
62+
"mode": "formdata",
63+
"formdata": [
64+
{
65+
"key": "email",
66+
"value": "jfernancordova3@gmail.com",
67+
"description": "",
68+
"type": "text"
69+
},
70+
{
71+
"key": "password",
72+
"value": "apiLaravelDocker",
73+
"description": "",
74+
"type": "text"
75+
}
76+
]
77+
},
78+
"url": {
79+
"raw": "http://127.0.0.1/api/auth/login",
80+
"protocol": "http",
81+
"host": [
82+
"127",
83+
"0",
84+
"0",
85+
"1"
86+
],
87+
"path": [
88+
"api",
89+
"auth",
90+
"login"
91+
]
92+
},
93+
"description": ""
94+
},
95+
"response": []
96+
}
97+
]
98+
}

‎app/Api/V1/Controllers/ForgotPasswordController.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,31 @@
44

55
use App\User;
66
use App\Http\Controllers\Controller;
7-
use Illuminate\Http\JsonResponse;
87
use Illuminate\Support\Facades\Password;
98
use App\Api\V1\Requests\ForgotPasswordRequest;
109
use Symfony\Component\HttpKernel\Exception\HttpException;
1110
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12-
use App\Helpers\ApiResponse;
1311

1412
class ForgotPasswordController extends Controller
1513
{
16-
/**
17-
* @param ForgotPasswordRequest $request
18-
* @return \Illuminate\Http\JsonResponse
19-
*/
20-
public function sendResetEmail(ForgotPasswordRequest $request): JsonResponse
14+
public function sendResetEmail(ForgotPasswordRequest $request)
2115
{
2216
$user = User::where('email', '=', $request->get('email'))->first();
23-
if (!$user) {
17+
18+
if(!$user) {
2419
throw new NotFoundHttpException();
2520
}
2621

2722
$broker = $this->getPasswordBroker();
2823
$sendingResponse = $broker->sendResetLink($request->only('email'));
2924

30-
if($sendingResponse !== Password::RESET_LINK_SENT) {
25+
if($sendingResponse !== Password::RESET_LINK_SENT) {
3126
throw new HttpException(500);
3227
}
3328

34-
ApiResponse::response(200, 'Ok');
29+
return response()->json([
30+
'status' => 'ok'
31+
], 200);
3532
}
3633

3734
/**
@@ -43,4 +40,4 @@ private function getPasswordBroker()
4340
{
4441
return Password::broker();
4542
}
46-
}
43+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /