VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more



Are you brilliant? We're hiring. Read more

Avoid Dependency on 3rd Party Sources With Composer

DevOps

Composer is the defacto standard dependency manager for PHP out there, also here in VG. We use it for not only our internal packages, but for all external packages like ZF2, Symfony, PHPUnit, etc. For the most parts it has been a pleasant experience, but it creates a hard dependency towards external sources as we now require these sources to be available when updating/installing.

We deploy our code with Capistrano which uses Composer to install all dependencies for each release. This essentially means we will be unable to deploy our code if a 3rd party source is unavailable (I’m looking at you GitHub!).

Since we use Composer for all our internal packages, we already had Satis set up, which basically is a package repository builder for Composer.

Our basic Satis config looked like this:

Show code
{
    "name": "VG Nett",
    "homepage": "http://internal.repo.no",
    "repositories": [
        { "type": "vcs", "url": "svn+ssh://internal-svn.server.no/svn/error-logger" },
        { "type": "vcs", "url": "https://github.com/zendframework/zf2.git" },
        { "type": "vcs", "url": "https://github.com/guzzle/guzzle.git" },
        { "type": "vcs", "url": "https://github.com/imbo/imboclient-php.git" }
    ],
    "require-all": true
}

We started adding all our external dependencies to Satis and turning on the archive function. Set up like this Satis will download local copies of all your external packages and mirror them for you.

In addition to setting up the archive feature you will also be needed to specify a new require block so that Satis can know which versions it has to have available from the external sources. Now we have a Satis configuration that looks like this:

Show code
{
    "name": "VG Nett",
    "homepage": "http://internal.repo.no",
    "repositories": [
        { "type": "vcs", "url": "svn+ssh://internal-svn.server.no/svn/vgno-error-logger" },
        { "type": "vcs", "url": "https://github.com/zendframework/zf2.git" },
        { "type": "vcs", "url": "https://github.com/imbo/imboclient-php.git" }
    ],
    "require": {
    	"vgno/error-logger": "*",
    	"zendframework/zendframework": ">=2.2.0",
    	"imbo/imboclient-php": ">=0.8.3"
    },
    "archive": {
    	"directory": "dist"
    }
}

Now we are no longer dependent on Github or any other external services being available and I feel Composer is able to install/update a lot faster now. Set up your own local Satis repository with the archive function today!

Developer at VG. @androa


0 comments

    Leave your comment