How do I define my build with Docker compose?

Fire CI can spin up a docker compose environment to setup your app and run your tests.

You just need to add a YAML .fire.yml as below at the root of your repository.

version: 2

pipeline:
  dockercomposefile: docker-compose-ci.yml

The build that Fire CI will execute is equivalent to running the following command in your cloned working copy:

docker-compose -f docker-compose-ci.yml up

The command is incomplete as we add other flags but you get the idea.

The name of the compose file to use should be specified in the .fire.yml file. This way you can have a dedicated file for CI runs called docker-compose-ci.yml for example.

Fire CI will use as success code the exit code of the first exiting container in your compose project. If the code is 0 the build will be considered a success. Once one container exits the whole compose project will be put down.

All containers of compose runs made by Fire CI are prefixed by 'fireci-' so they won't interfere with your running compose containers if you have any.

IMPORTANT: What we want to achieve here is a CI build that needs to end so you need to define your compose file in a way where one of the containers is basically the test runner and exits with a code that reflects on whether the tests have finished with success or not.

An example docker-compose.yml file performing API end to end testing could be:

version: '3.1'
services:
  db:
    image: postgres
    environment:
      POSTGRES_USER: john
      POSTGRES_PASSWORD: mysecretpassword
    expose:
      - 5432

  myapp:
    build: .
    image: myapp
    command: yarn start
    expose:
      - 8000
    depends_on:
      - db

  myapp-tests:
    image: myapp
    command: dockerize -wait tcp://db:5432 -wait tcp://myapp:8000 -timeout 10s bash -c "node db/init.js && yarn test"
    depends_on:
      - db
      - myapp

The example above spawns a Postgres DB instance, builds our app and starts the server on port 8000. Then it runs a third container called 'myapp-tests' that executes API tests against the running 'myapp' container. The 'myapp-tests' container will exit after the tests are run which will tell Fire CI what the result of the tests is and that it can put down the whole environment.

You can checkout the full working project for this example.


What next?

The other ways of configuring your builds are through YAML files or a Dockerfile:


If you have questions or ideas do not hesitate to contact us at support@fire.ci.