Skip to content

Commit

Permalink
Merge pull request #20 from specialtactics/v1
Browse files Browse the repository at this point in the history
Version 1 PR (Open for ongoing review until finalised)
  • Loading branch information
specialtactics authored Jul 25, 2019
2 parents 19d7cc9 + d843f35 commit bc24701
Show file tree
Hide file tree
Showing 33 changed files with 2,966 additions and 43 deletions.
68 changes: 57 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###########################################################
#################### Laravel Configuration ################
###########################################################

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
Expand All @@ -13,24 +17,23 @@ JWT_TTL=1440

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_CONNECTION=pgsql
DB_HOST=your_project_postgres
DB_PORT=5432
DB_DATABASE=your_project_local
DB_DATABASE_TEST=${DB_DATABASE}_test
DB_USERNAME=laradock
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
CACHE_DRIVER=redis
QUEUE_DRIVER=redis

REDIS_HOST=127.0.0.1
REDIS_HOST=your_project_redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_DRIVER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
Expand All @@ -44,3 +47,46 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"


###########################################################
################ Third Party Integrations #################
###########################################################

# Put third-party integration env vars here

###########################################################
###################### Docker Setup #######################
###########################################################
# To extend the composer process
COMPOSER_PROCESS_TIMEOUT=300

# A fix for Windows users, to ensure the application path works
COMPOSE_CONVERT_WINDOWS_PATHS=0

# Choose storage path on your machine. For all storage systems
DATA_PATH_HOST=./storage/laradock/

### PHP ###########################################

# Select a PHP version of the Workspace and PHP-FPM containers (Does not apply to HHVM). Accepted values: 7.2 - 7.1 - 7.0 - 5.6 - 5.5
PHP_VERSION=7.3

# Enable Xdebug
PHP_XDEBUG_ENABLE=false
PHP_XDEBUG_REMOTE_CONNECT_BACK=false
# use this value when PHP_VERSION is above 7.2, ie. 7.3
PHP_XDEBUG_VERSION=-2.7.0

### NGINX #################################################

NGINX_HOST_LOG_PATH=./storage/logs/nginx/
NGINX_VIRTUAL_HOST=localhost
HTTPS_METHOD=noredirect

### POSTGRES ##############################################

POSTGRES_DB=your_project_local
POSTGRES_USER=laradock
POSTGRES_PASSWORD=secret
POSTGRES_PORT=5432
14 changes: 14 additions & 0 deletions app/Policies/BasePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@

namespace App\Policies;

use App\Models\User;
use Specialtactics\L5Api\Policies\RestfulModelPolicy;

class BasePolicy extends RestfulModelPolicy
{
/**
* Process 'global' authorisation rules
*
* @param $user
* @param $ability
* @return bool
*/
public function before(User $user, $ability)
{
if ($user->isAdmin()) {
return true;
}
}
}
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"specialtactics/l5-api": "~0"
"specialtactics/l5-api": "~1",
"predis/predis": "^1.1"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.4",
Expand Down Expand Up @@ -69,6 +70,7 @@
"lint": "./vendor/bin/phpcs",
"docs": [
"@php artisan ide-helper:generate --no-interaction"
]
],
"build": "./env/build.sh"
}
}
2 changes: 1 addition & 1 deletion config/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

'formats' => [

'json' => Dingo\Api\Http\Response\Format\Json::class,
'json' => Specialtactics\L5Api\Http\Response\Format\Json::class,

],

Expand Down
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'password' => 'secret',
'remember_token' => str_random(10),
];
});
5 changes: 5 additions & 0 deletions database/seeds/RoleTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public function runAlways()
'name' => 'admin',
'description' => 'Administrator Users',
]);

Role::firstOrCreate([
'name' => 'regular',
'description' => 'Regular Users',
]);
}

public function runFake()
Expand Down
14 changes: 13 additions & 1 deletion database/seeds/UserStorySeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

