Configuring a CD for a Ruby on Rails project using piping and a Bitbucket dock

I would like to set up continuous deployment in Bitbucket Pipelines for the Ruby on Rails / PostgreSQL / Sidekiq project, but I'm struggling to figure out how it all fits together, and in particular how to get postgres to work inside the Docker image. I am very new to Docker and Pipelines.

In my Googling, Docker talks about using docker layout to create a package, so I will have a Postgres container and a Sideqik container, and then bind them to the application container. But I'm not sure what the difference is between a package and an image, and if Bitbucket Pipelines supports packages. In the end, I want to set up intermediate deployment on Heroku, but now just getting the rspec spec to work in Pipelines would be fine.

Is there an existing public image that has already configured Ruby + PostgreSQL that I can use? If not, where to 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 

Then I 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"? 
+5
source share
2 answers

Taking the advice https://bitbucket.org/spittet/ruby-postgresql , you can easily configure your bitbucket-pipelines.yml as follows:

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

As you can see, I need to create a user with permissions to create databases.

For debugging, you can first try locally:

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

Docker compose is still not available inside Bitbucket Pipelines, so you will need to use a single Docker image that has all the dependencies you need to install.

We also struggled with finding a good Docker container with the Django Postgres stack and finished creating a custom Docker container. I described the whole process and the steps in the post: Building, testing and deploying a Django application using Bitbucket streams . You can use it as a template for your project and replace Python dependencies with Ruby.

0
source

All Articles