14
.
11
.
2023
14
.
11
.
2018
Ruby on Rails
Backend
Tutorial

Docker hosted on Jelastic

Marcin Prokop
Ruby Developer

Two years ago we introduced Docker to our company. One of our projects was complex in terms of deployment architecture and scalability. We were looking for a solution which allows us to simplify the process of deployment and scaling client's instances in the future. Docker turned out as a very good tool to isolate apps into containers with all needed dependencies and treat them as block boxes. They are easily portable from machine to machine and basically, we can host them whenever we want if there Docker engine is installed. I think it doesn't make sense describing Docker more, because there are already a lot of articles about it, not to mention excellent Docker documentation.

The next question was: where to host our docker containers? There were various options from dedicated servers to PaaS solutions. As a company, we don't deal with server management and prefer using Heroku for our apps. That's why we looked more closely at solutions that do not require care of the servers. After long research, we decided to go with Jelastic.

In few words, Jelastic is a complex dev platform which combines Platform as a Service (PaaS) and Container as a Service cloud models. It supports deployment for many technologies, including Python, Java, PHP and Docker as well. With automatic scalability based on pay-as-you-go model you don't have to care about resources management. Moreover Jelastic came with rich API which is helpful to automate many things outside of their panel. For more information about this platform, I recommend visit this post.

Image from jelastic.com

In this article I will show how to simply deploy dockerized Rails app. Let's start with the simple Docker image for Rails. I assumed that we have a Rails app which uses an external database (e.g. Postgresql) and has generated scaffold for posts (title and body).

FROM ruby:2.5.1

RUN apt-get update -qq \
   && apt-get install -y --no-install-recommends \
   libpq-dev \
   git \
   nodejs \
   vim \
   && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY Gemfile .
COPY Gemfile.lock .

RUN bundle install --without test development
COPY . .

RUN chmod +x docker/launch.sh

CMD ./docker/launch.sh

We are not doing much in this Dockerfile, just installing necessary libs, copy project files, install gems and finally run the application. Also I like put docker things in docker directory. Let's build it.

docker build -t b4k3r/sample-app .

And push to the registry (can be a Docker or private). Later Jelalstic will fetch the image from this registry to run the app.

docker push b4k3r/sample-app

Let's move to Jelastic part. The first thing we need to do is create an environment. The environment in Jelastic is like a private space or an independent virtual machine for your application environment. In the environment, among other things, you can put environment variables, define volumes or adjust resources for your app. As you can see, there is also vertical and horizontal scaling. In the vertical scaling, you can adjust resources like ram, CPU by cloudlets. Cloudlet is the unit which represents a specific amount of RAM and CPU clocking. Below, on the right side system automatically calculates estimation cost.

After clicking "Select container" we can find and select our image which was previously built and pushed.

Of course, if we store Docker images on a different repository, we can have access to them through Jelastic as well. Let's do the same for the database image.

Now we have defined two containers. Let's move to links and environment variables part. Just like in Docker, Jelastic allows defining a connection between containers of a single environment aka links and environment variables.

Jelastic automatically adds some default environment variables to containers.

We can't forget about volumes which are useful to prevent losing dynamic data in containers. Jelastic supports it as well, even remote storage!

Basically, that's it. We configured production environment for our simple Rails app.

Conclusion

In our project we haven't used many features which Jelastic offers. What interested us, were Docker support and no server management. Did Jelastic do job? Quite good but there were some issues with stability, for example with disappearing environment variables after redeploying containers. Despite this, support from Jelastic team was excellent (I hope now also :) ) and guys was fixing issues as soon as possible. In the next article I will write how we created complex deployment architecture using Jelastic, Docker and Jekins.

Marcin Prokop
Ruby Developer

Check my Twitter

Check my Linkedin

Did you like it? 

Sign up To VIsuality newsletter

READ ALSO

Safe navigation operator '&.' vs '.try' in Rails

14
.
11
.
2023
Mateusz Woźniczka
Ruby on Rails
Backend
Ruby
Tutorial

What does the ||= operator actually mean in Ruby?

14
.
11
.
2023
Mateusz Woźniczka
Ruby on Rails
Backend
Ruby
Tutorial

How to design an entity - DDD in Ruby on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Domain-Driven Design
Backend
Tutorial

Entity - DDD in Ruby on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Domain-Driven Design
Backend
Tutorial

Should I use instance variables in Rails views?

14
.
11
.
2023
Mateusz Woźniczka
Ruby on Rails
Frontend
Backend
Tutorial

Data Quality in Ruby on Rails

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Backend
Software

We started using Event Storming. Here’s why!

14
.
11
.
2023
Mariusz Kozieł
Event Storming
Visuality

First Miłośnicy Ruby Warsaw Meetup

14
.
11
.
2023
Michał Łęcicki
Conferences
Visuality

Should I use Action Filters?

14
.
11
.
2023
Mateusz Woźniczka
Ruby on Rails
Backend
Tutorial

Value Object - DDD in Ruby on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Domain-Driven Design
Backend
Tutorial

Introduction to DDD in Ruby on Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Domain-Driven Design
Backend
Tutorial

Safe data migrations in Rails

17
.
03
.
2024
Paweł Strzałkowski
Ruby on Rails
Backend
Tutorial

I love dev, and so do we!

14
.
11
.
2023
Michał Łęcicki
Software
Conferences

Updated guide to recruitment process at Visuality

14
.
11
.
2023
Michał Łęcicki
Visuality
HR

Visuality Academy for wannabe Junior Engineers

14
.
11
.
2023
Michał Piórkowski
HR
Visuality

How to approach funding as an MVP

14
.
11
.
2023
Michał Piórkowski
Business
Startups

Visuality 13th birthday

14
.
11
.
2023
Michał Piórkowski
HR
Visuality

How To Receive Emails With a Rails App in 2021

14
.
11
.
2023
Michał Łęcicki
Ruby on Rails
Tutorial

Project Quality in IT - How to Make Sure You Will Get What You Want?

02
.
10
.
2024
Wiktor De Witte
Ruby on Rails
Project Management
Business

5 Trends in HR Tech For 2021

14
.
11
.
2023
Maciej Zdunek
Business
Project Management