Skip to content

Commit c517fbf

Browse files
committed
Add the demo_web_app source code and Dockerfile
[refs #cd23f1c7be00]
1 parent 5c0677f commit c517fbf

19 files changed

+535
-0
lines changed

demo_web_app/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ruby:2.4.2
2+
3+
RUN apt-get update && apt-get install -y postgresql-client
4+
5+
WORKDIR /tmp
6+
COPY Gemfile* ./
7+
RUN bundle install
8+
9+
WORKDIR /app
10+
COPY . .
11+
12+
ENV POSTGRES_HOST=localhost POSTGRES_DB=web_app POSTGRES_USER=web_app POSTGRES_PASSWORD=
13+
ARG WAIT_FOR_POSTGRES=false
14+
ENV WAIT_FOR_POSTGRES=$WAIT_FOR_POSTGRES
15+
EXPOSE 9292
16+
17+
CMD ["./start.sh"]

demo_web_app/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'activerecord'
4+
gem 'pg'
5+
gem 'rake'
6+
gem 'sinatra'
7+
gem 'sinatra-activerecord', '~> 2.0'

demo_web_app/Gemfile.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activemodel (5.1.4)
5+
activesupport (= 5.1.4)
6+
activerecord (5.1.4)
7+
activemodel (= 5.1.4)
8+
activesupport (= 5.1.4)
9+
arel (~> 8.0)
10+
activesupport (5.1.4)
11+
concurrent-ruby (~> 1.0, >= 1.0.2)
12+
i18n (~> 0.7)
13+
minitest (~> 5.1)
14+
tzinfo (~> 1.1)
15+
arel (8.0.0)
16+
concurrent-ruby (1.0.5)
17+
i18n (0.9.1)
18+
concurrent-ruby (~> 1.0)
19+
minitest (5.10.3)
20+
mustermann (1.0.1)
21+
pg (0.21.0)
22+
rack (2.0.3)
23+
rack-protection (2.0.0)
24+
rack
25+
rake (12.3.0)
26+
sinatra (2.0.0)
27+
mustermann (~> 1.0)
28+
rack (~> 2.0)
29+
rack-protection (= 2.0.0)
30+
tilt (~> 2.0)
31+
sinatra-activerecord (2.0.13)
32+
activerecord (>= 3.2)
33+
sinatra (>= 1.0)
34+
thread_safe (0.3.6)
35+
tilt (2.0.8)
36+
tzinfo (1.2.4)
37+
thread_safe (~> 0.1)
38+
39+
PLATFORMS
40+
ruby
41+
42+
DEPENDENCIES
43+
activerecord
44+
pg
45+
rake
46+
sinatra
47+
sinatra-activerecord (~> 2.0)
48+
49+
BUNDLED WITH
50+
1.15.4

demo_web_app/Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'sinatra/activerecord'
2+
require 'sinatra/activerecord/rake'
3+
require './app'

demo_web_app/app.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'sinatra'
2+
require 'sinatra/activerecord'
3+
require 'sinatra/activerecord/rake'
4+
require 'erb'
5+
require './models/request'
6+
7+
set :database, {
8+
adapter: 'postgresql',
9+
encoding: 'unicode',
10+
pool: 2,
11+
host: ENV['POSTGRES_HOST'],
12+
database: ENV['POSTGRES_DB'],
13+
username: ENV['POSTGRES_USER'],
14+
password: ENV['POSTGRES_PASSWORD'],
15+
}
16+
set :raise_errors, true
17+
18+
class App < Sinatra::Base
19+
get '/' do
20+
Request.create!(ip: request.ip, host: Socket.gethostname, path: request.path, timestamp: Time.now)
21+
erb :index, locals: { requests: Request.all.order(timestamp: :desc).limit(25) }
22+
end
23+
end

demo_web_app/config.ru

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rubygems'
2+
require 'bundler'
3+
4+
Bundler.require
5+
6+
require './app'
7+
run App
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateRequests < ActiveRecord::Migration[5.1]
2+
def change
3+
create_table :requests do |t|
4+
t.timestamp :timestamp
5+
t.string :ip
6+
t.string :host
7+
t.string :path
8+
end
9+
end
10+
end

demo_web_app/db/schema.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# Note that this schema.rb definition is the authoritative source for your
6+
# database schema. If you need to create the application database on another
7+
# system, you should be using db:schema:load, not running all the migrations
8+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9+
# you'll amass, the slower it'll run and the greater likelihood for issues).
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(version: 20171128082428) do
14+
15+
# These are extensions that must be enabled in order to support this database
16+
enable_extension "plpgsql"
17+
18+
create_table "requests", force: :cascade do |t|
19+
t.datetime "timestamp"
20+
t.string "ip"
21+
t.string "host"
22+
t.string "path"
23+
end
24+
25+
end

demo_web_app/docker-compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
image: jfahrer/demo_web_app:latest
6+
build:
7+
context: .
8+
volumes:
9+
- ./:/app
10+
environment:
11+
POSTGRES_HOST: pg
12+
POSTGRES_DB: web_app_db
13+
POSTGRES_USER: web_app
14+
POSTGRES_PASSWORD: secret
15+
ports:
16+
- 9292:9292
17+
18+
wait_for:
19+
image: jfahrer/demo_web_app:wait_for_pg
20+
build:
21+
context: .
22+
args:
23+
- WAIT_FOR_POSTGRES=true
24+
environment:
25+
POSTGRES_HOST: pg
26+
POSTGRES_DB: web_app_db
27+
POSTGRES_USER: web_app
28+
POSTGRES_PASSWORD: secret
29+
30+
pg:
31+
image: postgres:9.6.6-alpine
32+
environment:
33+
POSTGRES_DB: web_app_db
34+
POSTGRES_USER: web_app
35+
POSTGRES_PASSWORD: secret

demo_web_app/models/request.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Request < ActiveRecord::Base
2+
3+
end

0 commit comments

Comments
 (0)