Skip to content

Instantly share code, notes, and snippets.

@skobkin
Last active December 13, 2017 08:43
Show Gist options
  • Save skobkin/ce617fe184cd42c88e14eca54a45cf27 to your computer and use it in GitHub Desktop.
Save skobkin/ce617fe184cd42c88e14eca54a45cf27 to your computer and use it in GitHub Desktop.
Deploying Symfony2 application using CodeShip and Deployer
#################################
### Building environment and app
#################################
# https://documentation.codeship.com/classic/languages-frameworks/php/
phpenv local 7.1
# Passing Symfony parameters through environment variables
export SYMFONY_ENV=test
export SYMFONY__TEST_DATABASE_USER=$PGUSER
export SYMFONY__TEST_DATABASE_PASSWORD=$PGPASSWORD
export SYMFONY__TEST_DATABASE_NAME=test
export SYMFONY__TEST_DATABASE_PORT=5436
# Enabling composer cache:
export COMPOSER_HOME=${HOME}/cache/composer
# Copy the parameters.yml.dist
cp app/config/parameters.yml.dist app/config/parameters.yml
# Changing default PostgreSQL port for PostgreSQL 9.6
sed -i "s|5432|5436|" "app/config/parameters.yml"
sed -i "s|point_login: point-tools|point_login: testuser|" "app/config/parameters.yml"
sed -i "s|point_id: 435|point_id: 99999|" "app/config/parameters.yml"
sed -i "s|telegram_log_chat_id: ~|telegram_log_chat_id: 0|" "app/config/parameters.yml"
# Install extensions through Pecl
# yes yes | pecl install memcache
# Install dependencies through Composer
composer install --no-suggest --no-interaction
# Drop and recreate Test-Database
php ./app/console doctrine:schema:drop --force --full-database --no-interaction
# Execute migrations
php ./app/console doctrine:migrations:migrate --no-interaction
# Running fixtures
php ./app/console doctrine:fixtures:load --no-interaction
# Clear Cache
php ./app/console cache:clear
# Cloning the repo with Deployer configuration for owr projects
git clone [email protected]:skobkin/deployer-config.git
# Entering corresponding project configuration directory
cd deployer-config/point-tools
# Installing Deployer and it's dependencies
composer install --no-dev --no-interaction
# Running deploy
php vendor/bin/dep deploy production
# Running tests
phpunit --coverage-clover=clover.xml
# Uploading coverage stats
bash <(curl -s https://codecov.io/bash)
<?php
namespace Deployer;
require __DIR__.'/vendor/deployer/deployer/recipe/symfony.php';
// Configuration
set('repository', 'https://[email protected]/skobkin/point-tools.git');
add('shared_files', []);
add('shared_dirs', [
'vendor'
]);
add('writable_dirs', []);
// Servers
server('production', /* server host */, /* server port */)
->user('deploy')
->identityFile()
->forwardAgent()
->set('deploy_path', '/var/www/point-tools')
->stage('production')
;
set('keep_releases', 5);
// Tasks
// Overriding assets installation (adding symlink)
task('deploy:assets:install', function () {
run('{{env_vars}} {{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web --symlink');
})->desc('Install bundle assets via symlink');
task('php-fpm:restart', function () {
// The user must have rights for restart service
// /etc/sudoers: deploy ALL=NOPASSWD:/sbin/service service php-fpm restart
run('sudo service php-fpm restart');
})->desc('Restart PHP-FPM service');
after('deploy:symlink', 'php-fpm:restart');
// Migrate database before symlink new release.
before('deploy:symlink', 'database:migrate');
{
"require": {
"deployer/deployer": "^4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment