Giter VIP home page Giter VIP logo

rails7-startkit's Introduction

Rails 7. Start Kit

Rails 7. Start kit. v2.1

Install and Run Ruby on Rails in Minutes!

Copy & Paste in your terminal

❤️ Linux / MacOS

git clone https://github.com/the-teacher/rails7-startkit.git && \
  cd rails7-startkit && \
  ruby bin/setup

💙 Windows

git clone https://github.com/the-teacher/rails7-startkit.git & cd rails7-startkit & ruby bin/setup

What Is That?

Rails App in a Docker container with some popular preinstalled tools.

Why Do I Need It?

Save hours, days or weeks on setting up a typical Rails app.

What Cases for Using It?

  • You start new Rails project
  • You need a playground for experiments
  • You learn Rails and related technologies
  • You teach people or record videos about Rails
  • You are going to write a new article about Rails

How it works

Rails 7. Start Kit

What Is Under the Hood?

Logotype Description Why it was added

Main

docker Docker Helps to keep all required services in containers. To have fast and predictable installation process in minutes. Docker Images are here.
ruby Ruby 3.2 Most recent version of Ruby
rails7 Rails 7 Most recent version of Rails
pgsql PostgresSQL Most popular relational database

Cache and Delayed Jobs

redis Redis In-memory data store. For caching and as a dependency of Sidekiq
sidekiq Sidekiq Job Scheduler and Async Tasks Executor. Can be used as a stand alone tool or as ActiveJob backend
whenever whenever Linux Cron based periodical tasks

Full Text Search

elastic Elasticsearch The world’s leading Search engine
chewy Chewy Ruby Connector to Elasticsearch

Front-end

bootstrap Bootstrap Old but Gold Framework for Web
import-maps ES Build An extremely fast bundler for the web
import-maps Import Maps Rails' recommended way to process JavaScript
sprockets Sprockets Rack-based asset packager

Application Configuration

gem dotenv-rails gem "dotenv" ENV variables management tool
gem config gem "config" Configuration management tool

Application Level

puma Nginx Web Server. Reverse Proxy. Load Balancer. Caching, Streaming etc.
puma Puma Application Web Server. To launch Rails app
devise Devise Authentication solution for Rails + Emails confirmations
ActiveStorage ActiveStorage Default Cloud Storage Solution for Rails
faker Faker Fake data for development and testing
kaminari Kaminari Pagination solution
sanitize Sanitize Sanitization of a dangerous users' input
letter_opener mailcatcher Email previewer for development

Code Quality

rspec RSpec Testing Framework for Rails
rspec Rubocop Ruby static code analyzer (a.k.a. linter) and formatter.
breakman Breakman Static analysis tool | Security Vulnerabilities.
rspec SimpleCov Code coverage for Ruby (and Rails)

What I'm going to add...

Logotype Description Why it was added
devise Devise Login with Facebook and Google

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

Installation and Running

Copy & Paste in your terminal

❤️ Linux / MacOS

git clone https://github.com/the-teacher/rails7-startkit.git && \
  cd rails7-startkit && \
  ruby bin/setup

💙 Windows

git clone https://github.com/the-teacher/rails7-startkit.git & cd rails7-startkit & ruby bin/setup

You will see something like that:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rails 7. StartKit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What was done:
1. Pull all required Images

2. Launching ElasticSearch Container
3. Launching Mailcatcher Container
4. Launching PgSQL Container
5. Launching Redis Container
6. Launching Rails Container

7. Correcting Permissions for Linux
8. Installing Gems
9. Turn off some ElasticSearch settings
10. Prepare Database (Create, Migrate, Create Seeds)
11. Indexing Article Model

12. Quality: Rubocop
13. Quality: RSpec with SimpleConv
14. Quality: Breakman

15. Yarn: Install Node Packages
16. Yarn: Build JS/CSS Assets
17. Precompile Assets

18. Launching Sidekiq
19. Launching Rails App with Puma

20. Visit Rails App: http://localhost:3000
21. Visit Mail Service: http://localhost:1080
22. Visit ElasticSearch: http://localhost:9200
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Welcome to RAILS 7!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bin/ commands

❤️ ⚠️ bin/exec - Linux and MacOS users can skip using ruby

💙 ⚠️ ruby bin/exec - Windows users should use ruby explicitly

From the root of the project

Command Description
Most important
ruby bin/setup Download images, run containers, initialize data, launch all processes.
ruby bin/open Get in Rails Container
rubyc bin/exec [CMD] Execute a command ([CMD]) from Rails7StartKit module

bin/open command

Command Description
Get in a container
ruby bin/open [NAME] Get in a Container. [NAME]

[NAME] Values: rails,psql, redis, elastic, mailcatcher.

Default value is: rails.

bin/exec command

