Skip to content

Commit 5f51a13

Browse files
jneenjneen
andauthored
Setup to deploy on jneen's infra (#44)
* update Dockerfile for jneen server deployment * add x86_64-linux-musl as a platform * remove sprockets and use plain css/js * factor out `make_demo` and log errors * disable static file serving in production * don't log on InvalidVersion * move load-dependent stuff into setup() * update link colours --------- Co-authored-by: jneen <jneen@jneen.net>
1 parent a2493a9 commit 5f51a13

15 files changed

Lines changed: 240 additions & 416 deletions

File tree

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ FROM ruby:4.0-alpine AS base
22

33
LABEL org.opencontainers.image.source=https://github.com/rouge-ruby/dingus
44

5-
RUN apk add --update --no-cache \
6-
nodejs=24.11.1-r0 \
7-
&& rm -rf /var/cache/apk/*
8-
95
ENV BUNDLER_VERSION=2.6.9
106

117
RUN gem update --system \
@@ -15,7 +11,7 @@ RUN gem update --system \
1511
# This stage is responsible for installing gems
1612
FROM base AS dep
1713

18-
RUN apk add --no-cache \
14+
RUN apk add --update --no-cache \
1915
build-base=0.5-r3
2016

2117
WORKDIR /app
@@ -24,18 +20,23 @@ COPY Gemfile Gemfile.lock ./
2420

2521
# Install core dependencies
2622
RUN bundle config --local without development && \
27-
bundle install --jobs=3 --retry=3
23+
bundle install --jobs=3 --retry=3 && \
24+
bundle config --local frozen true
2825

2926
# ---------------------------------
3027
# This stage is what we run the app
3128
FROM base
3229

3330
RUN adduser -D app
3431

35-
USER app
36-
3732
WORKDIR /app
3833

34+
RUN apk add --update --no-cache \
35+
git \
36+
bash
37+
38+
USER app
39+
3940
COPY --from=dep /usr/local/bundle /usr/local/bundle
4041
COPY --chown=app . ./
4142

Gemfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ source 'https://rubygems.org'
66
gem 'puma'
77
gem 'sinatra'
88

9-
# Asset pipeline
10-
gem 'base64'
11-
gem 'sassc-embedded'
12-
gem 'sprockets'
13-
gem 'uglifier'
14-
159
# Standard library gems
1610
gem 'logger'
1711
gem 'ostruct'

Gemfile.lock

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ GEM
77
base64 (0.3.0)
88
bigdecimal (4.0.1)
99
coderay (1.1.3)
10-
concurrent-ruby (1.3.6)
1110
drb (2.2.3)
12-
execjs (2.10.0)
13-
google-protobuf (4.34.0-arm64-darwin)
14-
bigdecimal
15-
rake (~> 13.3)
1611
io-console (0.8.2)
1712
json (2.19.0)
1813
json-schema (6.2.0)
@@ -85,33 +80,23 @@ GEM
8580
rubocop-ast (>= 1.47.1, < 2.0)
8681
ruby-progressbar (1.13.0)
8782
ruby2_keywords (0.0.5)
88-
sass-embedded (1.97.3-arm64-darwin)
89-
google-protobuf (~> 4.31)
90-
sassc-embedded (1.80.8)
91-
sass-embedded (~> 1.80)
9283
sinatra (4.2.1)
9384
logger (>= 1.6.0)
9485
mustermann (~> 3.0)
9586
rack (>= 3.0.0, < 4)
9687
rack-protection (= 4.2.1)
9788
rack-session (>= 2.0.0, < 3)
9889
tilt (~> 2.0)
99-
sprockets (4.2.2)
100-
concurrent-ruby (~> 1.0)
101-
logger
102-
rack (>= 2.2.4, < 4)
10390
tilt (2.7.0)
104-
uglifier (4.2.1)
105-
execjs (>= 0.3.0, < 3)
10691
unicode-display_width (3.2.0)
10792
unicode-emoji (~> 4.1)
10893
unicode-emoji (4.2.0)
10994

11095
PLATFORMS
11196
arm64-darwin-25
97+
x86_64-linux-musl
11298

11399
DEPENDENCIES
114-
base64
115100
bigdecimal
116101
json
117102
logger
@@ -125,10 +110,7 @@ DEPENDENCIES
125110
rubocop
126111
rubocop-minitest
127112
rubocop-performance (~> 1.20)
128-
sassc-embedded
129113
sinatra
130-
sprockets
131-
uglifier
132114

133115
BUNDLED WITH
134116
2.6.9

app.rb

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@ class Dingus < Sinatra::Base
1414
MAX_PATH_SIZE = 1900
1515
MAX_BODY_SIZE = 1400
1616

17-
# initialize new sprockets environment
18-
set :environment, Sprockets::Environment.new
19-
20-
# append assets paths
21-
environment.append_path 'assets/images'
22-
environment.append_path 'assets/stylesheets'
23-
environment.append_path 'assets/javascripts'
24-
25-
# [jneen] no need to compress assets for now, the site is
26-
# extremely simple.
27-
#
28-
# environment.js_compressor = Uglifier.new(harmony: true)
29-
# environment.css_compressor = :scssc
30-
31-
# get assets
32-
get '/assets/*' do
33-
env['PATH_INFO'].sub!('/assets', '')
34-
settings.environment.call(env)
17+
enable :logging
18+
19+
if environment == :development
20+
set :static, true
21+
else
22+
set :static, false
23+
end
24+
25+
def make_demo(*args)
26+
Demo.new(*args)
27+
rescue Demo::InvalidVersion
28+
halt 400
29+
rescue StandardError => e
30+
request.logger.error "#{e.message}:\n#{e.backtrace.join("\n")}"
31+
halt 400
3532
end
3633

3734
before do
@@ -54,13 +51,7 @@ class Dingus < Sinatra::Base
5451
when 'application/json'
5552
payload = JSON.parse request.body.read
5653

57-
demo = begin
58-
Demo.new payload['ver'],
59-
payload['lang'],
60-
payload['source']
61-
rescue StandardError
62-
halt 400
63-
end
54+
demo = make_demo(payload['ver'], payload['lang'], payload['source'])
6455

6556
content_type :json
6657

@@ -84,29 +75,17 @@ class Dingus < Sinatra::Base
8475
end
8576

8677
get '/:ver' do
87-
demo = begin
88-
Demo.new params['ver'], nil, nil
89-
rescue StandardError
90-
halt 400
91-
end
78+
demo = make_demo(params['ver'], nil, nil)
9279

9380
erb :index, locals: { demo: demo, flash: nil }
9481
end
9582

9683
get '/:ver/:lang/:source?' do
97-
if params['source'].nil? || params['source'] == 'draft'
98-
demo = begin
99-
Demo.new params['ver'], params['lang']
100-
rescue StandardError
101-
halt 400
102-
end
84+
demo = if params['source'].nil? || params['source'] == 'draft'
85+
make_demo(params['ver'], params['lang'])
10386
else
10487
source = Base64.urlsafe_decode64(params['source']).force_encoding('utf-8')
105-
demo = begin
106-
Demo.new params['ver'], params['lang'], source
107-
rescue StandardError
108-
halt 400
109-
end
88+
make_demo(params['ver'], params['lang'], source)
11089
end
11190

11291
erb :index, locals: { demo: demo, flash: nil }

assets/javascripts/application.js.erb

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)