From f2221f4739db23b467d29ef5cabbf8a703427bea Mon Sep 17 00:00:00 2001 From: Ben Parees Date: Thu, 30 Oct 2014 22:09:49 -0400 Subject: [PATCH] enable app to be built by sti --- Dockerfile | 4 +- Gemfile | 6 +++ Gemfile.lock | 46 +++++++++++++++++++ Rakefile | 4 ++ sinatra_app/app.rb => app.rb | 15 ++++++ config.ru | 2 + {sinatra_app/config => config}/database.yml | 0 .../config => config}/environments.rb | 9 ---- .../migrate/1414364400_create_timestamp.rb | 0 sinatra_app/models.rb => models.rb | 0 sinatra_app/Rakefile | 2 - sinatra_app/start.rb | 6 --- 12 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile rename sinatra_app/app.rb => app.rb (65%) create mode 100644 config.ru rename {sinatra_app/config => config}/database.yml (100%) rename {sinatra_app/config => config}/environments.rb (74%) rename {sinatra_app/db => db}/migrate/1414364400_create_timestamp.rb (100%) rename sinatra_app/models.rb => models.rb (100%) delete mode 100644 sinatra_app/Rakefile delete mode 100644 sinatra_app/start.rb diff --git a/Dockerfile b/Dockerfile index c4a201ad2a..1539f2c5f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM openshift/ruby-20-centos RUN gem install sinatra sinatra-activerecord mysql2 --no-ri --no-rdoc -ADD sinatra_app /tmp/ +ADD . /tmp/ USER root @@ -13,4 +13,4 @@ USER ruby WORKDIR /tmp/ EXPOSE 8080 -CMD ["ruby", "start.rb"] +CMD ["ruby", "app.rb"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..62495d3c83 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org' + +gem 'sinatra' +gem 'sinatra-activerecord' +gem 'mysql2' +gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..f0450d3482 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,46 @@ +GEM + remote: https://rubygems.org/ + specs: + activemodel (4.1.7) + activesupport (= 4.1.7) + builder (~> 3.1) + activerecord (4.1.7) + activemodel (= 4.1.7) + activesupport (= 4.1.7) + arel (~> 5.0.0) + activesupport (4.1.7) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) + builder (3.2.2) + i18n (0.6.11) + json (1.8.1) + minitest (5.4.2) + mysql2 (0.3.16) + rack (1.5.2) + rack-protection (1.5.3) + rack + rake (10.3.2) + sinatra (1.4.5) + rack (~> 1.4) + rack-protection (~> 1.4) + tilt (~> 1.3, >= 1.3.4) + sinatra-activerecord (2.0.3) + activerecord (>= 3.2) + sinatra (~> 1.0) + thread_safe (0.3.4) + tilt (1.4.1) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + mysql2 + rake + sinatra + sinatra-activerecord diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..d473245ac4 --- /dev/null +++ b/Rakefile @@ -0,0 +1,4 @@ +require_relative 'config/environments' +require_relative 'models' +require 'sinatra/activerecord/rake' + diff --git a/sinatra_app/app.rb b/app.rb similarity index 65% rename from sinatra_app/app.rb rename to app.rb index c9e73c4b06..5daa2af15f 100644 --- a/sinatra_app/app.rb +++ b/app.rb @@ -5,6 +5,21 @@ set :bind, '0.0.0.0' set :port, 8080 +configure do + puts "Running app file" + puts "Create database..." + %x"rake db:create" + puts "Run migrations..." + %x"rake db:migrate" + puts "Run app..." + + while !self.connect_to_database + puts "Connecting to database...\n" + sleep 0.1 + end + puts "Connected to database" +end + get '/' do Timestamp.create(date: Time.now, text: "This is a message from a database query. The last insertion in the database was at") "Hello World!\n"+ diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..76a6edff81 --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require './app' +run Sinatra::Application diff --git a/sinatra_app/config/database.yml b/config/database.yml similarity index 100% rename from sinatra_app/config/database.yml rename to config/database.yml diff --git a/sinatra_app/config/environments.rb b/config/environments.rb similarity index 74% rename from sinatra_app/config/environments.rb rename to config/environments.rb index 477865c908..a474e28916 100644 --- a/sinatra_app/config/environments.rb +++ b/config/environments.rb @@ -16,12 +16,3 @@ def self.connect_to_database return false end end - -configure :development do - - while !self.connect_to_database - puts "Connecting to database...\n" - sleep 0.1 - end - puts "Connected to database" -end diff --git a/sinatra_app/db/migrate/1414364400_create_timestamp.rb b/db/migrate/1414364400_create_timestamp.rb similarity index 100% rename from sinatra_app/db/migrate/1414364400_create_timestamp.rb rename to db/migrate/1414364400_create_timestamp.rb diff --git a/sinatra_app/models.rb b/models.rb similarity index 100% rename from sinatra_app/models.rb rename to models.rb diff --git a/sinatra_app/Rakefile b/sinatra_app/Rakefile deleted file mode 100644 index 1d016631ac..0000000000 --- a/sinatra_app/Rakefile +++ /dev/null @@ -1,2 +0,0 @@ -require_relative 'app' -require 'sinatra/activerecord/rake' diff --git a/sinatra_app/start.rb b/sinatra_app/start.rb deleted file mode 100644 index cc3f8135c6..0000000000 --- a/sinatra_app/start.rb +++ /dev/null @@ -1,6 +0,0 @@ -puts "Create database..." -%x"rake db:create" -puts "Run migrations..." -%x"rake db:migrate" -puts "Run app..." -%x"ruby app.rb &" \ No newline at end of file