All Possible Module Methods
  • breakman
  • cache
  • check_docker!
  • check_docker_compose_v2!
  • check_docker_running!
  • chewy_index
  • chewy_reset
  • container_bash_exec
  • container_exec
  • containers_information
  • cron_start
  • cron_stop
  • docker_compose
  • init_nvm
  • log_puma
  • log_server
  • log_sidekiq
  • print_methods
  • prompt!
  • puma_dev_start
  • puma_restart
  • puma_start
  • puma_stop
  • rails7_header
  • rails7_ready
  • rails7_startkit_greetings!
  • rails_assets_precompile
  • rails_db_migrate
  • rails_db_prepare
  • rails_install_gems
  • reset
  • restart
  • restart_all
  • rspec
  • rspec_with_cov
  • rubocop
  • rubocop_fix
  • setup!
  • sidekiq_start
  • sidekiq_stop
  • start
  • start_all
  • start_all_containers
  • status
  • stop
  • stop_all
  • stop_all_containers
  • system!
  • turn_off_elastic_settings
  • whenever_show
  • whenever_start
  • whenever_stop
  • yarn_build
  • yarn_install
Command Description

➡️ Execute

ruby bin/exec [CMD] Execute a command ([CMD]) from Rails7StartKit module

➡️ Start/Stop/Restart

ruby bin/exec start Start processes in rails container
ruby bin/exec stop Stop processes in rails container
ruby bin/exec restart bin/exec stop + bin/exec start
ruby bin/exec start_all Start processes and containers
ruby bin/exec stop_all Stop processes and containers
ruby bin/exec restart_all bin/exec stop_all + bin/exec start_all

➡️ Helpers

ruby bin/exec status To see running containers and launched services
ruby bin/exec cache Toggle caching in development and restart web server
ruby bin/exec index Run Search engines indexation
ruby bin/exec reset Reset data of services in ./db folder

Prerequisites

On your host you have:

  • Any version of Ruby
  • Any version of Git
  • Any version of Docker

Conventions and Agreements

Show details

For demonstration, education and maintainance purposes I use a bit unsusual approach to name some files.

I _UNDERSCORE and UPPERCASE some files and folders to move them on the top of a folder and to make them more visible and to highlight their importance.

Data

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

Configuration Files

  • All services' configurations are placed in ./config
  • All configs are _UNDERSCORED and UPPERCASED
./config
├── _CONFIG.yml
├── _PUMA.rb
└── _SIDEKIQ.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

Rails user

Show Details

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

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.

TODO

Show details
  • Nginx
  • Production roll up
  • Action Cable Link

Sponsorship

These amazing companies and teams support the project:

JetBrains.com Hoodies.team

License

MIT License. 2023. Ilya N. Zykin

rails7-startkit's People

Contributors

ggalancs avatar kronen10 avatar luilver avatar nicke avatar the-teacher avatar wiiikiii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails7-startkit's Issues

Mailcatcher. Loosing a network

I noticed that time to time mailcatcher container can not be stopped/started correctly due to some issues with an access to a network for the project.

Issues can be solved with restart of the whole project after some time.

I think for now it is low priority issue. Would be great to figure out once.

Is turbo enabled by default?

I don't see
import "@hotwired/turbo-rails"
anywhere in the JavaScript.

Do I need to set up the hotwire myself? Can we enable it by default?

Thank you for the package. I will help out once I get more Rails experience.

ES shim in Production mode

[41b29ecc-c06f-457e-b980-2d83ba9e4727] ActionView::Template::Error (The asset "es-module-shims.min.js" is not present in the asset pipeline.
):

Screenshot 2023-09-03 at 13 02 24

Devise. Confirmation issue

Screenshot 2023-02-03 at 21 58 57

Screenshot 2023-02-03 at 21 59 32

NameError in Devise::RegistrationsController#create
undefined local variable or method `unconfirmed_email'

Docker Compose v2 not found but docker-compose v2 is installed

Cloning into 'rails7-startkit'...
remote: Enumerating objects: 2519, done.
remote: Counting objects: 100% (608/608), done.
remote: Compressing objects: 100% (95/95), done.
remote: Total 2519 (delta 534), reused 514 (delta 513), pack-reused 1911
Receiving objects: 100% (2519/2519), 12.48 MiB | 13.22 MiB/s, done.
Resolving deltas: 100% (1544/1544), done.
Docker version 24.0.7, build afdd53b4e3
=> Docker found
=> Docker is running
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rails 7. StartKit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=> Docker Compose v2 not found
To continue please install or upgrade Docker Compose v2
More info: https://docs.docker.com/compose/compose-v2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~/De/R/rails7-startkit    master  docker-compose -v                                 1 ✘    5  
Docker Compose version 2.23.3

I am using Arch Linux.

docker compose version
Docker Compose version 2.23.3

Even this command works but the match does not contains v2.

Works after change v2 to 2 in Rails7StartKit/bin/docker.rb

unable to deploy successfully

Greetings!

I've been trying to setup a new instance of this today, I have a few other instances that have deployed without a hitch. today I am receiveing this though,

# ./spec/views/landings/show.html.erb_spec.rb:1:in <top (required)>
# ------------------
# --- Caused by: ---
# PG::ConnectionBad:
#   FATAL:  no pg_hba.conf entry for host "172.24.0.6", user "postgres", database "rails7_app_test", no encryption
#   /usr/local/bundle/gems/pg-1.4.5/lib/pg/connection.rb:632:in async_connect_or_reset'
No examples found.

Finished in 0.00006 seconds (files took 1.65 seconds to load)
0 examples, 0 failures, 10 errors occurred outside of examples

Coverage report generated for RSpec to /home/lucky/app/coverage. 8 / 164 LOC (4.88%) covered.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
15. Visit Rails App: http://local....

more specifically:

PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "172.24.0.6", user "postgres", database "rails7_app_development", no encryption```

