Skip to content

Instantly share code, notes, and snippets.

@Astyk
Forked from vedovelli/Envoy.blade.php
Created September 27, 2016 05:46
Show Gist options
  • Save Astyk/9baac55d68c11d96bf55a8ce0005f58f to your computer and use it in GitHub Desktop.
Save Astyk/9baac55d68c11d96bf55a8ce0005f58f to your computer and use it in GitHub Desktop.
@servers(['staging' => '[email protected]', 'production' => '[email protected]'])
<?php
$app_name = 'l5eka';
$app_path = '/var/www/vhosts/'.$app_name;
$repo = 'https://github.com/vedovelli/l5eka';
$branch = 'aula4';
$keep = 6;
$timezone = 'America/Sao_Paulo';
$apt_get_packages = [
'git',
'nodejs',
'npm',
'php5-cli',
'php5-mcrypt',
// 'mysql-server-5.5',
// 'mysql-client-5.5',
// 'nginx',
// 'php5',
// 'php5-mysql',
// 'php5-curl',
// 'php5-cgi',
// 'php5-gd',
// 'php-pear',
// 'php5-sqlite',
// 'php5-tidy',
// 'php5-xmlrpc',
// 'php5-xsl'
];
$bower_packages = [
'bower',
'gulp',
];
$chmods = [
'app/storage',
'app/database/production.sqlite',
'public',
];
$firewall = [
'allow_ports' => [
'22',
'80',
'443'
]
];
$date = new DateTime('now', new DateTimeZone($timezone));
// $release = $app_path .'/releases/'. $date->format('YmdHis');
$release = $app_path .'/releases/'. $date->format('Ymd');
$environment = isset($env) ? $env : "testing";
$bin_path = '/usr/bin';
// $os_name = exec("lsb_release -i | cut -d: -f 2 | sed 's/\t//g'");
?>
@macro('test_deploy', ['on' => $on])
update_apt_sources
install_os_packages
install_bower_packages
fetch_repo
composer
update-symlink
assets
ufw_rules
done
@endmacro
@macro('deploy')
update_apt_sources
install_os_packages
install_bower_packages
fetch_repo
composer
update-symlink
assets
chmod
artisan_migrate
artisan_seed
ufw_rules
done
@endmacro
@task('update_apt_sources', ['on' => $on])
echo "Atualizando lista de pacotes..." ;
apt-get update -q ;
@endtask
@task('install_os_packages', ['on' => $on])
echo "Instalando pacotes necessários..." ;
@foreach($apt_get_packages as $pkg)
apt-get install -qq -y {{ $pkg }} ;
echo -e "{{ $pkg }} instalado...\n" ;
@endforeach
[[ -e /usr/bin/nodejs ]] && ln -s /usr/bin/nodejs /usr/bin/node ;
apt-get install -f -q ;
php5enmod mcrypt && service nginx restart;
[[ -e {{$bin_path}}/composer ]] && composer self-update;
[[ ! -e {{$bin_path}}/composer ]] && curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir={{$bin_path}}
@endtask
@task('install_bower_packages', ['on' => $on])
echo "Instalando pacotes npm necessários..." ;
@foreach($bower_packages as $pkg)
npm install -g {{ $pkg }} ;
@endforeach
@endtask
@task('assets', ['on' => $on])
echo "Instalando Assets..." ;
cd {{ $release }}/resources/assets ;
npm install ;
gulp ;
@endtask
@task('ufw_rules', ['on' => $on])
echo "Atualizando regras do Firewall..." ;
@foreach($firewall['allow_ports'] as $port)
ufw allow {{ $port }};
ufw default deny;
ufw reload;
echo "Certifique-se de ativar o firewall com o comando 'ufw enable && ufw reload'..." ;
@endforeach
@endtask
@task('fetch_repo', ['on' => $on])
mkdir -p {{ $release }};
git clone --branch "{{ $branch }}" "{{ $repo }}" {{ $release }};
@endtask
@task('composer', ['on' => $on])
cd {{ $release }} ;
composer install ;
composer update ;
echo "Composer dependencie s have been installed"
@endtask
@task('chmod', ['on' => $on])
@foreach($chmods as $file)
chmod -R 755 {{ $release }}/{{ $file }}
chmod -R g+s {{ $release }}/{{ $file }}
chown -R www-data:www-data {{ $release }}/{{ $file }}
echo "Permissions have been set for {{ $file }}"
@endforeach
@endtask
@task('update-symlink', ['on' => $on])
rm -rf {{ $app_path }}/current
ln -fs {{ $release }} {{ $app_path }}/current
echo "Release symlink has been set"
@endtask
@task('artisan_migrate', ['on' => $on])
cd {{ $release }};
php artisan migrate
@endtask
@task('artisan_seed', ['on' => $on])
cd {{ $release }};
php artisan db:seed
@endtask
@task('update_permissions')
cd {{ $release }};
chgrp -R www-data ../{{ $release }};
chmod -R ug+rwx ../{{ $release }};
@endtask
@task('done', ['on' => $on])
echo "Deployment finished successfully!"
@endtask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment