Skip to content

Commit 1a37f48

Browse files
Dedicated Docker Compose service for the remote interpreter
Things to point out: - No need for .ruby-version (it's specified on Gemfile instead) - Some adjustment on puma.rb and notes (TODOs) on other files - Dedicated environment file for development Interesting links: - docker/compose#1393 - https://www.alanvardy.com/post/puma-server-not-loading - https://webpack.js.org/guides/environment-variables/
1 parent a7e4ea0 commit 1a37f48

9 files changed

+84
-74
lines changed

.dockerignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Block everything
3+
*
4+
# Allowed files and directories
5+
!app
6+
!bin
7+
!config
8+
!db
9+
!lib
10+
!config.ru
11+
!Gemfile
12+
!Gemfile.lock
13+
!tmp/.keep
14+
!tmp/pids/.keep

.env.development

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
##################
2+
#### HTTP
3+
PORT=3000
4+
5+
##################
6+
#### Rails
7+
RAILS_ENV=development
8+
9+
##################
10+
#### Web Server
11+
RAILS_MIN_THREADS=4
12+
RAILS_MAX_THREADS=20
13+
WEB_CONCURRENCY=0
14+
PIDFILE=tmp/pids/server.pid
15+
16+
##################
17+
#### Ruby
18+
# https://bugs.ruby-lang.org/issues/14850
19+
TZ=UTC

.gitignore

+7-59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
# Created by https://www.toptal.com/developers/gitignore/api/rails,ruby,jetbrains+all
3-
# Edit at https://www.toptal.com/developers/gitignore?templates=rails,ruby,jetbrains+all
2+
# Created by https://www.toptal.com/developers/gitignore/api/rails,jetbrains+all
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=rails,jetbrains+all
44

55
### JetBrains+all ###
66
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
@@ -108,8 +108,11 @@ pickle-email-*.html
108108
# Ignore all logfiles and tempfiles.
109109
/log/*
110110
/tmp/*
111+
/tmp/pids/*
111112
!/log/.keep
112113
!/tmp/.keep
114+
!/tmp/pids
115+
!/tmp/pids/.keep
113116

114117
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
115118
config/initializers/secret_token.rb
@@ -120,8 +123,8 @@ config/master.key
120123

121124
# dotenv, dotenv-rails
122125
# TODO Comment out these rules if environment variables can be committed
126+
#.env.*
123127
.env
124-
.env.*
125128

126129
## Environment normalization:
127130
/.bundle
@@ -161,62 +164,7 @@ yarn-debug.log*
161164
/storage/*
162165
!/storage/.keep
163166

164-
### Ruby ###
165-
*.gem
166-
/.config
167-
/InstalledFiles
168-
/pkg/
169-
/spec/reports/
170-
/spec/examples.txt
171-
/test/tmp/
172-
/test/version_tmp/
173-
/tmp/
174-
175-
# Used by dotenv library to load environment variables.
176-
# .env
177-
178-
# Ignore Byebug command history file.
179-
180-
## Specific to RubyMotion:
181-
.dat*
182-
.repl_history
183-
build/
184-
*.bridgesupport
185-
build-iPhoneOS/
186-
build-iPhoneSimulator/
187-
188-
## Specific to RubyMotion (use of CocoaPods):
189-
#
190-
# We recommend against adding the Pods directory to your .gitignore. However
191-
# you should judge for yourself, the pros and cons are mentioned at:
192-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
193-
# vendor/Pods/
194-
195-
## Documentation cache and generated files:
196-
/.yardoc/
197-
/_yardoc/
198-
/doc/
199-
/rdoc/
200-
201-
/.bundle/
202-
/lib/bundler/man/
203-
204-
# for a library or gem, you might want to ignore these files since the code is
205-
# intended to run in multiple environments; otherwise, check them in:
206-
# Gemfile.lock
207-
# .ruby-version
208-
# .ruby-gemset
209-
210-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
211-
212-
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
213-
# .rubocop-https?--*
214-
215-
### Ruby Patch ###
216-
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
217-
# .rubocop-https?--*
218-
219-
# End of https://www.toptal.com/developers/gitignore/api/rails,ruby,jetbrains+all
167+
# End of https://www.toptal.com/developers/gitignore/api/rails,jetbrains+all
220168

221169
# Ignore master key for decrypting credentials and more.
222170
/config/master.key

DockerfileForDev

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM timbru31/ruby-node:2.7
2+
3+
RUN groupadd --system app-user && adduser --system --ingroup app-user app-user
4+
5+
WORKDIR /app
6+
7+
RUN chown app-user:app-user /app
8+
9+
COPY Gemfile Gemfile.lock ./
10+
11+
RUN bundle install
12+
13+
USER app-user
14+
15+
COPY --chown=app-user:app-user . ./
16+
17+
# https://puma.io/puma/
18+
# Without arguments, puma will look for a rackup (.ru) file in the current working directory called config.ru
19+
CMD bundle exec puma

config/environments/production.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
Rails.application.configure do
24
# Settings specified here will take precedence over those in config/application.rb.
35

@@ -11,7 +13,7 @@
1113
config.eager_load = true
1214

1315
# Full error reports are disabled and caching is turned on.
14-
config.consider_all_requests_local = false
16+
config.consider_all_requests_local = false
1517

1618
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
1719
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
@@ -38,10 +40,11 @@
3840

3941
# Use the lowest log level to ensure availability of diagnostic information
4042
# when problems arise.
43+
# TODO: Use ENV for this setup
4144
config.log_level = :debug
4245

4346
# Prepend all log lines with the following tags.
44-
config.log_tags = [ :request_id ]
47+
config.log_tags = [:request_id]
4548

4649
# Use a different cache store in production.
4750
# config.cache_store = :mem_cache_store
@@ -64,7 +67,7 @@
6467
# require 'syslog/logger'
6568
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
6669

67-
if ENV["RAILS_LOG_TO_STDOUT"].present?
70+
if ENV['RAILS_LOG_TO_STDOUT'].present?
6871
logger = ActiveSupport::Logger.new(STDOUT)
6972
logger.formatter = config.log_formatter
7073
config.logger = ActiveSupport::TaggedLogging.new(logger)

config/puma.rb

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1+
# frozen_string_literal: true
2+
13
# Puma can serve each request in a thread from an internal thread pool.
24
# The `threads` method setting takes two numbers: a minimum and maximum.
35
# Any libraries that use thread pools should be configured to match
46
# the maximum value specified for Puma. Default is set to 5 threads for minimum
57
# and maximum; this matches the default thread size of Active Record.
6-
#
7-
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8-
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
8+
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
9+
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
910
threads min_threads_count, max_threads_count
1011

1112
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
12-
#
13-
port ENV.fetch("PORT") { 3000 }
13+
port ENV.fetch('PORT') { 3000 }
1414

1515
# Specifies the `environment` that Puma will run in.
16-
#
17-
environment ENV.fetch("RAILS_ENV") { "development" }
16+
environment ENV.fetch('RAILS_ENV') { 'development' }
1817

1918
# Specifies the `pidfile` that Puma will use.
20-
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
19+
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
2120

2221
# Specifies the number of `workers` to boot in clustered mode.
2322
# Workers are forked web server processes. If using threads and workers together
2423
# the concurrency of the application would be max `threads` * `workers`.
2524
# Workers do not work on JRuby or Windows (both of which do not support
2625
# processes).
27-
#
28-
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
26+
number_of_workers = ENV.fetch('WEB_CONCURRENCY') { 0 }
27+
workers number_of_workers
2928

3029
# Use the `preload_app!` method when specifying a `workers` number.
3130
# This directive tells Puma to first boot the application and load code
3231
# before forking the application. This takes advantage of Copy On Write
3332
# process behavior so workers use less memory.
34-
#
35-
# preload_app!
33+
preload_app! if number_of_workers.positive?
3634

3735
# Allow puma to be restarted by `rails restart` command.
3836
plugin :tmp_restart

docker-compose.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
version: "2.4"
22
services:
3+
remote-interpreter:
4+
build:
5+
context: .
6+
dockerfile: DockerfileForDev
7+
env_file: .env.development
8+
ports:
9+
- "8000:3000"
10+
volumes:
11+
- .:/app
312
word-suggestion:
413
image: willianantunes/runner-said-no-one-ever
514
environment:

tmp/.keep

Whitespace-only changes.

tmp/pids/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)