-
-
Save otaviomedeiros/fb8eda4962da393f7c994c1afd09785a to your computer and use it in GitHub Desktop.
Ruby on Rails with Sidekiq and docker compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=3000 | |
REDIS_PORT=6379 | |
SIDEKIQ_REDIS_URL=redis://redis:6379/0 | |
APP_DATABASE_HOST=database | |
APP_DATABASE_PORT=5432 | |
APP_DATABASE_NAME=app_development | |
APP_DATABASE_USERNAME=postgres | |
APP_DATABASE_PASSWORD=postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/database.yml | |
default: &default | |
adapter: postgresql | |
encoding: unicode | |
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | |
host: <%= ENV['APP_DATABASE_HOST'] %> | |
database: <%= ENV['APP_DATABASE_NAME'] %> | |
username: <%= ENV['APP_DATABASE_USERNAME'] %> | |
password: <%= ENV['APP_DATABASE_PASSWORD'] %> | |
development: | |
<<: *default | |
test: | |
<<: *default | |
database: app_test | |
production: | |
<<: *default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.3" | |
services: | |
app: | |
build: . | |
env_file: | |
- .env | |
volumes: | |
- ".:/app" | |
ports: | |
- ${PORT}:${PORT} | |
depends_on: | |
- database | |
database: | |
image: postgres:13.2 | |
restart: always | |
environment: | |
POSTGRES_PASSWORD: postgres | |
ports: | |
- ${APP_DATABASE_PORT}:${APP_DATABASE_PORT} | |
volumes: | |
- "pg_volume:/var/lib/postgresql/data" | |
redis: | |
image: redis | |
ports: | |
- ${REDIS_PORT}:${REDIS_PORT} | |
sidekiq: | |
build: . | |
depends_on: | |
- database | |
- redis | |
volumes: | |
- .:/app | |
env_file: | |
- .env | |
command: bundle exec sidekiq | |
volumes: | |
pg_volume: | |
driver: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:2.7.2 | |
RUN curl -sS 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 -qq && apt-get install -y build-essential nodejs yarn | |
RUN mkdir /app | |
WORKDIR /app | |
ADD Gemfile /app/Gemfile | |
ADD Gemfile.lock /app/Gemfile.lock | |
RUN bundle install | |
ADD . /app | |
CMD rm -f tmp/pids/server.pid && bin/rails server -b '0.0.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
ruby '2.7.2' | |
gem 'rails', '~> 6.1.4', '>= 6.1.4.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
require 'sidekiq/web' | |
Rails.application.routes.draw do | |
mount Sidekiq::Web, at: '/sidekiq' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/sidekiq.rb | |
Sidekiq.configure_server do |config| | |
config.redis = { url: ENV['SIDEKIQ_REDIS_URL'] } | |
end | |
Sidekiq.configure_client do |config| | |
config.redis = { url: ENV['SIDEKIQ_REDIS_URL'] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create initial files:
Copy contents of the corresponding files above.
Create new rails app:
Add
gem 'sidekiq'
toGemfile
Copy contents of the corresponding files above.
Build docker images and install webpacker:
Create the database:
Run the app:
The app is running on localhost:3000. The Sidekiq web interface can be accessed at http://localhost:3000/sidekiq