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

LLM Embeddings in Ruby - Paweł Strzałkowski

LLM Embeddings in Ruby

17
.
03
.
2024
Paweł Strzałkowski
Ruby
LLM
Embeddings
ChatGPT
Ollama
Handling Errors in Concurrent Ruby, Michał Łęcicki

Handling Errors in Concurrent Ruby

14
.
11
.
2023
Michał Łęcicki
Ruby
Ruby on Rails
Tutorial
Recap of Friendly.rb 2024 conference

Insights and Inspiration from Friendly.rb: A Ruby Conference Recap

02
.
10
.
2024
Kaja Witek
Conferences
Ruby on Rails

Covering indexes - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Ruby on Rails
Postgresql
Backend
Ula Sołogub - SQL Injection in Ruby on Rails

The Deadly Sins in RoR security - SQL Injection

14
.
11
.
2023
Urszula Sołogub
Backend
Ruby on Rails
Software
Michal - Highlights from Ruby Unconf 2024

Highlights from Ruby Unconf 2024

14
.
11
.
2023
Michał Łęcicki
Conferences
Visuality
Cezary Kłos - Optimizing Cloud Infrastructure by $40 000 Annually

Optimizing Cloud Infrastructure by $40 000 Annually

14
.
11
.
2023
Cezary Kłos
Backend
Ruby on Rails

Smooth Concurrent Updates with Hotwire Stimulus

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

Freelancers vs Software house

02
.
10
.
2024
Michał Krochecki
Visuality
Business

Table partitioning in Rails, part 2 - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Backend
Postgresql
Ruby on Rails

N+1 in Ruby on Rails

14
.
11
.
2023
Katarzyna Melon-Markowska
Ruby on Rails
Ruby
Backend

Turbo Streams and current user

29
.
11
.
2023
Mateusz Bilski
Hotwire
Ruby on Rails
Backend
Frontend

Showing progress of background jobs with Turbo

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

Table partitioning in Rails, part 1 - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Backend
Ruby on Rails

Table partitioning types - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Backend

Indexing partitioned table - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Backend
Postgresql
SQL Views in Ruby on Rails

SQL views in Ruby on Rails

14
.
11
.
2023
Jan Grela
Backend
Ruby
Ruby on Rails
Postgresql
Design your bathroom in React

Design your bathroom in React

14
.
11
.
2023
Bartosz Bazański
Frontend
React
Lazy Attributes in Ruby - Krzysztof Wawer

Lazy attributes in Ruby

14
.
11
.
2023
Krzysztof Wawer
Ruby
Software

Exporting CSV files using COPY - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Postgresql
Ruby
Ruby on Rails
Michał Łęcicki - From Celluloid to Concurrent Ruby

From Celluloid to Concurrent Ruby: Practical Examples Of Multithreading Calls

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

Super Slide Me - Game Written in React

14
.
11
.
2023
Antoni Smoliński
Frontend
React
Jarek Kowalewski - ILIKE vs LIKE/LOWER - Postgres Stories

ILIKE vs LIKE/LOWER - Postgres Stories

14
.
11
.
2023
Jarosław Kowalewski
Ruby
Ruby on Rails
Postgresql