Multiple docker images & executions


#1

Situation

Suppose I have a PHP app and I have to test the frontend workflow which is based on nodejs.

I’m not using docker on my project, but CircleCI proposes so, and it seems to look better than using a machine.

The goal

The only thing I have to do is the following:

composer install && vendor/bin/phpunit
yarn install && node_modules/.bin/gulp dump --prod

With CircleCI 1.0, this was (sort of) my config:

# circle.yml
machine:
    php:  { version: '7.1.3' }
    node: { version: '6.10.2' }

dependencies:
    override:
        - 'composer install --no-interaction --no-suggest --ignore-platform-reqs'
        - 'yarn'

test:
    override:
        - './node_modules/gulp4/bin/gulp.js dump --prod --verbose'
        - './vendor/bin/phpunit'

(It used to work very well but actually there was A LOT MORE STUFF than this in my original circle file, like coverage, etc.)

So I followed Circle 2.0 docs and tried to do something similar as base config:

# .circleci/config.yml
version: 2

jobs:
    build:
        docker:
            - image: 'php:7.1'
            - image: 'node:6.10'

        working_directory: ~/app

        steps:
            - run: 'php composer.phar install --no-interaction --no-suggest --ignore-platform-reqs'
            - run: 'yarn install'

            - run: 'node_modules/gulp4/bin/gulp.js dump --prod'
            - run: 'vendor/bin/phpunit'

Obviously, it doesn’t work, because there’s a lot of things to consider:

  • Docker images are loaded at runtime, so if you’re not using CircleCI’s images, it takes a much longer time
  • I have to configure stuff myself. With Circle 1.0, almost everything I needed was already installed.
  • Circle 2.0 doesn’t seem to execute docker “natively”, or when using multiple images, all steps seem to be run in the first docker image, or maybe I have not understood how this works, or anything else, but still, I could not make yarn work jointly with composer (which is not installed by default by the way).
  • Half the build time is dedicated to installing and configuring stuff to run my tests, and even if my tests run incredibly fast (and globally almost twice as fast as with 1.0), half the time is used to configure the environment.
  • Lots of this configuration could be cached because it doesn’t change, but it seems that there’s not much documentation about this yet (I know 2.0 is beta, but system config should be cacheable IMO).

Here comes the code

I made a gist: https://gist.github.com/Pierstoval/ee5f9372a82158fb3b80abb6a10a5d1b

This stores the old circle.yml file and the new .circleci/config.yml file.

Even though I’m glad it’s working now, I’m not using nodejs docker image at all because it doesn’t work and I have absolutely no idea on how to use it to install my dependencies with yarn.

Why is it a problem?

The problem could be summed up in two points:

  • Is it possible to cache the configuration setup which takes half the build time?
  • Is it relevant to use multiple docker images (especially the nodejs one) and if yes is it possible to use it to execute my tests? Else, if switching back to the machine option, how to use both php and node stacks?

#2

The ability to run commands on the non-primary container is coming, but we’re not there yet.

As 2.0 stands today, your best option is to build a PHP image. We have a CircleCI PHP image but it’s not fully built out yet- it’s missing xdebug and composer, for example.

Though, an immediate alternative is to run multiple jobs;

https://circleci.com/docs/2.0/defining-multiple-jobs/


#3

I’m gonna go for multiple jobs, this seems to be a good solution, as frontend workflow can be dissociated with backend one.

For the case of your CircleCI images, I hope they’re gonna be ready soon especially for PHP ones, IMO, providing at least one image with composer, phpunit and xdebug for each PHP version is part of the basics for most projects :slight_smile:

Thanks for your answer, I’m really looking forward for future updates of Circle 2.0 :smile:


#4

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.