Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #32 from ibrunotome/issue/#25
Browse files Browse the repository at this point in the history
chore: upgrade to laravel 8.x
  • Loading branch information
ibrunotome authored Apr 18, 2021
2 parents feb36cc + ad74285 commit e44326d
Show file tree
Hide file tree
Showing 211 changed files with 4,092 additions and 3,375 deletions.
14 changes: 7 additions & 7 deletions .k8s/06-app-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
args:
- -c
- |
sleep 12
sleep 5
php artisan optimize
php artisan view:cache
ln -s public html
Expand All @@ -42,17 +42,17 @@ spec:
ports:
- containerPort: 9000
readinessProbe:
initialDelaySeconds: 20
periodSeconds: 10
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 5
failureThreshold: 3
successThreshold: 1
tcpSocket:
port: 9000
resources:
requests:
cpu: 50m
memory: 320Mi
cpu: 100m
memory: 512Mi
volumeMounts:
- name: static
mountPath: /static
Expand All @@ -68,8 +68,8 @@ spec:
"-credential_file=/secrets/cloudsql/cloudsqlproxy.json"]
resources:
requests:
cpu: 2m
memory: 8Mi
cpu: 10m
memory: 12Mi
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
Expand Down
23 changes: 17 additions & 6 deletions .k8s/09-queue-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ spec:
args:
- -c
- |
sleep 12
sleep 5
php artisan migrate --force
php artisan config:cache
php artisan optimize
php artisan view:cache
ln -s public html
ln -s /var/www /usr/share/nginx
cp -r /var/www/public/. /static
php artisan horizon --quiet
envFrom:
- secretRef:
name: env
resources:
requests:
cpu: 50m
memory: 320Mi
cpu: 100m
memory: 512Mi
volumeMounts:
- name: static
mountPath: /static

- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:latest
Expand All @@ -49,14 +56,18 @@ spec:
"-credential_file=/secrets/cloudsql/cloudsqlproxy.json"]
resources:
requests:
cpu: 2m
memory: 8Mi
cpu: 10m
memory: 12Mi
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true

volumes:
- name: static
nfs:
server: nfs-server.seguidores.svc.cluster.local
path: "/static"
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
6 changes: 3 additions & 3 deletions .k8s/11-schedule-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
resources:
requests:
cpu: 10m
memory: 32Mi
memory: 64Mi

- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:latest
Expand All @@ -43,8 +43,8 @@ spec:
"-credential_file=/secrets/cloudsql/cloudsqlproxy.json"]
resources:
requests:
cpu: 1m
memory: 8Mi
cpu: 10m
memory: 12Mi
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ spec:
- containerPort: 8080
resources:
requests:
cpu: 80m
memory: 320Mi
cpu: 100m
memory: 512Mi

- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:latest
Expand All @@ -50,8 +50,8 @@ spec:
"-credential_file=/secrets/cloudsql/cloudsqlproxy.json"]
resources:
requests:
cpu: 2m
memory: 8Mi
cpu: 10m
memory: 12Mi
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM composer:1.9.0 as build
FROM composer:2.0.12 as build
WORKDIR /app
COPY . /app
RUN composer install --prefer-dist --classmap-authoritative --no-dev

FROM php:7.4.3-apache-buster
FROM php:8.0.3-apache-buster
RUN docker-php-ext-install pdo pdo_pgsql pdo_mysql && pecl install redis

COPY --from=build /app /var/www/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@ opcache.enable = 1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli = 1

opcache.jit_buffer_size=100M
;opcache.preload=/var/www/storage/preload.php
;opcache.preload_user=www-data

Expand Down Expand Up @@ -2016,6 +2017,3 @@ zend_optimizerplus.enable_file_override = 1
; End:

extension = redis.so
extension = decimal.so
extension = grpc.so
extension = protobuf.so
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ibrunotome/php:7.4-fpm
FROM ibrunotome/php:8.0-fpm

