Giter Site home page Giter Site logo

d3diva / rails6-docker-stimulus-reflex Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 155 KB

Docker Docker-composer Sidekiq Redis Stimulus-reflix

Dockerfile 1.28% Ruby 66.23% JavaScript 17.72% CSS 1.34% SCSS 0.33% HTML 12.73% Shell 0.38%
rails6 ruby docker docker-compose sidekiq redis stimulus-js mysql webpacker

rails6-docker-stimulus-reflex's Introduction

README

To run a Stimulus Reflex in Docker with Sidekiq and Redis

  1. Create a Dockerfile
FROM ruby:2.7.3

RUN curl https://deb.nodesource.com/setup_12.x | bash
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update && apt-get install -y nodejs yarn postgresql-client

WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]
  1. Create a Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.3'
  1. Create a Gemfile.lock

touch Gemfile.lock

  1. Create a docker-compose.yml file
version: "3.9"
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    environment:
      RAILS_ENV: "development"
      REDIS_URL: "redis://redis:6379/12"
    ports:
      - "3000:3000"
    depends_on:
      - db
  
  1. Generate the project

docker-compose run web rails new . --force --database=postgresql

  1. Build the containers

docker-compose build

  1. User permission

sudo chown -R $USER:$USER .

  1. Update the database config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password:
  pool: 5

development:
  <<: *default
  database: myapp_development


test:
  <<: *default
  database: myapp_test
  1. Create the database

docker-compose run web rake db:create

  1. Add sidekiq and gem

gem 'sidekiq' gem 'stimulus_reflex'

  1. Update Gemfile.lock

docker-compose run web bundle install

  1. Add redis and sidekiq container
redis:
    image: redis
    volumes:
      - ./tmp/db:/var/lib/redis/data
sidekiq:
  build: .
  command: 'bundle exec sidekiq'
  volumes:
    - .:/myapp
  environment:
    RAILS_ENV: "development"
    REDIS_URL: "redis://redis:6379/12"
  depends_on:
    - redis
  1. Add active job queue config
config.active_job.queue_adapter = :sidekiq
  1. Add sidekiq config
Sidekiq.configure_server do |config|
  config.redis = { url: 'redis://redis.example.com:7372/12' }
end

Sidekiq.configure_client do |config|
  config.redis = { url: 'redis://redis.example.com:7372/12' }
end
  1. Install Stimulus

docker-compose run web rails stimulus_reflex:install

  1. Install Stimulus Reflex

docker-compose run web rails webpacker:install:stimulus

  1. Genrate Page Controller

docker-compose run web rails g controller Pages index

  1. Edit app/views/pages/index.html.erb
<a href="#"
  data-reflex="click->Counter#increment"
  data-step="1" 
  data-count="<%= @count.to_i %>"
> Increment <%= @count.to_i %></a>
  1. Add counter_reflex.rb in app/reflex folder and edit and add
class CounterReflex < ApplicationReflex
  def increment
    @count = element.dataset[:count].to_i + element.dataset[:step].to_i
  end
end

rails6-docker-stimulus-reflex's People

Contributors

d3diva avatar

Watchers

 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.