Skip to content

zanetagebka/rails7-startkit

 
 

Repository files navigation

Rails 7. Start Kit

Rails 7 App with Preinstalled Tools is Ready in Minutes!

Why?

Usually It is difficult and time consuming to setup a typical Rails environment from scratch.

Since now if you have Ruby and Docker then you have working Rails environment in about 5 minutes without any manual efforts.

What is under the hood?

Technology Logo Description Technology Logo Description
docker Docker
Containerization for Services
pgsql PostgresSQL
Database
ruby Ruby 3.2 rails7 Rails 7
sphinx Sphinx
Full Text Search Engine
ts Thinking Sphinx
Ruby Connector to Sphinx
elastic Elasticsearch
The world’s leading Search engine
chewy Chewy
Ruby Connector to Elasticsearch
redis Redis
In-memory data store for Caching
sidekiq Sidekiq
Job Scheduler and Async Tasks Executor
puma Puma
Application Web Server
New Things ...Coming Soon

All trademarks, logos and brand names are the property of their respective owners.

Prerequisites

On your host you have:

  • Ruby 2+
  • Docker
  • Git

How to start?

ONE!

git clone https://github.com/the-teacher/rails7-startkit.git

TWO!

cd rails7-startkit

THREE!

bin/setup

You will see something like that:

1. Launching PgSQL container
2. Launching Rails container
3. Installing Gems. Please Wait
4. Create DB. Migrate DB. Create Seeds
5. Launching Redis Container
6. Generate Sphinx Config
7. Launching Sphinx Container
8. Indexing Article Model
9. Launching Rails App with Puma
10. Launching Sidekiq
11. Visit: http://localhost:3000

To Run All Containers

From the root of the project

bin/start
Output
[+] Running 4/4
  ⠿ Container rails7app-redis-1   Running
  ⠿ Container rails7app-psql-1    Running
  ⠿ Container rails7app-sphinx-1  Running
  ⠿ Container rails7app-rails-1   Running

To See Running Containers

From the root of the project

bin/status
Output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NAMES                IMAGE                          PORTS                    CONTAINER ID
rails7app-rails-1    iamteacher/rails7:2023.arm64   0.0.0.0:3000->3000/tcp   1ed64ee7ca1c
rails7app-sphinx-1   macbre/sphinxsearch:3.4.1      36307/tcp                498ca21f4be3
rails7app-redis-1    redis:7.0.5-alpine             6379/tcp                 5bb16abc7ff8
rails7app-psql-1     postgres:15.1-bullseye         5432/tcp                 63669cc683c7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docker compose -f docker/docker-compose.yml exec  rails /bin/bash -c 'ps a | grep puma'
   16 pts/1    Ssl+   0:01 puma 5.6.5 (tcp://0.0.0.0:3000) [app]
   33 pts/1    Sl+    0:01 puma: cluster worker 0: 16 [app]

docker compose -f docker/docker-compose.yml exec  rails /bin/bash -c 'ps a | grep sidekiq'
   23 pts/2    Ssl+   0:05 sidekiq 7.0.2 app [0 of 1 busy]

To Get In a Container

Rails

bin/open rails

PgSQL

bin/open psql

Redis

bin/open redis

Sphinx

bin/open sphinx

To Stop All Containers

From the root of the project

bin/stop
Output
[+] Running 4/4
  ⠿ Container rails7app-redis-1   Removed
  ⠿ Container rails7app-psql-1    Removed
  ⠿ Container rails7app-sphinx-1  Removed
  ⠿ Container rails7app-rails-1   Removed

Conventions and Agreements

For demonstration, education and maintainance purposes I use the following approach:

Data

  • All services' data related folders are placed in ./db
  • All folders are UPPERCASED
./db
├── ELASTIC
├── PGSQL
├── REDIS
└── SPHINX

Configuration Files

  • All services' configurations are placed in ./config
  • All configs are _UNDERSCORED and UPPERCASED
./config
├── _SPHINX (<< folder)
├── _CONFIG.yml
├── _PUMA.rb
├── _SIDEKIQ.yml
└── _THINKING_SPHINX.yml

Initialazers

  • All services' initializers are placed in ./config/initializers
  • All files are _UNDERSCORED and UPPERCASED
./config/initializers/
├── _CHEWY.rb
├── _CONFIG.rb
├── _REDIS.rb
├── _SIDEKIQ.rb
└── _SPHINX.rb

Rails user

As a user to own files and run Rails inside a container I use

user:group => lucky:lucky => 7777:7777

If you would like to run the project on a linux environment then:

  • create group lucky (7777) and user lucky (7777)
  • run the project with RUN_AS=7777:7777 option

How to Run Tests

From the root of the project

  bin/open rails

Now you are in the Rails container and you can do everything as usual

  RAILS_ENV=test rake db:create
  rake test

Questions and Answers

What is an idea of this project?

For many years Rails gives you freedom to choose development tools. Different databases, different paginators, different search engines, different delayed job solutions.

It is great. But all the time you need to choose something and install it from scratch.

I think I did my choice about many solutions and tools.

I want to install my minimal pack of tools now and reuse my StartKit every time when I start a new project.

With Docker I can roll out my minimal application with all required preinstalled tools in minutes, not in hours or in days.

Why did you create this project?

I didn't work with Rails last 4 or 5 years. I wanted to learn new approaches and techniques. I found that there is still no a simple way to setup a blank app with most popular tools.

So. Why not to make my own playground?

How do you choose technologies for the StartKit?

I use tools that I like or want to learn.

I use tools that I think are the most popular ones.

It looks good for development. What about production?

I'm not a DevOps, but I have a vision how to deploy this code to production.

Right now it is not described somehow. It is in my plans.

Why did you use 2 Search engines in this project?

Sphinx is a tool what I know. ElasticSearch I'm going to learn. If you do not need one of them it is not a problem.

It is always easier to cut off than install and set up.

TODO

License

MIT

About

Rails7 StartKit. Launch App in minutes!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 71.9%
  • HTML 19.8%
  • Dockerfile 6.0%
  • CSS 2.2%
  • JavaScript 0.1%