class UserStorySeeder extends BaseSeeder
{
/**
* Credentials
*/
const ADMIN_CREDENTIALS = ['[email protected]', 'secret'];

public function runFake()
{
// Grab all roles for reference
Expand All @@ -13,10 +18,17 @@ public function runFake()
// Create an admin user
factory(App\Models\User::class)->create([
'name' => 'Admin',
'email' => '[email protected]',
'email' => static::ADMIN_CREDENTIALS[0],
'primary_role' => $roles->where('name', 'admin')->first()->role_id,
]);

// Create regular user
factory(App\Models\User::class)->create([
'name' => 'Bob',
'email' => '[email protected]',
'primary_role' => $roles->where('name', 'regular')->first()->role_id,
]);

// Get some random roles to assign to users
$fakeRolesToAssignCount = 3;
$fakeRolesToAssign = RoleTableSeeder::getRandomRoles($fakeRolesToAssignCount);
Expand Down
91 changes: 91 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
version: '3.7'

services:

# Workspace Container
workspace:
container_name: your_project_workspace
build:
context: ./env/docker/workspace
args:
- PHP_VERSION=${PHP_VERSION}
- PHP_XDEBUG_ENABLE=${PHP_XDEBUG_ENABLE}
- PHP_XDEBUG_VERSION=${PHP_XDEBUG_VERSION}
- PHP_XDEBUG_REMOTE_CONNECT_BACK=${PHP_XDEBUG_REMOTE_CONNECT_BACK}
- COMPOSER_PROCESS_TIMEOUT=${COMPOSER_PROCESS_TIMEOUT}
volumes:
- ./:/var/www:cached
- ~/.ssh:/home/laradock/.ssh
- ~/.gitconfig:/home/laradock/.gitconfig
- ~/.config/composer:/home/laradock/.config/composer
- ~/.aws:/home/laradock/.aws
tty: true
networks:
- your_project_network

# PHP-FPM
php-fpm:
container_name: your_project_php_fpm
build:
context: ./env/docker/php-fpm
args:
- PHP_VERSION=${PHP_VERSION}
- PHP_XDEBUG_ENABLE=${PHP_XDEBUG_ENABLE}
- PHP_XDEBUG_VERSION=${PHP_XDEBUG_VERSION}
- PHP_XDEBUG_REMOTE_CONNECT_BACK=${PHP_XDEBUG_REMOTE_CONNECT_BACK}
volumes:
- ./:/var/www:cached
depends_on:
- workspace
networks:
- your_project_network

# NGINX
nginx:
container_name: your_project_nginx
build:
context: ./env/docker/nginx
volumes:
- ./:/var/www:cached
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
depends_on:
- php-fpm
- postgres
environment:
- HTTPS_METHOD=${HTTPS_METHOD}
ports:
- 80:80
networks:
- your_project_network

# PostgreSQL
postgres:
container_name: your_project_postgres
build:
context: ./env/docker/postgres
volumes:
- ${DATA_PATH_HOST}postgres:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
networks:
- your_project_network

# Redis
redis:
container_name: your_project_redis
image: "redis"
hostname: your_project_redis
networks:
- your_project_network

# Volumes configuration
volumes:
postgres:
driver: "local"

# Network configuration
networks:
your_project_network:
name: your_project_network
6 changes: 6 additions & 0 deletions env/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

composer install
composer dump-autoload --optimize
php artisan ide-helper:generate
php artisan ide-helper:meta
7 changes: 7 additions & 0 deletions env/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
/logs
/data
.env
/.project
.docker-sync
/jenkins/jenkins_home
12 changes: 12 additions & 0 deletions env/docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM nginx:alpine

COPY nginx.conf /etc/nginx/
COPY sites/laravel.conf /etc/nginx/conf.d/
COPY upstream.conf /etc/nginx/conf.d/
RUN rm -f /etc/nginx/conf.d/default.conf

RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 1000 -D -S -G www-data www-data && exit 0 ; exit 1

EXPOSE 80 443
34 changes: 34 additions & 0 deletions env/docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
user www-data;
worker_processes 4;
pid /run/nginx.pid;
# daemon off;

events {
worker_connections 2048;
multi_accept on;
use epoll;
}

http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
client_max_body_size 20M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout;
error_log /dev/stderr;
gzip on;
gzip_disable "msie6";

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*.conf;
open_file_cache off; # Disabled for issue 619
charset UTF-8;
}
37 changes: 37 additions & 0 deletions env/docker/nginx/sites/laravel.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
server {

listen 80;
listen [::]:80;

server_name localhost;
root /var/www/public;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}

error_log /var/log/nginx/laravel_error.log;
access_log /var/log/nginx/laravel_access.log;
}
3 changes: 3 additions & 0 deletions env/docker/nginx/upstream.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
upstream php-upstream {
server php-fpm:9000;
}
Loading

0 comments on commit bc24701

Please sign in to comment.