Skip to content

Commit 9b6631c

Browse files
committed
[sinatra] Mark as production
Sinatra uses standard framework configuration. Use Rack::Deflater middleware for compression. Turn on deployment flag for bundler, this also requires the Gemfile.lock.
1 parent 7ad4005 commit 9b6631c

5 files changed

Lines changed: 65 additions & 17 deletions

File tree

frameworks/sinatra/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ ENV MAX_THREADS=4
1515

1616
WORKDIR /app
1717

18-
COPY Gemfile .
18+
COPY Gemfile* .
19+
RUN bundle config set deployment 'true'
1920
RUN bundle install --jobs=$(nproc)
2021

2122
COPY . .

frameworks/sinatra/Gemfile.lock

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
base64 (0.3.0)
5+
concurrent-ruby (1.3.6)
6+
connection_pool (3.0.2)
7+
json (2.19.4)
8+
logger (1.7.0)
9+
mustermann (3.1.1)
10+
nio4r (2.7.5)
11+
pg (1.6.3-arm64-darwin)
12+
puma (7.2.0)
13+
nio4r (~> 2.0)
14+
rack (3.2.6)
15+
rack-protection (4.2.1)
16+
base64 (>= 0.1.0)
17+
logger (>= 1.6.0)
18+
rack (>= 3.0.0, < 4)
19+
rack-session (2.1.2)
20+
base64 (>= 0.1.0)
21+
rack (>= 3.0.0)
22+
sinatra (4.2.1)
23+
logger (>= 1.6.0)
24+
mustermann (~> 3.0)
25+
rack (>= 3.0.0, < 4)
26+
rack-protection (= 4.2.1)
27+
rack-session (>= 2.0.0, < 3)
28+
tilt (~> 2.0)
29+
tilt (2.7.0)
30+
31+
PLATFORMS
32+
arm64-darwin
33+
34+
DEPENDENCIES
35+
concurrent-ruby
36+
connection_pool
37+
json
38+
pg (~> 1.5)
39+
puma (~> 7.2)
40+
sinatra (~> 4.1)
41+
42+
CHECKSUMS
43+
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
44+
concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
45+
connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a
46+
json (2.19.4) sha256=670a7d333fb3b18ca5b29cb255eb7bef099e40d88c02c80bd42a3f30fe5239ac
47+
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
48+
mustermann (3.1.1) sha256=4c6170c7234d5499c345562ba7c7dfe73e1754286dcc1abb053064d66a127198
49+
nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1
50+
pg (1.6.3-arm64-darwin) sha256=7240330b572e6355d7c75a7de535edb5dfcbd6295d9c7777df4d9dddfb8c0e5f
51+
puma (7.2.0) sha256=bf8ef4ab514a4e6d4554cb4326b2004eba5036ae05cf765cfe51aba9706a72a8
52+
rack (3.2.6) sha256=5ed78e1f73b2e25679bec7d45ee2d4483cc4146eb1be0264fc4d94cb5ef212c2
53+
rack-protection (4.2.1) sha256=cf6e2842df8c55f5e4d1a4be015e603e19e9bc3a7178bae58949ccbb58558bac
54+
rack-session (2.1.2) sha256=595434f8c0c3473ae7d7ac56ecda6cc6dfd9d37c0b2b5255330aa1576967ffe8
55+
sinatra (4.2.1) sha256=b7aeb9b11d046b552972ade834f1f9be98b185fa8444480688e3627625377080
56+
tilt (2.7.0) sha256=0d5b9ba69f6a36490c64b0eee9f6e9aad517e20dcc848800a06eb116f08c6ab3
57+
58+
BUNDLED WITH
59+
4.0.6

frameworks/sinatra/app.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'bundler/setup'
44
Bundler.require(:default)
55

6-
require 'zlib'
76
require 'pg'
87

98
class Hash
@@ -90,19 +89,7 @@ class App < Sinatra::Base
9089
d.merge(total: (d[:price] * d[:quantity] * m))
9190
end
9291

93-
result = JSON.generate(items: items, count: items.length)
94-
95-
if accept_encodings = request.get_header('HTTP_ACCEPT_ENCODING')
96-
if accept_encodings.include?('gzip')
97-
sio = StringIO.new
98-
gz = Zlib::GzipWriter.new(sio, 1)
99-
gz.write(result)
100-
gz.close
101-
headers 'Content-Encoding' => 'gzip'
102-
result = sio.string
103-
end
104-
end
105-
render_json result
92+
render_json JSON.generate(items: items, count: items.length)
10693
end
10794

10895
post '/upload' do

frameworks/sinatra/config.ru

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ class MethodGuard
1818
end
1919

2020
use MethodGuard
21+
use Rack::Deflater
2122
run App

frameworks/sinatra/meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"display_name": "sinatra",
33
"language": "Ruby",
4-
"type": "tuned",
4+
"type": "production",
55
"engine": "puma",
66
"description": "Sinatra DSL web framework on Puma, multi-threaded with one worker per CPU core.",
77
"repo": "https://github.com/sinatra/sinatra",
@@ -19,4 +19,4 @@
1919
"static"
2020
],
2121
"maintainers": []
22-
}
22+
}

0 commit comments

Comments
 (0)