Telling Symfony to Use Cached Validation From Doctrine Cache Bundle Provider

Right now Symfony on 2.7-2.8 and probably until before 3.0 will still support apc type validation caching. This will be dropped soon, at least the class support. You could still use apc past that point however you would have to wrap your ApcCache class into a DoctrineCache. The DoctrineCache is a means to adapt any Cache service implementing Doctrine\Common\Cache\Cache interface into a Symfony caching service for validation.

How this looks in code follows:

-        cache: apc
+        cache: vendor.validation_cache.doctrine 
+        vendor_filesystem_validation_cache:
+            file_system:
+                extension: cache
+                directory: %kernel.root_dir%/cache/doctrine
+    vendor.validation_cache.doctrine:
+        class: Symfony\Component\Validator\Mapping\Cache\DoctrineCache
+        arguments:
+            - @doctrine_cache.providers.vendor_filesystem_validation_cache

ArrayCache and FilesystemCache are implementations of doctrine caches, but in order to tube them in to make them available to symfony we have to use this DoctrineCache wrapper.

One extra trick to test services is to include config_prod.yml in config_dev.yml imports and comment the first lines of config_prod.yml importing config.yml since it is already imported in config_dev.yml. Then you can exercise your container:debug –show-private command without problems to test and ensure things are working correctly.


Doctrine File System Caching with Doctrine Cache Bundle

Some people had experience some difficulty configuring a filesystem cache type. Symfony by default comes with some caching because of the doctrine bundle, however if one wants to extend to more types one has to install the Doctrine Cache Bundle which brings more provides into place. Now if you want to still instruct doctrine to cache metadata, the results and the query caching with these service providers then this is the way:

            type: service
            id: doctrine_cache.providers.vendor_filesystem_metadata_cache
            type: service
            id: doctrine_cache.providers.vendor_filesystem_result_cache
            type: service
            id: doctrine_cache.providers.vendor_filesystem_query_cache

                extension: cache
                directory: %kernel.root_dir%/cache/doctrine
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine

I hope this resolves it for you when you need it.

Docker Symfony Development Box with Data Containers

Data containers are containers where you define a path or folder to be mounted onto other containers. The data here can be read only or writeable. This means that for when you need a swap or temp storage for your projects you can use these containers since any other containers that are perhaps mounted on your host will not be writeable.

So we start by defining the cache and logs container as follows:

// cache_container
FROM busybox
RUN mkdir -p /var/cache/repay/dev
VOLUME /var/cache/repay
ENTRYPOINT chmod -R 777 /var/cache/repay; /usr/bin/tail -f /dev/null


// logs_container
FROM busybox
RUN mkdir -p /var/log/repay/
VOLUME /var/log/repay
ENTRYPOINT chmod -R 777 /var/log/repay; /usr/bin/tail -f /dev/null

Here is how you piece everything together. You build those containers, notice that they have entry points so that after running that command gets invoked setting the right permissions for those folders when they get ran.

After the symfony box gets build you can run the whole thing and attach/mount the data containers to your main host shared container where the code is:

!#/usr/bin/env bash
# troubleshoot
# docker exec -i -t repay bash
# kill all previous containers
docker rm -f $(docker ps -a -q)
docker build --rm -t "cache_container:v1" docker/cache_container
docker build --rm -t "logs_container:v1" docker/logs_container
docker run -d --name repay_cache_container cache_container:v1
docker run -d --name repay_logs_container logs_container:v1
# build symfony project box
docker build -rm -t repay .
# run symfony container
docker run \
    -v $PWD:/srv \
    -e DB_NAME=repay \
    -e INIT=bin/reload \
    --volumes-from repay_cache_container:rw \
    --volumes-from repay_logs_container:rw \
    --name repay_development_webserver \
    -itP repay
This can work thanks to adding in the kernel a couple of methods:
<pre lang="php">
     * {@inheritdoc}
    public function getCacheDir()
        return '/var/cache/repay/'.$this->environment;
     * {@inheritdoc}
    public function getLogDir()
        return '/var/log/repay';

I grabbed the top Dockerfile from an adaptation of ubermuda repo for symfony docker:

FROM debian:jessie
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y
RUN apt-get install -y nginx php5-fpm php5-mysqlnd php5-cli mysql-server supervisor
RUN sed -e 's/;daemonize = yes/daemonize = no/' -i /etc/php5/fpm/php-fpm.conf
RUN sed -e 's/;listen\.owner/listen.owner/' -i /etc/php5/fpm/pool.d/www.conf
RUN sed -e 's/;listen\.group/' -i /etc/php5/fpm/pool.d/www.conf
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
ADD vhost.conf /etc/nginx/sites-available/default
ADD supervisor.conf /etc/supervisor/conf.d/supervisor.conf
RUN chmod 777 /
VOLUME ["/srv"]
CMD ["/usr/bin/supervisord"]

Now you can enjoy!

My SSH KeyChain And Phansible

I built a box with phansible and was getting this error:

~ vagrant provision                                                                                 Luiss-MacBook-Pro-3 [7:39:07]
==> default: Running provisioner: ansible...
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
fatal: [] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
TASK: [init | Update apt] *****************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
           to retry, use: --limit @/Users/cordoval/playbook.retry             : ok=0    changed=0    unreachable=1    failed=0
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

The reason was that my host was not connecting to the vagrant box because I had several things configured in my ~/.ssh/config. So what I did was:

# added entry to ~/.ssh/config
  User vagrant
  IdentitiesOnly yes
  IdentityFile ~/.ssh/vagrant
# added in /etc/hosts  project.local

And you can check with ssh-add -L.

