From 6d62c8b776ecfde9c72947a4d20308182299d374 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Tue, 15 Mar 2022 14:46:42 +0100 Subject: [PATCH] #48 - heroku deployment (#70) * test * #48 - deployment * #48 - fixes * #48 - prod assets * #48 - readme for heroku deployment * #48 - fix * #48 - ecs fix * #48 - fix * #48 - fix * #48 - cr fix * #48 - remove predis dependency --- .gitignore | 1 + Procfile | 3 ++ app/Eloquent/Observers/UserObserver.php | 16 +++---- .../Http/Controllers/DashboardController.php | 2 +- .../Http/Middleware/TrustProxies.php | 10 +---- composer.json | 7 +-- composer.lock | 5 ++- config/google-calendar.php | 7 +-- docker-compose.yml | 6 +-- {docker => environment}/dev/nginx/nginx.conf | 0 {docker => environment}/dev/php/Dockerfile | 0 {docker => environment}/dev/php/php.ini | 0 environment/prod/nginx.conf | 10 +++++ environment/prod/readme.md | 45 +++++++++++++++++++ package.json | 3 +- readme.md | 4 +- resources/js/Composables/statusInfo.js | 2 +- resources/js/Pages/VacationRequest/Create.vue | 2 +- 18 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 Procfile rename {docker => environment}/dev/nginx/nginx.conf (100%) rename {docker => environment}/dev/php/Dockerfile (100%) rename {docker => environment}/dev/php/php.ini (100%) create mode 100644 environment/prod/nginx.conf create mode 100644 environment/prod/readme.md 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 new file mode 100644 index 0000000..6cf46a6 --- /dev/null +++ b/Procfile @@ -0,0 +1,3 @@ +web: vendor/bin/heroku-php-nginx -C environment/prod/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/Controllers/DashboardController.php b/app/Infrastructure/Http/Controllers/DashboardController.php index 05b13ea..f215a93 100644 --- a/app/Infrastructure/Http/Controllers/DashboardController.php +++ b/app/Infrastructure/Http/Controllers/DashboardController.php @@ -50,7 +50,7 @@ class DashboardController extends Controller $holidays = Holiday::query() ->whereDate("date", ">=", $now) - ->latest() + ->orderBy("date") ->limit(3) ->get(); diff --git a/app/Infrastructure/Http/Middleware/TrustProxies.php b/app/Infrastructure/Http/Middleware/TrustProxies.php index b3d08f4..0650c12 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 0238916..306094f 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.1", "ext-pdo": "*", + "ext-redis": "*", "azuyalabs/yasumi": "^2.4", "barryvdh/laravel-dompdf": "^1.0", "fruitcake/laravel-cors": "^2.0", @@ -24,12 +25,12 @@ }, "require-dev": { "blumilksoftware/codestyle": "^0.10.0", - "spatie/laravel-ignition": "^1.0", - "fakerphp/faker": "^1.9.1", + "fakerphp/faker": "^1.19", "laravel/dusk": "^6.21", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", - "phpunit/phpunit": "^9.5.10" + "phpunit/phpunit": "^9.5.10", + "spatie/laravel-ignition": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 6f6abe7..c947164 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": "937eef6310bd4bb12f1d0ccb623946d1", + "content-hash": "45ec654a060d5985bc58fec1f42d8219", "packages": [ { "name": "asm89/stack-cors", @@ -10983,7 +10983,8 @@ "prefer-lowest": false, "platform": { "php": "^8.1", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-redis": "*" }, "platform-dev": [], "plugin-api-version": "2.1.0" 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-compose.yml b/docker-compose.yml index 6a4231b..6e14c5d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: container_name: toby-web working_dir: /application volumes: - - ./docker/dev/nginx/nginx.conf:/etc/nginx/conf.d/default.conf + - ./environment/dev/nginx/nginx.conf:/etc/nginx/conf.d/default.conf - .:/application networks: - toby-dev @@ -19,7 +19,7 @@ services: php: build: - context: docker/dev/php + context: environment/dev/php args: INSTALL_XDEBUG: ${DOCKER_INSTALL_XDEBUG:-false} container_name: toby-php @@ -27,7 +27,7 @@ services: user: ${CURRENT_UID:-1000} volumes: - .:/application - - ./docker/dev/php/php.ini:/usr/local/etc/php/conf.d/php.ini + - ./environment/dev/php/php.ini:/usr/local/etc/php/conf.d/php.ini networks: - toby-dev extra_hosts: diff --git a/docker/dev/nginx/nginx.conf b/environment/dev/nginx/nginx.conf similarity index 100% rename from docker/dev/nginx/nginx.conf rename to environment/dev/nginx/nginx.conf diff --git a/docker/dev/php/Dockerfile b/environment/dev/php/Dockerfile similarity index 100% rename from docker/dev/php/Dockerfile rename to environment/dev/php/Dockerfile diff --git a/docker/dev/php/php.ini b/environment/dev/php/php.ini similarity index 100% rename from docker/dev/php/php.ini rename to environment/dev/php/php.ini diff --git a/environment/prod/nginx.conf b/environment/prod/nginx.conf new file mode 100644 index 0000000..48da7e3 --- /dev/null +++ b/environment/prod/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; +} diff --git a/environment/prod/readme.md b/environment/prod/readme.md new file mode 100644 index 0000000..47ce847 --- /dev/null +++ b/environment/prod/readme.md @@ -0,0 +1,45 @@ +# Heroku deployment + +## Addons + +* Heroku Postgres +* Heroku Redis + +## Dynos + +* web (app) +* worker (queue worker) + +## Buildpacks +* heroku/php +* heroku/nodejs +* https://github.com/buyersight/heroku-google-application-credentials-buildpack.git + +## Config vars +* APP_DEBUG=false +* APP_ENV=production +* APP_KEY= +* APP_NAME="Toby HR application" +* APP_URL= +* ASSET_URL= +* BROADCAST_DRIVER=log +* CACHE_DRIVER=redis +* DATABASE_URL= +* DB_CONNECTION=pgsql +* DB_DATABASE= +* DB_HOST= +* DB_PORT= +* DB_USER= +* FILESYSTEM_DISK=local +* GOOGLE_CALENDAR_ID= +* GOOGLE_CLIENT_ID= +* GOOGLE_CLIENT_SECRET= +* GOOGLE_CREDENTIALS= +* GOOGLE_REDIRECT= +* LOG_CHANNEL=errorlog +* LOG_LEVEL=info +* MAIL_MAILER=log +* QUEUE_CONNECTION=redis +* REDIS_URL= +* SESSION_DRIVER=redis +* SESSION_LIFETIME=120 \ No newline at end of file diff --git a/package.json b/package.json index 29e809e..510146a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "prod": "npm run production", "production": "mix --production", "lint": "./node_modules/.bin/eslint resources/js --ext .js,.vue", - "lintf": "./node_modules/.bin/eslint resources/js --ext .js,.vue --fix" + "lintf": "./node_modules/.bin/eslint resources/js --ext .js,.vue --fix", + "postinstall": "npm run prod" }, "dependencies": { "@headlessui/vue": "^1.5.0", diff --git a/readme.md b/readme.md index d25b8f7..423afa1 100644 --- a/readme.md +++ b/readme.md @@ -53,14 +53,14 @@ 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) - **web** - nginx HTTP server - **php** - php and composer stuff - **node** - npm stuff -- **mysql** - database for local development +- **pgsql** - database for local development - **mailhog** - for emails preview ### Running tests 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,