In this example of deploying, commands were used for a laravel app using docker.
- Add the application name:
set('application', 'sm-semec');
- Add application repository found on github:
set('repository', 'git@github.com:utfpr-gp-tsi/sm-semec.git');
- Allocate TTY to the git clone command, this allows you to enter a password for keys:
set('git_tty', true);
- OBS: TTY é um terminal no qual está conectado, quando ativado ele mostrará o terminal do git para obter uma senha.
- Define how many versions you want to keep the application:
set('keep_releases', 3);
- Set the process execution timeout:
set('default_timeout', 600);
- Files that can be shared with all versions of the project:
add('shared_files', ['.env']);
- Creates a symbolic link, where it is shared with the other versions of the project:
add('shared_dirs', ['logs', 'public/uploads', 'vendor']);
- You need to specify a few things like:
host('production') ->hostname('161.35.122.229') ->user('deployer') ->port(22) ->identityFile('/var/www/.ssh/id_rsa') ->stage('production') ->set('deploy_path', '/var/www/') ->set('branch','production');
Where
- You must define a host to deploy:
host('production')
- Add the IP server that will be used:
→hostname('161.35.122.229')
- User responsible for the deployment (must never be root):
→user('deployer')
- Port you are using:
→port(22)
- File must contain information about domains and how to connect:
→identityFile('/var/www/.ssh/id_rsa')
- Host stage:
→stage('production')
- Path where the application is located (leave application saved locally in / var / www):
->set('deploy_path', '/var/www/')
- Branch production used in the deploy:
→set('branch','production');
- You must define a host to deploy:
- Upload the directories by sending to the server:
task('deploy:cp-docker-files', function () { upload('deploy/production/', ""); upload('deploy/php/', "/shared/php/"); upload('deploy/mysql/', "/shared/mysql/"); })→onStage('production');
OBS Stage being used to deploy:
→onStage('production');
- Commands related to containers:
task('deploy:build-containers', function () { run('cd && docker-compose stop app-semec'); run('cd && docker-compose build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) app-semec'); });
Where:
- Stop the containers from running without removal:
run('cd && docker-compose stop app-semec');
- Create the application container:
run('cd && docker-compose build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) app-semec'); });
- Stop the containers from running without removal:
- Issue a single command to start all containers, create volumes, configure and connect as networks
task('deploy:up-containers', function () { run('cd && docker-compose up -d'); });
- Displays the containers:
task('deploy:containers-ps', function () { run('cd && docker-compose ps'); });
- Command to perform docker-related tasks:
task('deploy:setup:docker', [ 'deploy:cp-docker-files', 'deploy:build-containers', 'deploy:up-containers', 'deploy:containers-ps' ]);
- To install all packages and libraries, where optimize-autoloader speeds up automatic loading in the application:
task('deploy:composer:install', function () { run('cd && docker-compose exec -T -w app-semec composer install – no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --no-suggest --optimize-autoloader'); });
- Generate a key for the project:
task('deploy:artisan:key:generate', function () { run('cd && docker-compose exec -T -w app-semec php artisan key:generate'); });
- Cache these settings in a file, which will increase the application loading speed:
task('deploy:config:cache', function () { run('cd && docker-compose exec -T -w app-semec php artisan config:cache'); });
- Perform the migrations of the database tables:
task('deploy:migrate', function () { run('cd && docker-compose exec -T -w app-semec php artisan migrate – force'); });
- Run the seeds:
task('deploy:seed', function () { run('cd && docker-compose exec -T -w app-semec php artisan db:seed –force'); });
- Install the packages and dependencies with npm install, then load the application’s sass files:
task('deploy:assets', function () { run('cd && docker-compose exec -T -w app-semec npm install'); run('cd && docker-compose exec -T -w app-semec npm run production'); });
- Run the command to clear the routes and cache from the application view:
task('deploy:cache', function () { run('cd && docker-compose exec -T -w app-semec php artisan route:cache'); run('cd && docker-compose exec -T -w app-semec php artisan view:cache'); });
- Stops the user process, causing the user to log off:
task('deploy:reload:php', function () { run('cd && docker-compose exec -T app-semec kill -USR2 1'); });
- Reload nginx settings after modification:
task('deploy:reload:nginx', function () { run('sudo nginx -s reload'); });task('deploy:reload:nginx', function () { run('sudo nginx -s reload'); });
- After completing the custom tasks, add them to the deploy task:
task('deploy', [ 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:clear_paths', 'deploy:composer:install', 'deploy:config:cache', 'deploy:migrate', 'deploy:seed', 'deploy:assets', 'deploy:cache', 'deploy:reload:php', 'deploy:reload:nginx', 'deploy:symlink', 'deploy:unlock', 'cleanup', 'success' ]);
- Delete release files like deploy.log that is on the server:
after('deploy:failed', 'deploy:unlock');