Fabric Deploy Your Symfony2 App: Part I

Sometime ago I heard OpenSky deploys their app with fabric from @jwage, he had an article but I couldn’t make up the details since I was confused a bit by capifony. Now I know why they use it and here is the repo that we can improve together:

I improve this script from https://github.com/fabriceb/sfLive2011 and from jwage blog post http://jwage.com/post/31049115791/deploying-opensky-with-fabric which i did not remember but now that i look at it has some complementing things i will touch on the next part ii of this blog post.

Let’s install it from the mother ship https://github.com/cordoval/Symfony2Fabric:

pip install fabric

Let’s add fabfile.py to the root folder of our app:

from fabric.api import *
from fabric.contrib.files import exists
import os
from time import strftime
repo = 'git@github:username/mysite.git'
path = '/var/www/mysite'
env.use_ssh_config = True
env.sudo_user = 'www-data'
env.hosts = ['grace', 'gospel']
# check read-access to the keys, to be server-independent
keys = ['~/.ssh/id_rsa']
env.key_filename = [key for key in keys if os.access(key, os.R_OK)]
# this tags the sha deploy
def tag_prod():
    tag = "prod/%s" % strftime("%Y/%m-%d-%H-%M-%S")
    local('git tag -a %s -m "Prod"' % tag)
    local('git push --tags')
def install():
    sudo('mkdir -p ' + path)
    with cd(path):
        sudo('git clone ' + repo + ' .')
        sudo('composer install --dev')
        sudo('php app/console doctrine:database:create')
        sudo('php app/console doctrine:migrations:migrate --no-interaction')
def update():
    with cd(path):
        sudo('git remote update')
        sudo('git pull')
        sudo('composer install --dev')
        sudo('php app/console doctrine:migrations:migrate --no-interaction')
#        tag = run('git tag -l prod/* | sort | tail -n1')
#        run('git checkout ' + tag)

def deploy():
    if not exists(path):
#    tag_prod()
#def rollback(num_revs=1):
#    with cd(path):
#        run('git fetch')
#        tag = run('git tag -l prod/* | sort | tail -n' + str(1 + int(num_revs)) + ' | head -n1')
#        run('git checkout ' + tag)

Thanks for your support, I hope to see you on Portland sflive! If you want to see me there please support me as it is very expensive :'(.

Twig Lexer Override for Special Situations

Update: This is coming from the mailing database, but i thought to replicate it because it is something very useful sometimes.
Credits to: Casey Klebba

You can use a custom Twig_Lexer this way:

in config.yml

        class: Twig_Environment
        arguments: ['@twig.loader', %twig.options%]
            - [addGlobal, ['app','@templating.globals']]
            - [setLexer, ['@custom.lexer']]
        class: Acme\DemoBundle\Twig\CoreLexer
        arguments: ['@twig']


namespace Acme\DemoBundle\Twig;
use \Twig_Environment;
use \Twig_Lexer;
class CoreLexer extends Twig_Lexer {
    public function __construct(Twig_Environment $twig)
        parent::__construct($twig, array(
            'tag_comment'   => array('{#', '#}'),
            'tag_block'     => array('{%', '%}'),
            'tag_variable'  => array('{{', '}}'),
            'interpolation' => array('#{', '}'),

Very easy now!


That is it. Enjoy! And thanks Casey.

Stay Safe with Quick Trick on Your Composer

Thanks to @Seldaek and @Fabien, I became aware of this nice security tool that just came up. And all community can use it in spite the comments against composer which don’t make really sense to me. But just follow the steps to run the security-checker cli tool to check whether your project is vulnerable or not:

First add to your composer.json:

     "sensiolabs/security-checker": "dev-master"

Then run:

~ composer update sensiolabs/security-checker --dev

Then add to your composer.json:

    "scripts": {
        "post-install-cmd": [
            "bin/security-checker security:check",


    "scripts": {
        "post-update-cmd": [
            "bin/security-checker security:check",

Then enjoy with:

~ composer install --dev
Loading composer repositories with package information
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Loading composer repositories with package information
Installing dev dependencies from lock file
Nothing to install or update
Generating autoload files
Security Report
No known* vulnerabilities detected.
* Disclaimer: This checker can only detect vulnerabilities that are referenced
              in the SensioLabs security advisories database.
Updating the "app/config/parameters.yml" file.
Clearing the cache for the dev environment with debug true
Installing assets using the symlink option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Symfony\Bundle\WebProfilerBundle into web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution

Encouragements in all good! I hope to make it to sflive Portland!

Sunshine PHP Report

Sunshine PHP 2013 was a very nice conference to attend. I came from Peru which is a bit far away but I met at least 4+ people coming from England. When I think of this conference I think of friends, from jj (aka jmather) to the legendary johnkary or the famous jwage and our pal kriswallsmith. I had the privilege to meet work friends and very good friends that had shaped my skills along the road. I will show here some pictures as they become available 🙂

With my friends Jarrett and Reece:

With dbu:

With assetic shirt given by krisswallsmith and photo taken by him too 🙂

With Rasmus:

With Kris:

And this space is dedicated to Javier Eguiluz http://symfony.es/noticias/2013/02/13/mi-resumen-de-la-sunshinephp-2013/ the friend who attended to me on my secret spanish conversations at sunshine.