🚀  Our new eBook is out – “CI/CD for Monorepos.” Learn how to effectively build, test, and deploy code with monorepos. Download now →

Define your CI/CD environment with Docker

CI/CD for Docker and Kubernetes

The range of applications that you can run on Semaphore keeps growing. After native support for iOS, today we’re happy to announce that you can run your CI/CD in any Docker image. This means that Semaphore now supports any technology stack that works with Docker out of the box.

Docker has become a standard for packaging and deploying cloud applications, APIs, and microservices. Semaphore has supported building and running containers via full access to the Docker CLI for a long time. However, we’ve heard loud and clear from developers who wanted to use the same environment in development, CI/CD, and production: it should be easier than running raw Docker commands.

A real-world project rarely runs in a single Docker container. So Semaphore lets you combine multiple containers into a single environment of networked services.

Here’s an example how you’d define an agent for a web application:

agent:
  machine:
    type: e1-standard-2

  containers:
    - name: main
      image: registry.semaphoreci.com/ruby:2.6.1
      env_vars:
        - name: DATABASE_URL
          value: "postgres://postgres:keyboard-cat@db"
        - name: RAILS_ENV
          value: test

    - name: db
      image: registry.semaphoreci.com/postgres:10
      env_vars:
        - name: POSTGRES_PASSWORD
          value: keyboard-cat

In the example above:

  • The first container in the containers list is the one that will execute the jobs.
  • We’re using a custom Ruby image built by Semaphore.
  • The second container is providing PostgreSQL service to the main container and is available via DNS by the hostname db.

For your convenience, Semaphore provides a container registry with a number of pre-built images that are optimized for CI/CD.

Using Public and Private Registries

You can run CI/CD jobs in your own Docker images. Semaphore can pull them from both public and private registries.

Consult the latest Semaphore documentation on how to authenticate to a public or private Docker registry.

Semaphore can push and pull from AWS Elastic Container Registry (ECR), Docker Hub, Google Container Registry (GCR), Quay.io, and any other container registry.

Is the new Docker-based environment for you?

Docker-based agents will be first-class citizens alongside Linux and macOS platforms. For several new technologies that we will soon announce support for, the Docker-based approach will be the way to go.

We will continue to update the Linux and macOS platforms with the selected software stack. Semaphore will not force you to use a Docker image for your existing projects.

However, if your Semaphore configuration includes significant software customization steps, we recommend adopting a Docker-based approach in which you’ll use an image that contains exactly the dependencies that you need, and nothing else.

Get started

To learn more about available options for running Docker-based agents and using them in your projects, refer to Semaphore documentation.

Happy building!

Have a comment? Join the discussion on the forum