ARG COMPOSER_FLAGS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@ opcache.enable = 1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli = 1

opcache.jit_buffer_size=100M
;opcache.preload=/var/www/storage/preload.php
;opcache.preload_user=www-data

Expand Down Expand Up @@ -2016,6 +2017,3 @@ zend_optimizerplus.enable_file_override = 1
; End:

extension = redis.so
extension = decimal.so
extension = grpc.so
extension = protobuf.so
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/4256471/88491449-4131da00-cf79-11ea-8620-04928cf52bf8.png" width="400px">
<img src="https://user-images.githubusercontent.com/4256471/115145753-888d5880-a029-11eb-9d26-37c8638823e7.png" width="400px">
<br>
A Laravel API starter kit collection using different structures.
</p>
Expand Down Expand Up @@ -31,7 +31,7 @@ This is a starter kit for your next API using Laravel, implemented with more tha
- Device authorization
- Etag
- Horizon
- Laravel [7.x](https://github.com/ibrunotome/laravel-api-templates/tree/v7.x), [6.x](https://github.com/ibrunotome/laravel-api-templates/tree/v6.x), [5.8](https://github.com/ibrunotome/laravel-api-templates/tree/v5.8)
- Laravel [8.x](https://github.com/ibrunotome/laravel-api-templates/tree/v8.x), [7.x](https://github.com/ibrunotome/laravel-api-templates/tree/v7.x), [6.x](https://github.com/ibrunotome/laravel-api-templates/tree/v6.x), [5.8](https://github.com/ibrunotome/laravel-api-templates/tree/v5.8)
- Login
- Login history
- Multiple localizations, preconfigured with en_US and pt_BR
Expand Down
1 change: 1 addition & 0 deletions default-structure/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APP_ENV=local
APP_KEY=base64:g1480dNK9TleD6NNmP0l29nPS0y8aYy/r9kBtlzmMmg=
APP_DEBUG=true
APP_URL=http://localhost
SPA_URL=http://localhost:3000

LOG_CHANNEL=stack

Expand Down
1 change: 1 addition & 0 deletions default-structure/.env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APP_ENV=testing
APP_KEY=base64:g1480dNK9TleD6NNmP0l29nPS0y8aYy/r9kBtlzmMmg=
APP_DEBUG=true
APP_URL=http://localhost
SPA_URL=http://localhost:3000

LOG_CHANNEL=stack

Expand Down
2 changes: 1 addition & 1 deletion default-structure/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ibrunotome/php:7.4-fpm
FROM ibrunotome/php:8.0-fpm

ARG COMPOSER_FLAGS

Expand Down
2 changes: 1 addition & 1 deletion default-structure/Dockerfile.testing
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ibrunotome/php:7.4-fpm
FROM ibrunotome/php:8.0-fpm

ARG COMPOSER_FLAGS

Expand Down
2 changes: 1 addition & 1 deletion default-structure/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Default Laravel structure

This API uses the default Laravel structure with all features explained [here](https://github.com/ibrunotome/laravel-api-templates#features).
This API uses the [default Laravel structure](https://laravel.com/docs/8.x/structure) with all features explained [here](https://github.com/ibrunotome/laravel-api-templates#features).
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace App\Contracts;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

interface AuthorizedDeviceRepository extends BaseRepository
{
public function doesNotHaveAuthorizedAnyDeviceYet(string $userId): bool;

public function findDeviceByCriteria(array $data);
public function findDeviceByCriteria(array $data): Model|Builder|null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use App\Http\Controllers\Controller;
use App\Models\AuthorizedDevice;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;

class AuthorizeDeviceController extends Controller
{
public function authorizeDevice(string $token)
public function authorizeDevice(string $token): JsonResponse
{
$authorizedDevice = AuthorizedDevice::query()
->withoutGlobalScopes()
Expand All @@ -31,7 +32,7 @@ public function authorizeDevice(string $token)
return $this->respondWithCustomData(['message' => $message], Response::HTTP_BAD_REQUEST);
}

public function destroy(string $id)
public function destroy(string $id): JsonResponse
{
$model = AuthorizedDevice::findOrFail($id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use App\Services\DisableAccountService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;

class DisableAccountController extends Controller
Expand All @@ -15,7 +16,7 @@ public function __construct(DisableAccountService $disableAccountService)
$this->disableAccountService = $disableAccountService;
}

public function disable($token)
public function disable($token): JsonResponse
{
$response = $this->disableAccountService->handle($token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
use App\Events\EmailWasVerifiedEvent;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;

class EmailVerificationController extends Controller
{
public function verify($token)
public function verify($token): JsonResponse
{
try {
$user = app(UserRepository::class)->findOneBy(['email_token_confirmation' => $token]);
Expand Down
26 changes: 12 additions & 14 deletions default-structure/app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Notification;
use Jenssegers\Agent\Agent;
use Sujip\Ipstack\Ipstack;

class LoginController extends Controller
{
Expand Down Expand Up @@ -56,7 +55,7 @@ protected function attemptLogin(Request $request)
*/
protected function sendLoginResponse(Request $request)
{
$user = auth()->user();
$user = $request->user();

try {
$this->checkUserIfIsActive($user, $request);
Expand Down Expand Up @@ -115,7 +114,7 @@ public function logout(Request $request)
Cache::forget($id);
Cache::tags('users:' . $id)->flush();

$this->guard()->logout(true);
$this->guard()->logout();
}

private function checkIfUserHasVerifiedEmail(User $user, Request $request)
Expand All @@ -140,7 +139,7 @@ private function getDeviceInfo(Request $request)
$agent->setUserAgent($request->userAgent());
$agent->setHttpHeaders($request->headers);

$ipstack = new Ipstack($request->ip());
$geoip = geoip($request->ip());

return [
'user_id' => auth()->id(),
Expand All @@ -150,16 +149,15 @@ private function getDeviceInfo(Request $request)
'platform_version' => $agent->version($agent->platform()),
'browser' => $agent->browser(),
'browser_version' => $agent->version($agent->browser()),
'city' => $ipstack->city(),
'region_code' => $ipstack->regionCode(),
'region_name' => $ipstack->region(),
'country_code' => $ipstack->countryCode(),
'country_name' => $ipstack->country(),
'continent_code' => $ipstack->continentCode(),
'continent_name' => $ipstack->continent(),
'latitude' => $ipstack->latitude(),
'longitude' => $ipstack->longitude(),
'zipcode' => $ipstack->zip(),
'city' => $geoip->getAttribute('city'),
'region_code' => $geoip->getAttribute('state'),
'region_name' => $geoip->getAttribute('state_name'),
'country_code' => $geoip->getAttribute('iso_code'),
'country_name' => $geoip->getAttribute('country'),
'continent_code' => $geoip->getAttribute('continent'),
'latitude' => $geoip->getAttribute('lat'),
'longitude' => $geoip->getAttribute('lon'),
'zipcode' => $geoip->getAttribute('postal_code'),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Rules\WeakPasswordRule;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand All @@ -32,7 +33,7 @@ class RegisterController extends Controller
*
* @return void
*/
public function __construct()
public function __construct(private UserRepository $userRepository)
{
$this->middleware('guest');
}
Expand Down Expand Up @@ -94,16 +95,10 @@ protected function validator(array $data)

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
* @throws \Exception
*/
protected function create(array $data)
protected function create(array $data): Model
{
$userRepository = app(UserRepository::class);

return $userRepository->store([
return $this->userRepository->store([
'email' => $data['email'],
'name' => $data['name'],
'email_token_confirmation' => Uuid::uuid4()->toString(),
Expand Down
Loading

0 comments on commit e44326d

Please sign in to comment.