Share bundles between Symfony2 Projects

New topics about Symfony 2 should go here

Moderators: tiagojsag, dcobalt

Share bundles between Symfony2 Projects

Postby andrescamera » Thu Jul 25, 2013 4:36 pm

Hi all,

I'm wondering how's the best way to work with Symfony2 when you have several projects sharing common bundles.

In my case, all bundles are private and will continue being, and each project will be in different servers.
For instance:

api.project.com
frontend.project.com
backend.project.com

The three project have their own bundles, and a others in common. In my case, the CoreBundle contains the model and business logic.
Our team has 4 members, and all of us will be continuously updating it.

In Symfony 1.4, you could split it easily creating one application per project inside the apps folder.
In Symofny 2, it's not recommended to "adapt" it that way (https://groups.google.com/forum/?fromgr ... neojUuFiqw)

The approaches we found are:

a) All in the same project. One app.php and AppKernel.php. In the routing.yml, we specify routes with subdomains per each project.
The AppKernel loads all bundles always. Problem: Unnecessary bundles loading.

b) All in the same project, but creating different entry points: app_front.php and app_back.php.
Multiple AppKernel:
http://jolicode.com/blog/multiple-appli ... h-symfony2
https://github.com/damienalexandre/symf ... s-2.2/apps

c) Using https://github.com/vbardales/MultipleAppKernelBundle is quite similar to the previous point

d) Each bundle with his own repository. Each project install the common bundles using git submodules in the src folder

e) All commond bundles in the same repository. Each project, through symlinks, include the bundles he needs.

f) Use Satis to share the bundles between the projects. Bundles will be installed with composer in vendor/companyName folder.
Each time a user modifies a common bundle, he must go inside the bundle folder (to access to its git repository), and make the git push

cd api/vendor/company/CoreBundle
git add . && git commit ... && git push origin develop

Then, in GitHub, we configured a hook, so that each time it receive a "push event", it calls a script we have in the Satis Repository Server, to recreate the build (the packages git revision, etc).

Then, per each project (api, backed and frontend), run the composer update command.


cd api && composer update myComparny/CoreBundle && git add composer.lock && git push origin develop
cd frontend && composer update myComparny/CoreBundle && git add composer.lock && git push origin develop
cd backend && composer update myComparny/CoreBundle && git add composer.lock && git push origin develop

Then, when another team member wants to get my changes, he will have to:


cd api && git pull origin develop && composer install
cd frontend && git pull origin develop && composer install
cd backend && git pull origin develop && composer install


What would you recommend me to do? Did you ever have to face this situation?

Thanks in advanced
Regards.
andrescamera
Junior Member
 
Posts: 1
Joined: Thu Jul 25, 2013 4:34 pm

Re: Share bundles between Symfony2 Projects

Postby bnewton » Fri Jul 26, 2013 5:44 pm

I'm interested to see some feedback on this topic as well. I also have some of the same questions with a project I'm working on.

If someone could chime in on some of andrescamera questions would be greatly appreciate and I think this would be helpful for a number of us out there moving our applications to symfony.

bnewton
bnewton
Junior Member
 
Posts: 7
Joined: Fri May 24, 2013 5:28 am

Re: Share bundles between Symfony2 Projects

Postby c4d3r » Tue Aug 20, 2013 10:03 am

I agree, i am having quite a hassle with this as well
c4d3r
Junior Member
 
Posts: 28
Joined: Fri Nov 02, 2012 6:42 pm

Re: Share bundles between Symfony2 Projects

Postby tiagojsag » Wed Aug 21, 2013 6:47 pm

Hi,

Let me start by pointing out that I never actually implemented something like that, so this is off the top of my head.

I think the problem is: do your 3 projects share the same DB or not? If they don't, just split them in 3 independent projects, and you're good to go. If they do share the same DBs, however, I wouldn't recommend this, as I don't know what can happen when you mix multiple doctrine instances and their caches over the same DB.

I'd go with option A. Yes, there's an overhead associated with loading unnecessary bundles, but if you take into account Symfony's cache and APC, you'll see that it's not that significant. Besides, you can separate you code in several bundles on the same instance, making you project modular yet simple to maintain (no need to update config.yml or run composer update 3 times). IMO, simplicity tops performance, as it's usually cheaper to upgrade a server than find a fix a bug that results from weird interactions between 3 kernels running on the same project and sharing some obscure resource or config parameter.

Hope it helps

cheers
Tiago Garcia
@tiagojsag

Core Web Developer @ Shopware
http://www.shopware.de
User avatar
tiagojsag
Faithful Member
 
Posts: 885
Joined: Wed Aug 10, 2011 4:58 pm

Re: Share bundles between Symfony2 Projects

Postby c4d3r » Sun Aug 25, 2013 9:50 am

Hello

I fixed my problem by creating multiple app.php files

i had a domain exampleA.com and a domain exampleB.com that were both running different themes but the same backend
i then made app_domainA.php and app_domainB.php and call them from the corresponding domain.
Because my themes are in bundles i decided to modify the appkernel and check the environment like this:

Code: Select all
switch(strtoupper($this->getEnvironment())) {
             case "DOMAINA" :
                $bundles[] = new MYNAME\DOMAINTHEMEA\MYNAMEDOMAINTHEMEA();
              
           break;
           case "DOMAINB":
              $bundles[] = new MYNAME\DOMAINTHEMEB\MYNAMEDOMAINTHEMEB();
             break;
             default:
                $bundles[] = new MYNAME\DOMAINTHEMEA\MYNAMEDOMAINTHEMEA();
          

          }


That was for the themes, then i also needed different configurations per theme which i did like this :
Code: Select all
        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
        } else {
            $loader->load(__DIR__.'/config/websites/' . $this->getEnvironment(). '/config_'.$this->getEnvironment().'.yml');
        }


that's it, if there are any remarks, please feel free to reply them.
c4d3r
Junior Member
 
Posts: 28
Joined: Fri Nov 02, 2012 6:42 pm

Re: Share bundles between Symfony2 Projects

Postby tiagojsag » Sun Aug 25, 2013 2:59 pm

Hi,

It seems that, although not documented, the best practice for these scenarios is to actually duplicate the whole app folder, and make each domain/subdomain use the corresponding folder.

cheers
Tiago Garcia
@tiagojsag

Core Web Developer @ Shopware
http://www.shopware.de
User avatar
tiagojsag
Faithful Member
 
Posts: 885
Joined: Wed Aug 10, 2011 4:58 pm


Return to General Symfony 2 discussion

Who is online

Users browsing this forum: Bing [Bot] and 2 guests