Skip to content

Commit

Permalink
updated to php 7.4 and laravel 6.13, improved environment
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriy committed Feb 1, 2020
1 parent 6bf0291 commit 8e994c4
Show file tree
Hide file tree
Showing 73 changed files with 8,732 additions and 2,589 deletions.
10 changes: 10 additions & 0 deletions .bitbucket/dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

set -eu

# Add python pip and bash
apk add --no-cache py-pip bash make

# Install docker-compose via pip
pip install --no-cache-dir docker-compose~=1.23.0
docker-compose -v
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
command: |
make phpunit
- run:
name: Report code coverage
command: |
make report-code-coverage
- store_artifacts:
path: reports

Expand Down
2 changes: 2 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
Expand Down
2 changes: 2 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
Expand Down
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
Expand Down
7 changes: 7 additions & 0 deletions .env.test-ci
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Laravel App

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
release:
types: [published]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Build the docker images
run: docker-compose -f docker-compose-test-ci.yml build
- name: Start the docker images
run: make start-test
- name: Check running containers
run: docker ps -a
- name: Wait for database connection
run: make wait-for-db
- name: Run migrations
run: make drop-migrate
- name: Run seeds
run: make seed
- name: Run test suite
run: make phpunit
- name: Stop the docker images
run: make stop-test
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.3-fpm
FROM php:7.4-fpm

# set main params
ARG BUILD_ARGUMENT_DEBUG_ENABLED=false
Expand Down Expand Up @@ -50,7 +50,7 @@ COPY ./docker/$BUILD_ARGUMENT_ENV/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY ./docker/$BUILD_ARGUMENT_ENV/php.ini /usr/local/etc/php/php.ini

# install Xdebug in case development environment
COPY ./docker/other/do_we_need_xdebug.sh /tmp/
COPY ./docker/general/do_we_need_xdebug.sh /tmp/
COPY ./docker/dev/xdebug.ini /tmp/
RUN chmod u+x /tmp/do_we_need_xdebug.sh && /tmp/do_we_need_xdebug.sh

Expand All @@ -59,8 +59,8 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/

# add supervisor
RUN mkdir -p /var/log/supervisor
COPY --chown=root:root ./docker/other/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chown=root:root ./docker/other/cron /var/spool/cron/crontabs/root
COPY --chown=root:root ./docker/general/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chown=root:root ./docker/general/cron /var/spool/cron/crontabs/root
RUN chmod 0600 /var/spool/cron/crontabs/root

# set working directory
Expand Down
58 changes: 52 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
dir=${CURDIR}
project=-p laravel
service=laravel:latest
interactive:=$(shell [ -t 0 ] && echo 1)
ifneq ($(interactive),1)
optionT=-T
endif

start:
@docker-compose -f docker-compose.yml $(project) up -d
Expand Down Expand Up @@ -31,7 +35,10 @@ env-test-ci:
@make exec cmd="cp ./.env.test-ci ./.env"

ssh:
@docker-compose $(project) exec laravel bash
@docker-compose $(project) exec $(optionT) laravel bash

ssh-nginx:
@docker-compose $(project) exec nginx /bin/sh

ssh-supervisord:
@docker-compose $(project) exec supervisord bash
Expand All @@ -40,14 +47,17 @@ ssh-mysql:
@docker-compose $(project) exec mysql bash

exec:
@docker-compose $(project) exec laravel $$cmd
@docker-compose $(project) exec $(optionT) laravel $$cmd