Try to test with ssh -v

Then you will be able to successfully run the rest of your playbooks:

~ vagrant provision                                                                                 Luiss-MacBook-Pro-3 [7:40:45]
==> default: Running provisioner: ansible...
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: []
TASK: [init | Update apt] *****************************************************
ok: []
TASK: [init | Install System Packages] ****************************************
changed: [] => (item=curl,wget,python-software-properties)
TASK: [init | Add ppa Repository] *********************************************
changed: []


Plug Dev Flow with Gush and Bldr into Vagrant

I recently added Gush and Bldr to a vagrant box generated by I also plugged librarian instead of the regular git tracking of the whole module set. This is a more pro way than to keep track of 2k+ files that are purely git repositories and that are already versioned.

So here are the sparse instructions. For Gush, this is inside vagrant/puphpet/puppet/nodes/gush.pp, yes you just add a gush.pp puppet file into your nodes:

  $gush_github   = ''
  $gush_location = '/usr/share/gush'
  exec { 'delete-gush-path-if-not-git-repo':
    command => "rm -rf ${gush_location}",
    onlyif  => "test ! -d ${gush_location}/.git",
    path    => [ '/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/' ],
  } ->
  vcsrepo { $gush_location:
    ensure   => present,
    provider => git,
    source   => $gush_github,
    revision => 'master',
  } ->
  composer::exec { 'gush':
    cmd     => 'install',
    cwd     => $gush_location,
    require => Vcsrepo[$gush_location],
  } ->
  file { 'symlink gush':
    ensure => link,
    path   => '/usr/bin/gush',
    target => "${gush_location}/bin/gush",

This will nicely plug gush into your vagrant and you just have to reprovision with:

vagrant provision

I also provisioned the dev popular script but via the Vagrantfile, if you think is best to provision this custom file via a pp file then set a good justification for it on the comments. I think it is ok for now and here it is:

// Vagrantfile

   if !data['vagrant']['host'].nil? = data['vagrant']['host'].gsub(':', '').intern
+  config.vm.provision :shell, :path => 'puphpet/shell/'

And place the dev file inside ${VAGRANT_CORE_FOLDER}/files/dot/dev:

#!/usr/bin/env bash

bldr=$(which bldr)
if [ -x "$bldr" ] ; then
    $bldr install
    $bldr run $1
    if [ ! -f ./bldr.phar ]; then
        curl -sS | php
    ./bldr.phar install
    ./bldr.phar run $1

And also the shell under ‘puphpet/shell/':


VAGRANT_CORE_FOLDER=$(cat '/.puphpet-stuff/vagrant-core-folder.txt')

sudo su
chmod +x "${VAGRANT_CORE_FOLDER}/files/dot/dev"
cp "${VAGRANT_CORE_FOLDER}/files/dot/dev" '/usr/local/bin/dev'

The last trick is with puppet-librarian which you can ruby install it. This tool is like a composer but for modules. So all that is under vagrant/puphpet/puppet/modules should be added to .gitignore on your project and you just need to run puppet-librarian install like in composer.


In order to get the right sha1 to which your working puppet was working then just switch to the right Puppetfile replacing it with:

forge ""
mod 'puppetlabs/apache',
    :git => '',
    :ref => 'f12483b'
mod 'puppetlabs/apt',
    :git => '',
    :ref => '1.4.2'
mod 'puphpet/beanstalkd',
    :git => '',
    :ref => '5a530ff'
mod 'tPl0ch/composer',
    :git => '',
    :ref => '1.2.1'
mod 'puppetlabs/concat',
    :git => '',
    :ref => '1.1.0'
mod 'elasticsearch/elasticsearch',
    :git => '',
    :ref => '0.2.2'
mod 'garethr/erlang',
    :git => '',
    :ref => '91d8ec73c3'
mod 'puppetlabs/firewall',
    :git => '',
    :ref => '1.1.1'
mod 'actionjack/mailcatcher',
    :git => '',
    :ref => 'dcc8c3d357'
mod 'puppetlabs/mongodb',
    :git => '',
    :ref => '0.8.0'
mod 'puppetlabs/mysql',
    :git => '',
    :ref => '2.3.1'
mod 'jfryman/nginx',
    :git => '',
    :ref => 'v0.0.9'
mod 'puppetlabs/ntp',
    :git => '',
    :ref => '3.0.4'
mod 'puphpet/php',
    :git => '',
    :ref => 'a1dad7828d'
mod 'puppetlabs/postgresql',
    :git => '',
    :ref => '3.3.3'
mod 'puphpet/puphpet',
    :git => '',
    :ref => '9253681'
mod 'example42/puppi',
    :git => '',
    :ref => 'v2.1.9'
mod 'daenney/pyenv',
    :git => '',
    :ref => '062ae72'
mod 'puppetlabs/rabbitmq',
    :git => '',
    :ref => '5ce33f4968'
mod 'puphpet/redis',
    :git => '',
    :ref => 'd9b3b23b0c'
mod 'maestrodev/rvm'
mod 'puppetlabs/sqlite',
    :git => '',
    :ref => 'v0.0.1'
mod 'petems/swap_file',
    :git => '',
    :ref => '39582afda5'
mod 'nanliu/staging',
    :git => '',
    :ref => '0.4.0'
mod 'ajcrowe/supervisord',
    :git => '',
    :ref => '17643f1'
mod 'puppetlabs/stdlib'
mod 'puppetlabs/vcsrepo',
    :git => '',
    :ref => '0.2.0'
mod 'example42/yum',
    :git => '',
    :ref => 'v2.1.10'

That is it! Encouragements in all good! and give retweets please!