diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..100bd6d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +./config/application_settings.yml +./config/database.yml +./config/environments/deveropment.rb + +vender/bundle \ No newline at end of file diff --git a/.gitignore b/.gitignore index b8c6cc6..5f34361 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,6 @@ pickle-email-*.html # TODO Comment out these rules if you are OK with secrets being uploaded to the repo config/initializers/secret_token.rb -config/secrets.yml config/setting_google_calendar.yml config/application_settings.yml @@ -53,4 +52,6 @@ bower.json attic/ -config/environments/development.rb \ No newline at end of file +config/environments/development.rb + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..078507e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM ruby:2.1.5 +RUN apt-get update -qq && apt-get install -y build-essential ruby-dev libxslt1-dev libxml2-dev libpq-dev nodejs sqlite3 postgresql-client redis-server + +WORKDIR camome + +COPY Gemfile Gemfile.lock /camome/ +RUN bundle install --path vendor/bundle + +COPY . /camome + +RUN git submodule init +RUN git config submodule.vendor/assets/bootstrap-table.url https://github.com/wenzhixin/bootstrap-table.git +RUN git config submodule.vendor/assets/jsSHA.url https://github.com/Caligatio/jsSHA.git +RUN git submodule update \ No newline at end of file diff --git a/Gemfile b/Gemfile index 62acca0..91c23ce 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ source 'https://rubygems.org' gem 'rails', '4.1.8' # Use sqlite3 as the database for Active Record gem 'sqlite3' +gem 'pg', '~> 0.20.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index 66e34e7..f933590 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,7 +92,7 @@ GEM less-rails (2.6.0) actionpack (>= 3.1) less (~> 2.6.0) - libv8 (3.16.14.7) + libv8 (3.16.14.19) mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.4.3) @@ -123,6 +123,7 @@ GEM oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) + pg (0.21.0) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) @@ -232,6 +233,7 @@ DEPENDENCIES nokogiri omniauth omniauth-google-oauth2 + pg rails (= 4.1.8) redis rspec-rails diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index ce080bf..d900bcf 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -174,7 +174,7 @@ def event_to_json(event) def exist_token? ds = DataStore::RedisStore.new user = current_user - if ds.load(user.auth_name) == nil && user.master_auth_info.token != nil + if ds.load(user.auth_name) == nil redirect_to :action => "input_master_pass" end end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 330a7a8..8e22815 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -35,7 +35,7 @@ def google_oauth2 case state when "invitation" - user = User.where("invitation_token is ?", token).first + user = User.where("invitation_token = token").first if user User.current = user user.provider = auth.provider diff --git a/app/models/redis_store.rb b/app/models/redis_store.rb index c3882a5..eb39ef3 100644 --- a/app/models/redis_store.rb +++ b/app/models/redis_store.rb @@ -1,7 +1,9 @@ +require 'uri' module DataStore class RedisStore < Base def initialize - @redis = Redis.new + uri = URI.parse(ApplicationSettings.redis.url) + @redis = Redis.new(host: uri.host, port: uri.port) end def load(key) diff --git a/config/application_settings_sample.yml b/config/application_settings_sample.yml index b1f3be8..865b89d 100644 --- a/config/application_settings_sample.yml +++ b/config/application_settings_sample.yml @@ -7,6 +7,8 @@ default: &default google: application_id: XXXXXXXXXXXXXXXXX application_secret: XXXXXXXXXXXXXXXXX + redis: + url: redis://XXXXX:6379 development: <<: *default diff --git a/config/database.yml b/config/database.yml index 1c1a37c..846498d 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,25 +1,15 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# default: &default - adapter: sqlite3 + adapter: postgresql + encoding: unicode pool: 5 - timeout: 5000 -development: +development: &development <<: *default - database: db/development.sqlite3 + database: camome_development + username: postgres + password: + host: db -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: <<: *default - database: db/test.sqlite3 - -production: - <<: *default - database: db/production.sqlite3 + database: camome_test \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..fd92913 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,6 @@ +development: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> +test: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1c72f22 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3' +services: + db: + container_name: db + image: postgres + expose: + - "5432" + volumes: + - ./db/camome_pgdata:/var/lib/postgresql/data + + web: + build: . + container_name: camome + image: nomlab/camome + command: bundle exec rails s -p 3000 -b 0.0.0.0 + ports: + - "3000:3000" + depends_on: + - redis + - db + volumes: + - ./config/application_settings.yml:/camome/config/application_settings.yml + - ./config/database.yml:/camome/config/database.yml + - ./config/environments/deveropment.rb:/camome/config/environments/deveropment.rb + env_file: .env + + redis: + container_name: redis + image: redis + + goohub: + container_name: goohub + image: nomlab/goohub + links: + - redis + - web + volumes: + - ./goohub:/root/.config/goohub \ No newline at end of file diff --git a/redis/appendonly.aof b/redis/appendonly.aof new file mode 100644 index 0000000..e69de29