Setting up CD for a Ruby on Rails project with Bitbucket Pipelines and Docker

I’d love to set up continuous deployment in Bitbucket Pipelines for a Ruby on Rails / PostgreSQL / Sidekiq project, but I’m struggling to get my head around how it all fits together, and specifically how to get postgres working inside a Docker image. I’m very new to Docker and Pipelines.

In my Googling, Docker talks about using docker-compose to create a bundle, so I’d have a Postgres container and a Sideqik container, then link them with the app container. But I’m not sure what the difference is between a bundle and an image, and if Bitbucket Pipelines supports bundles. Eventually I want to set up deployments to a staging environment on Heroku, but for now just getting rspec spec to work in Pipelines would be nice.

  • Stopping docker containers by image name - Ubuntu
  • Networking among kubernetes minions
  • Faster deploy of a docker image?
  • How do I create an image and run it locally?
  • Docker container start error
  • Run Infinispan cluster with Server management console using Docker swarm
  • Is there an existing public image that has Ruby + PostgreSQL already set up that I can use? If not, where do I start? My current Dockerfile looks like this:

    FROM postgres:9.4
    FROM ruby:2.3.1-onbuild
    RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-client

    I then run docker build . and docker run -it my-image /bin/bash and the following commands:

    root@a84ad0e7c16b:/usr/src/app# postgres
    bash: postgres: command not found
    root@a84ad0e7c16b:/usr/src/app# psql 
    psql: could not connect to server: No such file or directory
      Is the server running locally and accepting
      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

  • Why do docker-compose containers stay alive after finishing up command?
  • Docker copy command to copy a jar file from target folder
  • MAC | Access application deployed on Docker from another application on VirtualBox machine
  • INFO: I/O exception ( caught when processing request to {}->unix://localhost:80: Permission denied
  • Why can't you install docker natively in osx? [closed]
  • Cannot launch interactive session in Windows IIS Docker container
  • 2 Solutions collect form web for “Setting up CD for a Ruby on Rails project with Bitbucket Pipelines and Docker”

    Taking the advice from you could easily setup your bitbucket-pipelines.yml like this:

    image: spittet/ruby-postgresql
        - step:
              - bundle install
              - /etc/init.d/postgresql start
              - sudo -u postgres sh -c 'createuser root --createdb'
              - rails db:setup RAILS_ENV=test
              - rspec

    As you may see I needed to create a user with permissions for creating databases.

    For debugging you could try locally first:

    run -i -t -v <local_directory_of_your_rails_app>:<directory_on_docker> spittet/ruby-postgresql /bin/bash
    cd <directory_on_docker>
    bundle install...

    Docker compose is still not available inside Bitbucket Pipelines, so you’ll have to use a single Docker image which has all the dependencies you need already installed.

    We’ve also struggled with finding good Docker container with Django Postgres stack and ended up building custom Docker container. I’ve described the whole process and steps in a post: Building, Testing and Deploying Django App with Bitbucket Pipelines. You can use it as a template for your project, and replace Python dependencies with Ruby.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.