Skip to content

Commit

Permalink
Implement the third assignment in ruby
Browse files Browse the repository at this point in the history
[refs #f34238344b71]
  • Loading branch information
jfahrer committed May 5, 2018
1 parent 732d0f9 commit f23c7ac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
3 changes: 2 additions & 1 deletion developing/examples/webapp/ruby/Dockerfile
Expand Up @@ -2,7 +2,8 @@ FROM ruby:2.4.3-alpine

WORKDIR /app

RUN gem install sinatra
RUN apk update && apk add build-base postgresql-dev

This comment has been minimized.

Copy link
@nudnic

nudnic Aug 25, 2019

you can clean the apk cache :-)

RUN gem install sinatra pg

COPY app.rb .

Expand Down
15 changes: 7 additions & 8 deletions developing/examples/webapp/ruby/app.rb
@@ -1,15 +1,14 @@
require 'sinatra'
require 'pg'

set :bind, '0.0.0.0'
set :port, 9494

get '/' do
File.open('/tmp/requests.txt', 'a') do |file|
file.puts "IP: #{request.ip}"
file.puts "Hostname: #{Socket.gethostname}"
file.puts "Path: #{request.path}"
file.puts "Timestamp: #{Time.now}"
file.puts '------------'
end
'Hello World!'
conn = PG::Connection.open(ENV['POSTGRES_HOST'], 5432, '', '', ENV['POSTGRES_DB'],
ENV['POSTGRES_USER'], ENV['POSTGRES_PASSWORD'])
sql = "INSERT INTO requests (ip, path, host, requested_at) VALUES ($1, $2, $3, $4)"
res = conn.exec(sql, [request.ip, '/', Socket.gethostname, Time.now])
conn.finish
'Hello, World!'
end
24 changes: 23 additions & 1 deletion developing/examples/webapp/ruby/docker-compose.yml
Expand Up @@ -2,10 +2,32 @@ version: '3.3'

services:
app:
image: jfahrer/webapp-ruby:v2
image: jfahrer/webapp-ruby:v3
build:
context: .
environment:
- POSTGRES_USER=demo
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=demo
- POSTGRES_HOST=pg
volumes:
- .:/app
ports:
- 9494:9494

pg:
image: postgres:9.6-alpine
environment:
- POSTGRES_USER=demo
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=demo
volumes:
- ./sql/create_table.sql:/docker-entrypoint-initdb.d/create_table.sql

client:
image: jfahrer/checker-u-dev-a3:latest
environment:
- POSTGRES_USER=demo
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=demo
- POSTGRES_HOST=pg
7 changes: 7 additions & 0 deletions developing/examples/webapp/ruby/sql/create_table.sql
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS requests (
id serial primary key,
requested_at character varying,
ip character varying,
host character varying,
path character varying
);

0 comments on commit f23c7ac

Please sign in to comment.