Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployer script #44

Open
Gummibeer opened this issue Apr 15, 2021 · 3 comments
Open

Deployer script #44

Gummibeer opened this issue Apr 15, 2021 · 3 comments

Comments

@Gummibeer
Copy link
Member

Right now I'm using simple SSH deployment - because I have multiple hosts and want to maintain the deployment script next to the code I want to use https://deployer.org instead.

If you don't know deployer yet - @lorisleiva has a great course about deployer with Laravel https://lorisleiva.com/deploy-your-laravel-app-from-scratch

The current deployment script is:

$FORGE_PHP artisan backup:run
rm -f bootstrap/cache/config.php
$FORGE_PHP artisan optimize:clear

git pull origin main
$FORGE_COMPOSER update --no-interaction --prefer-dist --optimize-autoloader --no-dev

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

yarn install
yarn production
$FORGE_PHP artisan blade-fontawesome:sync-pro
$FORGE_PHP artisan icons:cache
$FORGE_PHP artisan nova:publish
$FORGE_PHP artisan horizon:publish

$FORGE_PHP artisan config:cache
$FORGE_PHP artisan event:cache
$FORGE_PHP artisan route:cache
$FORGE_PHP artisan view:cache
$FORGE_PHP artisan migrate --force
$FORGE_PHP artisan permission:cache-reset
$FORGE_PHP artisan permission:ensure
$FORGE_PHP artisan schedule-monitor:sync
@lorisleiva
Copy link

lorisleiva commented Apr 16, 2021

I haven't tested it and it can be cleaned up slightly using recipes but here's the equivalent as a Deployer config file. Just put that in the root of your app as deploy.yaml, tweak the hosts user, IP and deploy path and you should be sorted.

I've taken the liberty to push the php-fpm:reload at the very end of your deployment but feel free to put it back in the middle.

May I ask why you need to run nova:publish and horizon:publish during your deployment? I've recently removed them from the Deployer core since they're more local commands IMO but I could fix this if there's a good use case for it. :)

import:
  - recipe/laravel.php
  - contrib/php-fpm.php
  - contrib/yarn.php

config:
  application: 'opendor.me'
  repository: '[email protected]:Astrotomic/opendor.me.git'
  php_fpm_version: '8.0'

hosts:
  prod_1:
    remote_user: forge
    hostname: '139.59.161.100'
    deploy_path: '~/opendor.me'
  prod_2:
    remote_user: forge
    hostname: '139.59.161.101'
    deploy_path: '~/opendor.me'

tasks:
  deploy:
    - artisan:backup:up
    - cache:config:delete
    - artisan:optimize:clear
    - deploy:prepare
    - deploy:vendors
    - yarn:install
    - yarn:run:prod
    - artisan:blade-fontawesome:sync-pro
    - artisan:icons:cache
    - artisan:nova:publish
    - artisan:horizon:publish
    - artisan:config:cache
    - artisan:event:cache
    - artisan:route:cache
    - artisan:view:cache
    - artisan:migrate
    - artisan:permission:cache-reset
    - artisan:permission:ensure
    - artisan:schedule-monitor:sync
    - deploy:publish
    - php-fpm:reload
  artisan:backup:up:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan backup:run'
  cache:config:delete:
    script: 'cd {{release_or_current_path}} && rm -f bootstrap/cache/config.php'
  artisan:blade-fontawesome:sync-pro:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan blade-fontawesome:sync-pro'
  artisan:icons:cache:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan icons:cache'
  artisan:nova:publish:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan nova:publish'
  artisan:horizon:publish:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan horizon:publish'
  artisan:permission:cache-reset:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan permission:cache-reset'
  artisan:permission:ensure:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan permission:ensure'
  artisan:schedule-monitor:sync:
    script: 'cd {{release_or_current_path}} && {{bin/php}} artisan schedule-monitor:sync'
  yarn:run:prod:
    script: 'cd {{release_or_current_path}} && {{bin/yarn}} run production'

after:
  deploy:failed: deploy:unlock

@adevade
Copy link
Contributor

adevade commented Apr 16, 2021

Yeah, I would put the horizon:publish on the update hook of composer instead of in production, as suggested in the docs: https://laravel.com/docs/8.x/horizon#upgrading-horizon

{
  "scripts": {
    "post-update-cmd": [
      "@php artisan horizon:publish --ansi"
    ]
  }
}

@Gummibeer
Copy link
Member Author

As I run composer update on production as well this isn't important.^^
But is applied. I simply don't want/will manage the composer.lock file and it's never ending merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants