zero-24 / plg_system_gitdeploy

This Joomla plugin allows to automaticly deploy changes from a git repo and is based on [KickDeploy](https://github.com/nielsnuebel/kickdeploy)
8 stars 4 forks source link

Executing CLI on onAfterRoute #1

Open anibalsanchez opened 3 years ago

anibalsanchez commented 3 years ago

Hi Tobias,

This is more of general feedback than an issue itself. I understand that the method of executing commands with shell_exec works in the onAfterRoute.

My feedback in more in line with the recommendation to avoid using onAfterRoute for stuff that it is outside than what the web server should be doing (serving web pages). Since the web server has a configuration / security profile to serve pages, it can easily break the execution of a deployment.

Back to the extension, I would suggest a Cronjob execution with a CLI in the /file folder to execute the deployment.

Something like what Laravel does with the artisan commands. This is a script that I use as a deployment cron job:

#!/bin/sh -e

NOW=`date +"%Y-%m-%d %H:%M"`
echo "***** $NOW - Deploying application ..."

cd ...

# Enter maintenance mode
(/usr/bin/php artisan down --message 'The service is being updated. Please try again in a few minutes.') || true

# Update codebase
git fetch origin deploy
git reset --hard origin/deploy

....

# Optimizing Configuration Loading
/usr/bin/php artisan config:cache

# Optimizing Route Loading
/usr/bin/php artisan route:cache

# Optimizing View Loading
/usr/bin/php artisan view:cache

# Migrate database
/usr/bin/php artisan migrate --force

....

# Clear cache
/usr/bin/php artisan optimize

# Reload PHP to update opcache
# echo "" | sudo -S service php7.4-fpm reload

# Exit maintenance mode
...
/usr/bin/php artisan up

NOW=`date +"%Y-%m-%d %H:%M"`
echo "***** $NOW - Application deployed!"

Hope this helps! Let us know if there is anything else we can do.

zero-24 commented 3 years ago

I agree the idea here (and the reason for this plugin) is that you want to do it that way and that you want to use github webhooks. This way it also allows people to setup a git deploy without messing arround with shell scripts themself.

When you have a deploy script like you mention a simple git pull does not work anyway.

But to me this does not sound like a direct issue with the plugin just another way to do git deploys right?

anibalsanchez commented 3 years ago

I think that the value proposition of the plugin to ease the configuration of deployments is OK.

The only issue is the way of executing the deployment.

I would add the alternative to execute the deployment as a command line with a cron job (to avoid the execution of a long task in the webserver context, that could potentially break the site if it fails).

zero-24 commented 3 years ago

Thanks will take a look into it. i'm not sure yet how to trigger a cli script on a github hook but will take a look into it and maybe adding a option to trigger a custom build / deploy script.

anibalsanchez commented 3 years ago

This the post-merge that we execute on JED with a cronjob: https://github.com/joomla/jed-dev/blob/develop/hooks/post-merge

This is the cronjob: https://github.com/joomla/jed-dev/blob/develop/jed-git-hook-ci.sh

This is the crontab: https://github.com/joomla/jed-dev/blob/develop/crontab#L14

zero-24 commented 3 years ago

Will take a look into that thanks!