commit 995f8b4d9cb62a2888050221212f3ec2a9c405b4 Author: Jonathan Rosenbaum Date: Thu Dec 11 15:48:34 2014 +0000 History is made for the first demo of Bikeshed diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..273e567 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +############ +# BikeShed # +############ +# login for test users on website + +FROM bikebike/bikebike +MAINTAINER Jonathan Rosenbaum + +RUN git clone git://github.com/spacemunkay/BikeShed.git +RUN gem install bundler +RUN apt-get update && apt-get -y install libpq-dev postgresql-9.3 g++ unzip +RUN bundle install --gemfile=/BikeShed/Gemfile; \ + cd /BikeShed; gem install rake -v '10.1.1'; \ + gem install therubyracer -v '0.10.2' +COPY pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf + +# Because of an undefined constant SeedBike +COPY seeds.rb /BikeShed/db/seeds.rb +RUN cp /BikeShed/config/database.yml.example /BikeShed/config/database.yml; \ + service postgresql start; \ + cd /BikeShed; \ + sudo -u postgres -i createuser -d -w velocipede; \ + adduser --disabled-password --gecos "" velocipede; \ + sudo -u velocipede -i createdb -U velocipede --owner=velocipede velocipede; \ + sudo -u velocipede -i createdb -U velocipede --owner=velocipede velocipede_test; \ + + bundle exec rake db:create db:migrate; \ + bundle exec rake db:seed + + +COPY postgresql.conf bikeshed.conf /etc/supervisor/conf.d/ +#COPY bikeshed.conf /etc/supervisor/conf.d/ +COPY extjs-4.1.1.zip /BikeShed/ + +RUN cd /BikeShed; \ + unzip extjs-4.1.1.zip; \ + ln -s /BikeShed/ext-4.1.1a /BikeShed/public/extjs + +CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"] + +# docker run -d -p 3000:3000 --name="freehub" bikebike/freehub + diff --git a/bikeshed.conf b/bikeshed.conf new file mode 100644 index 0000000..102f8ff --- /dev/null +++ b/bikeshed.conf @@ -0,0 +1,5 @@ +[program:bikeshed] +priority=200 +directory=/BikeShed +command=rails s +autorestart=false diff --git a/extjs-4.1.1.zip b/extjs-4.1.1.zip new file mode 100644 index 0000000..9fe5812 Binary files /dev/null and b/extjs-4.1.1.zip differ diff --git a/pg_hba.conf b/pg_hba.conf new file mode 100644 index 0000000..0d65912 --- /dev/null +++ b/pg_hba.conf @@ -0,0 +1,11 @@ +# Database administrative login by Unix domain socket +local all postgres peer + +# TYPE DATABASE USER ADDRESS METHOD + +# "local" is for Unix domain socket connections only +local all all peer +# IPv4 local connections: +host all all 127.0.0.1/32 trust +# IPv6 local connections: +host all all ::1/128 md5 diff --git a/postgresql.conf b/postgresql.conf new file mode 100644 index 0000000..3b15268 --- /dev/null +++ b/postgresql.conf @@ -0,0 +1,7 @@ +[program:postgres] +priority = 100 +user = postgres +command = /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf +autostart = true +autorestart = true +startsecs = 10 diff --git a/seeds.rb b/seeds.rb new file mode 100644 index 0000000..8b94f54 --- /dev/null +++ b/seeds.rb @@ -0,0 +1,59 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) +require 'active_record/fixtures' + +#Load defaults from db/seed/fixtures +Dir.glob(File.join(Rails.root, 'db', 'seed', 'fixtures', '**', '*.{yml,csv}')).each do |fixture_file, something| + ActiveRecord::Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) +end + +#Load bike brands and models from sql +if BikeBrand.all.empty? and BikeModel.all.empty? + # Need to use DEFAULT instead of explicit IDs that are used in the sql file, + # so that the PG table ID sequence is incremented + # + # Note the drop(1) which assumes we have a junk PRAGMA line at the top + load_statements = File.readlines(File.join(Rails.root, 'db', 'seed', 'sql', 'bike_brands_and_models.sql')).drop(1).map do |statement| + statement.sub(/VALUES\(\d+,/, 'VALUES(DEFAULT,') + end + ActiveRecord::Base.connection.execute(load_statements.join) +end + +if Rails.env.development? + + #create default users + if User.all.empty? + u = FactoryGirl.create(:user) + FactoryGirl.create(:user_profile, user_id: u.id) + u = FactoryGirl.create(:staff) + FactoryGirl.create(:user_profile, user_id: u.id) + u = FactoryGirl.create(:bike_admin) + FactoryGirl.create(:user_profile, user_id: u.id) + u = FactoryGirl.create(:admin) + FactoryGirl.create(:user_profile, user_id: u.id) + end + + #create fake bikes + if Bike.all.empty? + 42.times do |n| +# FactoryGirl.create(:seed_bike) + end + end +elsif Rails.env.production? + + unless User.find_by_username('admin') + #create an admin + admin = User.create!( :username => 'admin', + :first_name => 'admin', + :last_name => 'admin', + :email=>'admin@example.com', + :password=>'password') + admin.roles << Role.find_by_role('admin') + end + +end