clean:
rm -rf $(dir)/reports/*
exec-bash:
@docker-compose $(project) exec $(optionT) laravel bash -c "$(cmd)"

prepare:
report-prepare:
mkdir -p $(dir)/reports/coverage

report-clean:
rm -rf $(dir)/reports/*

wait-for-db:
@make exec cmd="php artisan db:wait"

Expand All @@ -67,6 +77,9 @@ info:
logs:
@docker logs -f laravel

logs-nginx:
@docker logs -f nginx

logs-supervisord:
@docker logs -f supervisord

Expand All @@ -88,4 +101,37 @@ seed:
@make exec cmd="php artisan db:seed --force"

phpunit:
@make exec cmd="vendor/bin/phpunit -c phpunit.xml --log-junit reports/phpunit.xml --coverage-html reports/coverage --coverage-clover reports/coverage.xml"
@make exec cmd="./vendor/bin/phpunit -c phpunit.xml --coverage-html reports/coverage --coverage-clover reports/clover.xml --log-junit reports/junit.xml"

###> php-coveralls ###
report-code-coverage: ## update code coverage on coveralls.io. Note: COVERALLS_REPO_TOKEN should be set on CI side.
@make exec-bash cmd="export COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN} && php ./vendor/bin/php-coveralls -v --coverage_clover reports/clover.xml --json_path reports/coverals.json"
###< php-coveralls ###

###> phpcs ###
phpcs: ## Run PHP CodeSniffer
@make exec-bash cmd="./vendor/bin/phpcs --version && ./vendor/bin/phpcs --standard=PSR2 --colors -p app"
###< phpcs ###

###> ecs ###
ecs: ## Run Easy Coding Standard
@make exec-bash cmd="error_reporting=0 ./vendor/bin/ecs --clear-cache check app"

ecs-fix: ## Run The Easy Coding Standard to fix issues
@make exec-bash cmd="error_reporting=0 ./vendor/bin/ecs --clear-cache --fix check app"
###< ecs ###

###> phpmetrics ###
phpmetrics:
@make exec cmd="make phpmetrics-process"

phpmetrics-process: ## Generates PhpMetrics static analysis, should be run inside symfony container
@mkdir -p reports/phpmetrics
@if [ ! -f reports/junit.xml ] ; then \
printf "\033[32;49mjunit.xml not found, running tests...\033[39m\n" ; \
./vendor/bin/phpunit -c phpunit.xml --coverage-html reports/coverage --coverage-clover reports/clover.xml --log-junit reports/junit.xml ; \
fi;
@echo "\033[32mRunning PhpMetrics\033[39m"
@php ./vendor/bin/phpmetrics --version
@./vendor/bin/phpmetrics --junit=reports/junit.xml --report-html=reports/phpmetrics .
###< phpmetrics ###
2 changes: 0 additions & 2 deletions app/Console/Commands/DbWaitDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class DbWaitDatabase extends Command
public function handle(DB $db): int
{
for ($i = 0; $i < 60; $i += self::WAIT_SLEEP_TIME) {

try {
$db::select('SHOW TABLES');
$this->info('Connection to the database is ok!');
Expand All @@ -52,7 +51,6 @@ public function handle(DB $db): int

continue;
}

}

$this->error('Can not connect to the database');
Expand Down
6 changes: 5 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Handler extends ExceptionHandler
*
* @param \Exception $exception
* @return void
*
* @throws \Exception
*/
public function report(Exception $exception)
{
Expand All @@ -42,7 +44,9 @@ public function report(Exception $exception)
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Exception
*/
public function render($request, Exception $exception)
{
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/ConfirmPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ConfirmsPasswords;

class ConfirmPasswordController extends Controller
Expand All @@ -25,7 +26,7 @@ class ConfirmPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
Expand All @@ -25,7 +26,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
Expand All @@ -28,7 +29,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
Expand All @@ -25,5 +26,5 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
Expand All @@ -25,7 +26,7 @@ class VerificationController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = RouteServiceProvider::HOME;

/**
* Create a new controller instance.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Kernel extends HttpKernel

'api' => [
'throttle:60,1',
'bindings',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Authenticate extends Middleware
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
* @return string|null
*/
protected function redirectTo($request)
{
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;

Expand All @@ -18,7 +19,7 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
return redirect(RouteServiceProvider::HOME);
}

return $next($request);
Expand Down
7 changes: 7 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class RouteServiceProvider extends ServiceProvider
*/
protected $namespace = 'App\Http\Controllers';

/**
* The path to the "home" route for your application.
*
* @var string
*/
public const HOME = '/home';

/**
* Define your route model bindings, pattern filters, etc.
*
Expand Down
Empty file modified artisan
100755 → 100644
Empty file.
Loading

0 comments on commit 8e994c4

Please sign in to comment.