-
-
Save amandiobm/6b2de4e72fab95a85508c389dc6fc74d to your computer and use it in GitHub Desktop.
Laravel envoy template for Virtualmin & Webmin servers with cron jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@servers(['remote' => 'ks1.xxxxx.com', 'local' => '127.0.0.1']) | |
@include('vendor/autoload.php') | |
@setup | |
# customize this keys... | |
# USERNAME_HERE, DOMAIN_NAME_HERE, REPO_GROUP, REPO_NAME | |
$dotenv = Dotenv\Dotenv::create(__DIR__, '.env'); | |
$dotenv->load(); | |
$now = date('Ymd-His'); | |
$branch = "origin/master"; | |
$username = "USERNAME_HERE"; | |
$key_email = "no-reply@DOMAIN_NAME_HERE.com"; | |
$repo_domain = "git.DOMAIN_NAME_HERE.com"; | |
$repo_group = "REPO_GROUP"; | |
$repo_name = "REPO_NAME"; | |
$project_root = "/home/$username/$repo_name"; | |
$domain = $username.'.DOMAIN_NAME_HERE.com'; | |
$slack = env('SLACK_ENDPOINT'); | |
$crons = [ | |
'Laravel Schedule' => [ | |
'* * * * *', | |
"/usr/bin/php71 $project_root/artisan schedule:run >> /dev/null 2>&1" | |
] | |
]; | |
$alias = [ | |
'alias php="/usr/bin/php71"', | |
'alias composer="php /bin/composer"', | |
'alias ka="php artisan"', | |
'alias kdump="composer dump-autoload -o"', | |
'alias klean="ka clear-compiled && ka migrate:refresh && ka db:seed"', | |
]; | |
$envs = [ | |
'SLACK_ENDPOINT="https://hooks.slack.com/services/XXX/XX/XXX"', | |
]; | |
@endsetup | |
@task('php', ['on' => 'remote']) | |
su -l {{ $username }} | |
php -v | |
@endtask | |
@story('upgrade_php') | |
yum install rh-php72 rh-php72-php-mysqlnd rh-php72-php-mbstring rh-php72-php-fpm rh-php72-php-xml rh-php72-php-gd rh-php72-php-soap rh-php72-php-bcmath | |
@endstory | |
@story('doall') | |
build_production | |
deploy | |
build_dev | |
@endstory | |
@task('build_production', ['on' => 'local']) | |
yarn prod | |
git add . | |
git commit -m "Commit before deploy {{$now}}" | |
git push -u origin master | |
@endtask | |
@task('build_dev', ['on' => 'local']) | |
yarn dev | |
@endtask | |
@task('deploy', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan down --message="Upgrading system.." --retry=60 | |
git fetch --all | |
git reset --hard {{ $branch }} | |
git pull origin master | |
@if ($u) | |
composer update --no-dev --prefer-dist --optimize-autoloader --ignore-platform-reqs | |
@else | |
composer install --no-dev --prefer-dist --optimize-autoloader --ignore-platform-reqs | |
@endif | |
@if ($m) | |
php artisan migrate --force | |
@endif | |
php artisan config:clear | |
php artisan config:cache | |
php artisan view:clear | |
php artisan view:cache | |
php artisan up | |
@endtask | |
@task('update', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan down --message="Upgrading system.." --retry=60 | |
composer update --no-dev --prefer-dist | |
php artisan config:clear | |
php artisan config:cache | |
php artisan view:clear | |
php artisan view:cache | |
php artisan up | |
@endtask | |
@task('passport', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan passport:keys | |
php artisan passport:install | |
# php artisan vendor:publish --tag=passport-components | |
@endtask | |
@task('composer', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan down --message="Upgrading system.." --retry=60 | |
composer install --no-dev --prefer-dist | |
php artisan up | |
@endtask | |
@task('ssh', ['on' => 'remote', 'confirm' => true]) | |
su -l {{ $username }} | |
[ -d ~/.ssh ] || echo "~/.ssh directory does not exist, lets create" | |
[ -d ~/.ssh ] || mkdir ~/.ssh | |
echo "Adding {{ $repo_domain }} domain to known_hosts" | |
ssh-keyscan {{ $repo_domain }} >> ~/.ssh/known_hosts | |
cd ~/.ssh | |
echo "Deleting ssh keys..." | |
rm -rf id_rsa id_rsa.pub | |
ssh-keygen -t rsa -C "{{ $repo_domain }}" -b 4096 -N "" -f id_rsa | |
cat ~/.ssh/id_rsa.pub | |
@endtask | |
@story('setup') | |
download | |
install | |
@endstory | |
@task('download', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~ | |
echo "Cloning {{ "git@" . $repo_domain .":". $repo_group ."/" . $repo_name . ".git" }}" | |
git clone {{ "git@" . $repo_domain .":". $repo_group ."/" . $repo_name . ".git" }} | |
cd ~/{{ $repo_name }} | |
echo "Done download" | |
@endtask | |
@task('install', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
composer install --no-dev | |
[ -f .env ] || echo ".env does not exist, using default .env.example" | |
[ -f .env ] || cp .env.example .env | |
echo "Generating new KEY for .env" | |
php artisan key:generate | |
echo "Linking storage folder" | |
php artisan storage:link | |
@endtask | |
@task('alias', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~ | |
@foreach ($alias as $alia) | |
LINE='{{$alia}}' | |
FILE=.profile | |
grep -qF "$LINE" "$FILE" || echo "$LINE" >> "$FILE" | |
@endforeach | |
alias | |
echo "Done." | |
@endtask | |
@task('add_env', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
@foreach ($envs as $env) | |
LINE='{{$env}}' | |
FILE=.env | |
grep -qF "$LINE" "$FILE" || echo "$LINE" >> "$FILE" | |
@endforeach | |
cat .env | |
echo "Done." | |
@endtask | |
@task('publish', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~ | |
rm -rf public_html | |
ln -s ~/{{ $repo_name }}/public ~/public_html | |
echo "App should be now live." | |
@endtask | |
@task('cron_add', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
echo "# write out current crontab" | |
@foreach ($crons as $cron_name => $cron_job) | |
echo "{{$cron_job[1]}}" | |
croncmd="{{$cron_job[1]}}" | |
cronjob="{{$cron_job[0]}} $croncmd" | |
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab - | |
@endforeach | |
echo "# Done addCrons" | |
@endtask | |
@task('cron_remove', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
echo "# remove crontabs" | |
@foreach ($crons as $cron_name => $cron_job) | |
croncmd="{{$cron_job[1]}}" | |
( crontab -l | grep -v -F "$cron_name" ) | crontab - | |
( crontab -l | grep -v -F "$croncmd" ) | crontab - | |
@endforeach | |
echo "# Done rmCrons" | |
@endtask | |
@task('apachelogswatch', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
tail -f /var/log/virtualmin/{{$domain}}_error_log | |
@endtask | |
@task('laralogswatch', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
tail -f storage/logs/laravel.log | |
@endtask | |
@task('catenv', ['on' => 'local']) | |
cat .env | |
@endtask | |
@task('link_klaravel', ['on' => 'local']) | |
cd vendor/ksoft/ | |
rm -rf klaravel/ | |
ln -s ~/Developer/Laravel/Laravel-Plugins/klaravel/ ./klaravel | |
ls -la | |
cd .. | |
cd .. | |
@endtask | |
@task('klean', ['on' => 'local']) | |
php artisan clear-compiled | |
php artisan migrate:refresh | |
php artisan db:seed | |
@endtask | |
@task('dump', ['on' => 'local']) | |
composer dump-autoload | |
php artisan config:clear | |
php artisan view:clear | |
php artisan cache:clear | |
php artisan clear-compiled | |
@endtask | |
@task('up', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan up | |
@endtask | |
@task('down', ['on' => ['remote']]) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan down | |
@endtask | |
@story('migrate') | |
warning | |
run_migration_seed | |
@endstory | |
@task('warning', ['on' => ['local']]) | |
echo "---------------------------------------------" | |
echo "---------------------------------------------" | |
echo "--------------- "ATTENTION" -----------------" | |
echo "---------------------------------------------" | |
echo "---------------------------------------------" | |
echo "------------- Are you sure? ---------------" | |
echo "---------------------------------------------" | |
echo "---------------------------------------------" | |
@endtask | |
@task('run_migration_seed', ['on' => 'remote', 'confirm' => true]) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan migrate --force | |
@if ($seed) | |
php artisan db:seed --force | |
@endif | |
@endtask | |
@task('m:r', ['on' => 'remote']) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan migrate:rollback --force | |
@endtask | |
@task('rights', ['on' => 'remote', 'confirm' => true]) | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
chmod -R 0777 public/upload app/storage | |
find . -type d -exec chmod 775 {} \; | |
find . -type f -exec chmod 664 {} \; | |
@endtask | |
@task('reload_php_server', ['on' => 'remote']) | |
/etc/rc.d/init.d/php-fcgi-{{str_replace('.', '-', $domain)}} restart | |
@endtask | |
@task('reload_nginx', ['on' => 'remote']) | |
systemctl restart nginx | |
@endtask | |
@task('optimizeInstallation', ['on' => 'remote']) | |
echo 'start optimizeInstallation' | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan clear-compiled | |
php artisan optimize | |
@endtask | |
@task('backupDatabase', ['on' => 'remote']) | |
echo 'start backupDatabase' | |
su -l {{ $username }} | |
cd ~/{{ $repo_name }} | |
php artisan backup:run | |
@endtask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment