File tree 10 files changed +78
-37
lines changed
10 files changed +78
-37
lines changed Original file line number Diff line number Diff line change
1
+ * schema.rb
Original file line number Diff line number Diff line change 1
1
FROM openshift/ruby-20-centos
2
2
3
- # Install mysql client and gems to connect app to database.
4
- USER root
5
- RUN yum install -y mysql && gem install sinatra activerecord mysql2 --no-ri --no-rdoc
3
+ RUN gem install sinatra sinatra-activerecord mysql2 --no-ri --no-rdoc
6
4
7
- USER ruby
8
- ADD app.rb /tmp/app.rb
5
+ ADD sinatra_app /tmp/
6
+ WORKDIR /tmp/
9
7
10
8
EXPOSE 8080
11
- CMD ["ruby" , "/tmp/app .rb" ]
9
+ CMD ["ruby" , "start .rb" ]
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ require_relative 'app'
2
+ require 'sinatra/activerecord/rake'
Original file line number Diff line number Diff line change
1
+ require 'sinatra'
2
+ require_relative 'config/environments'
3
+ require_relative 'models'
4
+
5
+ set :bind , '0.0.0.0'
6
+ set :port , ENV [ "FRONTEND_SERVICE_PORT" ]
7
+
8
+ get '/' do
9
+ Timestamp . create ( date : Time . now , text : "This is a message from a database query. The last insertion in the database was at" )
10
+ "Hello World!\n " +
11
+ # ENV values are generated during template processing
12
+ # and then passed to the container when openshift launches it.
13
+ "All the environment variables are: #{ ENV . map { |k , v | "#{ k } =#{ v } " } . join ( "\n " ) } ]\n " +
14
+ "#{ Timestamp . last ( ) . text } #{ Timestamp . last ( ) . date } ."
15
+ end
Original file line number Diff line number Diff line change
1
+ development :
2
+ adapter : mysql2
3
+ database : <%= ENV["MYSQL_DATABASE"] %>
4
+ username : root
5
+ password : <%= ENV['MYSQL_ROOT_PASSWORD'] %>
6
+ host : <%= ENV["DATABASE_SERVICE_IP_ADDR"] %>
7
+ port : <%= ENV["DATABASE_SERVICE_PORT"] %>
Original file line number Diff line number Diff line change
1
+ require 'sinatra/activerecord'
2
+
3
+ def self . connect_to_database
4
+ begin
5
+ ActiveRecord ::Base . establish_connection (
6
+ :adapter => "mysql2" ,
7
+ :host => "#{ ENV [ "DATABASE_SERVICE_IP_ADDR" ] } " ,
8
+ :port => "#{ ENV [ "DATABASE_SERVICE_PORT" ] } " ,
9
+ :database => "#{ ENV [ "MYSQL_DATABASE" ] } " ,
10
+ :password => "#{ ENV [ "MYSQL_ROOT_PASSWORD" ] } "
11
+ )
12
+
13
+ ActiveRecord ::Base . connection . active?
14
+
15
+ rescue Exception
16
+ return false
17
+ end
18
+ end
19
+
20
+ configure :development do
21
+
22
+ while !self . connect_to_database
23
+ puts "Connecting to database...\n "
24
+ sleep 0.1
25
+ end
26
+ puts "Connected to database"
27
+ end
Original file line number Diff line number Diff line change
1
+ class CreateTimestamp < ActiveRecord ::Migration
2
+ def up
3
+ create_table :timestamps do |t |
4
+ t . date :date
5
+ t . text :text
6
+ end
7
+ end
8
+
9
+ def down
10
+ drop_table :timestamps
11
+ end
12
+ end
Original file line number Diff line number Diff line change
1
+ require 'active_record'
2
+
3
+ class Timestamp < ActiveRecord ::Base
4
+ end
Original file line number Diff line number Diff line change
1
+ puts "Create database..."
2
+ %x"rake db:create"
3
+ puts "Run migrations..."
4
+ %x"rake db:migrate"
5
+ puts "Run app..."
6
+ %x"ruby app.rb &>/dev/null &"
You can’t perform that action at this time.
0 commit comments