From d5ba1de40392ebf9dc65fd270da2ad3aec7d28d3 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Tue, 8 Mar 2022 11:28:49 +0100 Subject: [PATCH] #48 - deployment --- .env.example | 1 - .gitignore | 1 + Procfile | 4 +- app/Eloquent/Observers/UserObserver.php | 16 +-- .../Http/Middleware/TrustProxies.php | 10 +- composer.json | 2 +- composer.lock | 136 +++++++++--------- config/database.php | 2 - config/google-calendar.php | 7 +- docker/dev/php/Dockerfile | 9 +- nginx.conf | 10 ++ readme.md | 2 +- resources/js/Composables/statusInfo.js | 2 +- resources/js/Pages/VacationRequest/Create.vue | 2 +- 14 files changed, 102 insertions(+), 102 deletions(-) create mode 100644 nginx.conf diff --git a/.env.example b/.env.example index afb75cb..fe3a597 100644 --- a/.env.example +++ b/.env.example @@ -30,7 +30,6 @@ DOCKER_TEST_DB_PASSWORD=${DB_PASSWORD} DOCKER_TEST_DB_ROOT_PASSWORD=${DB_ROOT_PASSWORD} REDIS_PORT=6379 -REDIS_CLIENT=predis REDIS_HOST=toby-redis XDG_CONFIG_HOME=/tmp diff --git a/.gitignore b/.gitignore index 63cf7ed..569e675 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,6 @@ Homestead.json Homestead.yaml npm-debug.log yarn-error.log +google-credentials.json .idea/ .composer diff --git a/Procfile b/Procfile index 48aab52..da552c0 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,3 @@ -web: vendor/bin/heroku-php-apache2 public/ +web: vendor/bin/heroku-php-nginx -C nginx.conf public/ +release: php artisan migrate --force && php artisan cache:clear && php artisan config:cache +worker: php artisan queue:work diff --git a/app/Eloquent/Observers/UserObserver.php b/app/Eloquent/Observers/UserObserver.php index 33a76e5..6921550 100644 --- a/app/Eloquent/Observers/UserObserver.php +++ b/app/Eloquent/Observers/UserObserver.php @@ -4,19 +4,19 @@ declare(strict_types=1); namespace Toby\Eloquent\Observers; -use Toby\Eloquent\Helpers\YearPeriodRetriever; use Toby\Eloquent\Models\User; +use Toby\Eloquent\Models\YearPeriod; class UserObserver { - public function __construct( - protected YearPeriodRetriever $yearPeriodRetriever, - ) {} - public function created(User $user): void { - $user->vacationLimits()->create([ - "year_period_id" => $this->yearPeriodRetriever->current()->id, - ]); + $yearPeriods = YearPeriod::all(); + + foreach ($yearPeriods as $yearPeriod) { + $user->vacationLimits()->create([ + "year_period_id" => $yearPeriod->id, + ]); + } } } diff --git a/app/Infrastructure/Http/Middleware/TrustProxies.php b/app/Infrastructure/Http/Middleware/TrustProxies.php index b3d08f4..7e34570 100644 --- a/app/Infrastructure/Http/Middleware/TrustProxies.php +++ b/app/Infrastructure/Http/Middleware/TrustProxies.php @@ -9,12 +9,6 @@ use Symfony\Component\HttpFoundation\Request; class TrustProxies extends Middleware { - protected $proxies; - - protected $headers = - Request::HEADER_X_FORWARDED_FOR | - Request::HEADER_X_FORWARDED_HOST | - Request::HEADER_X_FORWARDED_PORT | - Request::HEADER_X_FORWARDED_PROTO | - Request::HEADER_X_FORWARDED_AWS_ELB; + protected $proxies = '*'; + protected $headers = Request::HEADER_X_FORWARDED_AWS_ELB; } diff --git a/composer.json b/composer.json index 7f21608..a10744d 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "ext-redis": "*", "azuyalabs/yasumi": "^2.4", "barryvdh/laravel-dompdf": "^1.0", + "fakerphp/faker": "^1.19", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "inertiajs/inertia-laravel": "^0.5.1", @@ -27,7 +28,6 @@ "require-dev": { "blumilksoftware/codestyle": "^0.10.0", "spatie/laravel-ignition": "^1.0", - "fakerphp/faker": "^1.9.1", "laravel/dusk": "^6.21", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", diff --git a/composer.lock b/composer.lock index 6b8a37c..ebb8dd1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c5b402774b90f0e4bb912ca08a44a143", + "content-hash": "0ee65ae15107942cb5ad2ee8067d514c", "packages": [ { "name": "asm89/stack-cors", @@ -813,6 +813,73 @@ }, "time": "2020-10-16T08:27:54+00:00" }, + { + "name": "fakerphp/faker", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/FakerPHP/Faker.git", + "reference": "d7f08a622b3346766325488aa32ddc93ccdecc75" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/d7f08a622b3346766325488aa32ddc93ccdecc75", + "reference": "d7f08a622b3346766325488aa32ddc93ccdecc75", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "psr/container": "^1.0 || ^2.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "conflict": { + "fzaninotto/faker": "*" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "doctrine/persistence": "^1.3 || ^2.0", + "ext-intl": "*", + "symfony/phpunit-bridge": "^4.4 || ^5.2" + }, + "suggest": { + "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", + "ext-curl": "Required by Faker\\Provider\\Image to download images.", + "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", + "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", + "ext-mbstring": "Required for multibyte Unicode string functionality." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "v1.19-dev" + } + }, + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "support": { + "issues": "https://github.com/FakerPHP/Faker/issues", + "source": "https://github.com/FakerPHP/Faker/tree/v1.19.0" + }, + "time": "2022-02-02T17:38:57+00:00" + }, { "name": "firebase/php-jwt", "version": "v5.5.1", @@ -8004,73 +8071,6 @@ ], "time": "2022-03-03T08:28:38+00:00" }, - { - "name": "fakerphp/faker", - "version": "v1.19.0", - "source": { - "type": "git", - "url": "https://github.com/FakerPHP/Faker.git", - "reference": "d7f08a622b3346766325488aa32ddc93ccdecc75" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/d7f08a622b3346766325488aa32ddc93ccdecc75", - "reference": "d7f08a622b3346766325488aa32ddc93ccdecc75", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0", - "psr/container": "^1.0 || ^2.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "conflict": { - "fzaninotto/faker": "*" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "doctrine/persistence": "^1.3 || ^2.0", - "ext-intl": "*", - "symfony/phpunit-bridge": "^4.4 || ^5.2" - }, - "suggest": { - "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", - "ext-curl": "Required by Faker\\Provider\\Image to download images.", - "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", - "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", - "ext-mbstring": "Required for multibyte Unicode string functionality." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "v1.19-dev" - } - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "support": { - "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.19.0" - }, - "time": "2022-02-02T17:38:57+00:00" - }, { "name": "filp/whoops", "version": "2.14.5", diff --git a/config/database.php b/config/database.php index 4593682..0ab09ab 100644 --- a/config/database.php +++ b/config/database.php @@ -30,7 +30,6 @@ return [ "prefix" => env("REDIS_PREFIX", Str::slug(env("APP_NAME", "laravel"), "_") . "_database_"), ], "default" => [ - "scheme" => "tls", "url" => env("REDIS_URL"), "host" => env("REDIS_HOST", "127.0.0.1"), "password" => env("REDIS_PASSWORD"), @@ -38,7 +37,6 @@ return [ "database" => env("REDIS_DB", "0"), ], "cache" => [ - "scheme" => "tls", "url" => env("REDIS_URL"), "host" => env("REDIS_HOST", "127.0.0.1"), "password" => env("REDIS_PASSWORD"), diff --git a/config/google-calendar.php b/config/google-calendar.php index e50a33b..da66b8c 100644 --- a/config/google-calendar.php +++ b/config/google-calendar.php @@ -6,14 +6,9 @@ return [ "default_auth_profile" => env("GOOGLE_CALENDAR_AUTH_PROFILE", "service_account"), "auth_profiles" => [ "service_account" => [ - "credentials_json" => storage_path("app/google-calendar/service-account-credentials.json"), - ], - "oauth" => [ - "credentials_json" => storage_path("app/google-calendar/oauth-credentials.json"), - "token_json" => storage_path("app/google-calendar/oauth-token.json"), + "credentials_json" => base_path("google-credentials.json"), ], ], - "calendar_id" => env("GOOGLE_CALENDAR_ID"), "user_to_impersonate" => env("GOOGLE_CALENDAR_IMPERSONATE"), ]; diff --git a/docker/dev/php/Dockerfile b/docker/dev/php/Dockerfile index 150cc77..d3b8533 100644 --- a/docker/dev/php/Dockerfile +++ b/docker/dev/php/Dockerfile @@ -9,14 +9,15 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \ && docker-php-ext-enable xdebug \ ;fi -RUN apk add --no-cache \ +RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \ postgresql-dev \ zip \ libzip-dev \ - libpng-dev \ + && pecl install redis \ && docker-php-ext-install \ pdo_pgsql \ zip \ - gd \ && docker-php-ext-configure \ - zip + zip \ + && docker-php-ext-enable \ + redis diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b03455d --- /dev/null +++ b/nginx.conf @@ -0,0 +1,10 @@ +if ($http_x_forwarded_proto != 'https') { + rewrite ^ https://$host$request_uri? permanent; +} + +location / { + try_files $uri @rewriteapp; +} +location @rewriteapp { + rewrite ^(.*)$ /index.php$1 last; +} \ No newline at end of file diff --git a/readme.md b/readme.md index d25b8f7..f981e88 100644 --- a/readme.md +++ b/readme.md @@ -53,7 +53,7 @@ Directory structure little differs from a standard Laravel tree. We decided to r dcr node npm run dev -- place google credentials here: `/storage/app/google-calendar/service-account-credentials.json` ([how to obtain the credentials](https://github.com/spatie/laravel-google-calendar#how-to-obtain-the-credentials-to-communicate-with-google-calendar)) +- place google credentials here: `/google-credentials.json` ([how to obtain the credentials](https://github.com/spatie/laravel-google-calendar#how-to-obtain-the-credentials-to-communicate-with-google-calendar)) ### Available containers (local) diff --git a/resources/js/Composables/statusInfo.js b/resources/js/Composables/statusInfo.js index 91e7ceb..a9c94bd 100644 --- a/resources/js/Composables/statusInfo.js +++ b/resources/js/Composables/statusInfo.js @@ -125,7 +125,7 @@ const statuses = [ export function useStatusInfo() { const getStatues = () => statuses - const findStatus = value => statuses.find(month => month.value === value) + const findStatus = value => statuses.find(status => status.value === value) return { getStatues, diff --git a/resources/js/Pages/VacationRequest/Create.vue b/resources/js/Pages/VacationRequest/Create.vue index e0139d5..2678078 100644 --- a/resources/js/Pages/VacationRequest/Create.vue +++ b/resources/js/Pages/VacationRequest/Create.vue @@ -372,7 +372,7 @@ export default { setup(props) { const form = useForm({ user: props.can.createOnBehalfOfEmployee - ? props.users.data.find(user => user.id === props.auth.user.id) + ? props.users.data.find(user => user.id === props.auth.user.id) ?? props.users.data[0] : props.auth.user, from: null, to: null,