Skip to content

Commit 9bb31e4

Browse files
author
José Fernando Cordova
committed
Merge branch 'develop'
2 parents 572d1da + a04e09a commit 9bb31e4

26 files changed

+883
-550
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: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,71 @@
77
* API Laravel Boilerplate 5.5
88
* Apache 2
99
* MySQL
10+
* Xdebug
1011
* Docker
12+
13+
You can manage a RestFull API in the fastest, simplest and funniest way! and with open source code dependencies.
14+
15+
However you can contribute for a better performance, the goal is to focus on the code avoiding the configurations and having docker installed.
16+
17+
### Prerequisites
18+
19+
* [Docker](https://docs.docker.com/install/)
20+
* [Docker Compose](https://docs.docker.com/compose/install/)
21+
22+
## Environments
23+
24+
### Dev or Local Mode
25+
* docker-compose-dev.yml: generate automatically folders and require-dev dependencies on your local workspace including Xdebug.
26+
Note: the yaml file has a key called:"XDEBUG_MODE", this yaml by default has the value true (1) to install it.
27+
28+
You can appreciate the dependencies generated automatically on your workspace!
29+
30+
### Play with Docker Mode
31+
32+
[![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)
33+
34+
* docker-compose-pwd.yml: you can use it to visualize this environment and test it, however you should see the container lists to verify the HEALTHCHECK.
35+
36+
```bash
37+
# container lists
38+
docker ps
39+
# make sure that the docker dockerlaravelapidev_php_1 or php container is (healthy),
40+
normally the process begins in starting mode (health: starting),
41+
```
42+
### Production Mode
43+
* docker-compose-prod.yml: if you are going to use this yaml, make sure to generate the migrations before!,you can modify the entrypoint to generate them.
44+
45+
## Deployment
1146

12-
## Docker Environments
47+
### Docker Environments
48+
49+
Clone this respository and run the following commands based on your orchestrator;
1350

1451
### Swarm Mode
1552
Clone this respository and run the following commands:
1653
```bash
1754
cd docker-laravel-api-dev/
18-
# Creating mount folder
19-
mkdir .docker/local-mysql-datadir
20-
docker stack deploy -c docker-compose.yml docker-laravel-api-dev
21-
# wait for it and follow the docker instructions!...
55+
docker stack deploy -c docker-compose-dev.yml docker-laravel-api-dev
56+
# wait for the HEALTHCHECK in healthy mode
2257
```
58+
2359
### Docker Compose
2460
Clone this respository and run the following commands:
2561
```bash
2662
cd docker-laravel-api-dev/
27-
docker-compose -f docker-compose.yml up --build -d
28-
# wait for it to build and follow the docker instructions!...
63+
docker-compose -f docker-compose-dev.yml up --build -d
64+
or to see the logs
65+
docker-compose -f docker-compose-dev.yml up
66+
# wait for the HEALTHCHECK in healthy mode
2967
```
30-
### PWD
31-
With Play with Docker and following the docker instructions, it is easy to deploy and test this environment!
68+
## Running the tests
3269

33-
[![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)
34-
35-
## Docker Instructions
36-
37-
### Execute Laravel Pre-requisites
38-
In the root directory:
39-
```bash
40-
# container lists
41-
docker ps
42-
# next, execute an interactive bash shell on the php container.
43-
docker container exec -t -i [dockerlaravelapidev_php_1 or container Id] bash
44-
```
45-
#### Run the following commands:
70+
You have a [Travis](https://travis-ci.org/) Pipeline to apply Continous Integration, and other technology to test this environment.
4671

47-
##### Compose and Swarm Mode
48-
```bash
49-
composer install && cp .env.example .env && php artisan key:generate && php artisan migrate
50-
chmod 755 -R storage
51-
# forward to the port 80, go to localhost and enjoy!...
52-
```
53-
##### Play With Docker (PWD)
54-
```bash
55-
composer install && php artisan migrate
56-
# forward to the port 80, go to localhost and enjoy!...
57-
```
72+
You can modify the runtests.sh from the [scripts folder](https://raw.githubusercontent.com/jfernancordova/docker-laravel-api-dev/master/scripts/runtests.sh)
5873

59-
### How to fix Error: laravel.log could not be opened?
60-
In the root directory or inside the container php:
61-
<pre><code>chmod -R 775 storage </code></pre>
62-
* 7 - Owner can write
63-
* 7 - Group can write
64-
* 5 - Others cannot write!
65-
Reference:
66-
https://stackoverflow.com/questions/23411520/how-to-fix-error-laravel-log-could-not-be-opened
74+
Insert jobs, instructions, builds in [this pipeline](https://raw.githubusercontent.com/jfernancordova/docker-laravel-api-dev/master/.travis.yml)
6775

68-
### API Boilerplate Reference
76+
## API Boilerplate Reference
6977
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+
}

app/Api/V1/Controllers/LoginController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace App\Api\V1\Controllers;
44

5-
use App\Helpers\ApiResponse;
6-
use Illuminate\Http\JsonResponse;
75
use Symfony\Component\HttpKernel\Exception\HttpException;
86
use Tymon\JWTAuth\JWTAuth;
97
use App\Http\Controllers\Controller;
@@ -21,7 +19,7 @@ class LoginController extends Controller
2119
* @param JWTAuth $JWTAuth
2220
* @return \Illuminate\Http\JsonResponse
2321
*/
24-
public function login(LoginRequest $request, JWTAuth $JWTAuth): JsonResponse
22+
public function login(LoginRequest $request, JWTAuth $JWTAuth)
2523
{
2624
$credentials = $request->only(['email', 'password']);
2725

@@ -36,9 +34,11 @@ public function login(LoginRequest $request, JWTAuth $JWTAuth): JsonResponse
3634
throw new HttpException(500);
3735
}
3836

39-
return ApiResponse::response(200, 'Ok', [
40-
'token' => $token,
41-
'expires_in' => Auth::guard()->factory()->getTTL() * 60
42-
]);
37+
return response()
38+
->json([
39+
'status' => 'ok',
40+
'token' => $token,
41+
'expires_in' => Auth::guard()->factory()->getTTL() * 60
42+
]);
4343
}
44-
}
44+
}

0 commit comments

Comments
 (0)