Coder Social home page Coder Social logo

kannans / rails7_redis_fly_io Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 83 KB

This is ruby on Rails application with deployment configuration at Fly.io

Dockerfile 6.25% Ruby 65.42% JavaScript 5.83% CSS 1.90% HTML 19.35% SCSS 1.24%
redis websocket rails rails-7

rails7_redis_fly_io's Introduction

What is repo?

This is simple Ruby on Rails application with redis integration. It has rails 7+, ruby 3.0, redis, postgresql. It's a example application how to use websocket using redis in rails application. It's running on Fly.io.

What is fly.io?

It's a cloud platform for application deployment. Alternate for Heroku.com

Fly.io is a platform for running full stack apps and databases. It use to deploy rails application pretty fast. Just few commands the application is production ready. This process completely on docker image and using fly.toml configuration, its runs on fly.io clusters

Note: Its free and no payment cards required. *Best comparing to Heroku.

How it was started?

create account in https://fly.io

# create rails application 
rails --version
rails new project_name
cd project_name

# add `pg` and `redis` gems and make necessary changes for websocket changes inside application. 
fly launch
fly deploy
fly open

# create redis instance.
fly redis create
fly secrets set REDIS_URL=redis://default:<redacted>.upstash.io
fly redis connect

# deploy again
fly deploy
fly open

#debug: 

fly ssh console
flyctl secrets unset RAILS_MASTER_KEY
flyctl secrets set RAILS_MASTER_KEY=<value>
fly redis connect
fly logs

How to run this application?

clone this repo git clone [email protected]:kannans/rails7_redis_fly_io.git

bundle install

bin/rails db:create
bin/rails db:migrate
# or 
bin/rails db:setup

redis-server
bin/rails server

Dev url : http://localhost:3000

Why redis?

With Redis, you write fewer lines of code to store, access, and use data in your applications. In rails application it act best for caching and websockets.

Where to acccess production?

https://kannansv.fly.dev/

How to use complete bundle of Bootstrap 5 css framework?

Build fast, responsive sites with Bootstrap Powerful, extensible, and feature-packed frontend toolkit. Build and customize with Sass, utilize prebuilt grid system and components, and bring projects to life with powerful JavaScript plugins.

Add bootstrap gem for css style

gem 'bootstrap', '~> 5.2.2'
gem 'sassc-rails'

We need to import this css style to our application stylesheets. Before that We should rename application.css to application.scss

application.scss file import the bootstrap bundle

....
 *
 *= require_tree .
 *= require_self
 */

@import "bootstrap";  

Now we have to import bootstrap javascripts. Import by using importmap

./bin/importmap pin bootstrap  

this will add following two lines in to importmap.rb

....
pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js"
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/[email protected]/lib/index.js"

simply include this line in to applicaiton.js, It will include all(*) the bootstrap js plugins.

...
import * as bootstrap from 'bootstrap'

It works!!!

Exceptions and fixes

  1. requires node js: Rails app fly deploy failing with ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime find solution here. https://community.fly.io/t/rails-app-fly-deploy-failing-with-execjs-could-not-find-a-javascript-runtime/7904

Actually!!!.. I tweek the code to fix runtime js issue. First include nodejs in DEPLOY_PACKAGES list and update the fly.task file with following code.

task :build #=> 'assets:precompile'
task :server => %i[swapfile assets:precompile]

How to Do Custom Domains With Fly?

flyctl ips list -a <appname> #to get the IPv4 and IPv6 addresses.
flyctl certs create -a <appname> example.com

You can direct traffic to example.com by:

1: Adding an A record to your DNS service which reads

A @ xxx.xxx.xxx.104

You can validate your ownership of kannans.dev by:

2: Adding an AAAA record to your DNS service which reads:

`AAAA @ 2a09:xx:xx::xxxx`

rails7_redis_fly_io's People

Contributors

kannans avatar

Watchers

 avatar  avatar

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.