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.

  • Why does Docker run so many processes to map ports though to my application?
  • Escaping double curly braces in Ansible
  • How to log docker build installation package errors
  • Filebeat is not forwarding logs
  • In Docker swarm mode, is there a way to get managers' information from workers?
  • How to create an serverless infrastructure with docker?
  • 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"?

  • How to set default docker environment variables
  • Docker container can't be reached from another PC
  • Private network issues with docker
  • Meaning of “$PWD”:/path/to/directory"
  • Docker (stopped container) but still I see processes and lot of memory taken?
  • WARNING: Unable to find module repositories
  • 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.