Cannot connect to the Docker daemon

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rails 7. StartKit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=> Docker not running
To continue please run Docker

========

➜ ruby -v
ruby 3.1.2p20
Not 3.2.2 because this MBA won't let puma launch.. But you didn't specify a Ruby version.

Gemfile does show 3.2.1. Also gem "rails", "7.0.7.2" which probably should be updated.

bin/setup issue

hi, i tried to follow the steps to setup the env, but bin/setup kept giving out this error:

ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux]

Docker version 20.10.12, build 20.10.12-0ubuntu4

error:
/rails7-startkit$ bin/setup
Docker version 20.10.12, build 20.10.12-0ubuntu4

  1. Launching PgSQL container
    unknown shorthand flag: 'f' in -f
    See 'docker --help'.

Usage: docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
--config string Location of client config files (default "/home/cmb/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/cmb/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/cmb/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/cmb/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit

database that was last run in `development`

rspec -f documentation

ActiveRecord::EnvironmentMismatchError: You are attempting to modify a database that was last run in `development` environment.
You are running in `test` environment. If you are sure you want to continue, first set the environment using:

        bin/rails db:environment:set RAILS_ENV=test


Tasks: TOP => db:test:load => db:test:purge => db:check_protected_environments
(See full trace by running task with --trace)

Screenshot 2023-02-10 at 21 58 13

service "rails" is not running container #1

hi, when runing bin/setup, kept getting the following error after step #3

$bin/setup
Docker version 20.10.23, build 7155243

  1. Launching PgSQL container
    [+] Running 1/0
    ⠿ Container rails7app-psql-1 Running 0.0s
    Waiting 3 seconds to initialize PgSQL database
    touch db/PGSQL/.keep
  2. Launching ElasticSearch Container
    [+] Running 1/1
    ⠿ Container rails7app-elastic-1 Started 0.5s
    Waiting 10 seconds to launch ElasticSearch Container
  3. Launching Rails container
    [+] Running 2/2
    ⠿ Container rails7app-psql-1 Running 0.0s
    ⠿ Container rails7app-rails-1 Started 0.6s
    Waiting 3 seconds to launch Rails Container
  4. Installing Gems. Please Wait
    Install Gems
    docker compose -f docker/docker-compose.yml exec rails /bin/bash -c 'bundle install'
    service "rails" is not running container #1

Can we change .env to .env.example?

Otherwise, the .env will get pushed to the production environment and override the environment variables if they are not defined.
Also, we may have accidentally pushed the .env to the repository if it is in Git.

Add Kamal

Could you add the necessary files and gems to use Kamal?

Thank you for the startkit!

Running rails test in bin/open getting this error

lucky@55409a6028c4:~/app$ rails test <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require': cannot load
such file -- test_helper (LoadError)
from internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:38:in require' from /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17: in require'
from /home/lucky/app/test/models/user_test.rb:3:in <main>' from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require'
from internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:38:in require' from /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32: in require'
from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/test_unit/runner.rb:47:in block in load_tests' from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/test_unit/runner.rb:47:in each'
from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/test_unit/runner.rb:47:in load_tests' from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/test_unit/runner.rb:40:in run'
from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/commands/test/test_command.rb:33:in perform' from /usr/local/bundle/gems/thor-1.2.2/lib/thor/command.rb:27:in run'
from /usr/local/bundle/gems/thor-1.2.2/lib/thor/invocation.rb:127:in invoke_command' from /usr/local/bundle/gems/thor-1.2.2/lib/thor.rb:392:in dispatch'
from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/command/base.rb:87:in perform' from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/command.rb:48:in invoke'
from /usr/local/bundle/gems/railties-7.0.7.2/lib/rails/commands.rb:18:in <main>' from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require'
from internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:38:in require' from /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32: in require'
from bin/rails:6:in <main>'

Removing require 'test_helper' in test/models/user_test.rb will fix the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.