diff --git a/.dockerignore b/.dockerignore index b7dded27..cc86e3f0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,7 @@ !Gemfile.lock !package.json !package-lock.json -!script/debian_setup.sh \ No newline at end of file +!script/build/debian/*.sh +!Rakefile +!config/* +!db/* \ No newline at end of file diff --git a/.env.test b/.env.test new file mode 100644 index 00000000..99aee497 --- /dev/null +++ b/.env.test @@ -0,0 +1,32 @@ +export DEVISE_SECRET_KEY='0696452e54b14758b8534437d8cf418ea920ff23bb9c3a061a9ab2827bab4685710e89b899ebd4457df600cb5f2e04adb6a0fdef09a6a45558ecae1d6906f4a6' #bundle exec rake secret +export SECRET_TOKEN='0696452e54b14758b8534437d8cf418ea920ff23bb9c3a061a9ab2827bab4685710e89b899ebd4457df600cb5f2e04adb6a0fdef09a6a45558ecae1d6906f4a6' #bundle exec rake secret + +export STRIPE_API_KEY='REPLACE' # use your test private key from your stripe account +export STRIPE_API_PUBLIC='REPLACE' # use your test public key from your stripe account +export S3_BUCKET_NAME='REPLACE' +export AWS_ACCESS_KEY='REPLACE' +export AWS_SECRET_ACCESS_KEY='REPLACE' + +### optional below +export ORG_NAME="default_organization" + +export GOOGLE_API_KEY='REPLACE' +export TWITTER_API_SECRET='REPLACE' +export FACEBOOK_API_SECRET='REPLACE' + +export MAILCHIMP_API_KEY='REPLACE' +export FULL_CONTACT_KEY='REPLACE' + +export LOG_TO_FILES=true + +export MAILCHIMP_OAUTH_CLIENT_ID='REPLACE' +export MAILCHIMP_OAUTH_CLIENT_SECRET='REPLACE' +export MAILCHIMP_REDIRECT_URL='REPLACE' +export FACEBOOK_APP_ID="REPLACE" + + +export CYPHER_KEY="REPLACE" # used for mailchimp integration + + + +export CIVIC_CRM_RABBITMQ_PASSWORD="" diff --git a/.ruby-version b/.ruby-version index e75da3e6..00355e29 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.6 +2.3.7 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..0545e24a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +sudo: required + +language: minimal + +services: +- docker + +before_install: +- docker-compose -f docker/build/docker-compose.yml build +- cp .env.test .env + +script: +- docker-compose -f docker/build/docker-compose.yml run -e RACK_ENV=ci -e RAILS_ENV=ci -e BUILD_DATABASE_URL=postgres://admin:password@db/commitchange_development build script/test.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 30baac89..00000000 --- a/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM ruby:2.3 -ARG USER -RUN mkdir /myapp -COPY Gemfile /myapp/Gemfile -COPY Gemfile.lock /myapp/Gemfile.lock -COPY package.json /myapp/package.json -COPY package-lock.json /myapp/package-lock.json -COPY script/debian_setup.sh /myapp/script/debian_setup.sh -WORKDIR /myapp -RUN script/debian_setup.sh -RUN groupadd -r -g 1000 $USER -RUN useradd -r -m -g $USER -u 1000 $USER -RUN chown -R $USER /usr/local/bundle -RUN chgrp -R $USER /usr/local/bundle -RUN chown -R $USER /myapp -RUN chgrp -R $USER /myapp -RUN chown -R $USER /usr/lib/node_modules -RUN chgrp -R $USER /usr/lib/node_modules -USER $USER -RUN bundle install -EXPOSE 5000 -CMD foreman start diff --git a/Gemfile b/Gemfile index ed134f19..88eda6c5 100755 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '~> 2.3.6' +ruby '2.3.7' gem 'rake' gem 'rails', '3.2.22.5' gem 'rails_12factor' @@ -109,13 +109,13 @@ gem 'i18n-js' gem 'countries' -group :development do +group :development, :ci do gem 'traceroute' gem 'debase' gem 'ruby-debug-ide' end -group :development, :test do +group :development, :ci, :test do gem 'timecop' gem 'pry' #gem 'pry-byebug' diff --git a/Gemfile.lock b/Gemfile.lock index 5e10d876..cde0958f 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -526,7 +526,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 2.3.6p384 + ruby 2.3.7p456 BUNDLED WITH - 1.16.1 + 1.16.4 diff --git a/README.md b/README.md index 1f87a915..cda0bf49 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ You will likely need to logout and log back in again. #### Build your docker-container and start it up for initial set up. We'll keep this running in the console we'll call **console 1** ``` +cd docker/debug docker-compose build docker-compose up ``` diff --git a/config/application.rb b/config/application.rb index d34386dc..32ee9cec 100755 --- a/config/application.rb +++ b/config/application.rb @@ -5,7 +5,7 @@ require 'rails/all' Bundler.require *Rails.groups(:assets) if defined?(Bundler) -require File.expand_path('lib/htp') # Hamster Table Print +#require File.expand_path('lib/htp') # Hamster Table Print module Commitchange class Application < Rails::Application diff --git a/config/database.yml b/config/database.yml index 476a7a84..50c799fe 100755 --- a/config/database.yml +++ b/config/database.yml @@ -30,6 +30,16 @@ test: username: admin password: password host: <%= ENV['DATABASE_HOST'] || 'localhost' %> +ci: + adapter: postgresql + encoding: unicode + database: commitchange_development + pool: 5 + username: admin + password: password + host: <%= ENV['DATABASE_HOST'] || 'localhost' %> + + # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have diff --git a/config/environment.rb b/config/environment.rb index e7e9d5f1..8b283da0 100755 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,16 +5,20 @@ require File.expand_path('../application', __FILE__) Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 @ignore_dotenv = ENV['IGNORE_DOTENV'] +@env = Rails.env || 'development' unless (@ignore_dotenv) require 'dotenv' - Dotenv.load ".env" + if @env == 'test' + if File.file?(".env.#{@env}") + Dotenv.load ".env.#{@env}" + end + else + Dotenv.load ".env" + end end -@env = Rails.env || 'development' + @org_name = ENV['ORG_NAME'] || 'default_organization' puts "config files .env .env.#{@env} ./config/settings.#{@env}.yml#{ @env != 'test' ? " ./config/#{@org_name}.yml": " "} #{ @env != 'test' ? " ./config/#{@org_name}.#{@env}.yml": " "} #{ @env == 'test' ? "./config/settings.test.yml" : ""}" -unless @ignore_dotenv - Dotenv.load ".env.#{@env}" if File.file?(".env.#{@env}") -end if Rails.env == 'test' Settings.add_source!("./config/settings.test.yml") else diff --git a/config/environments/ci.rb b/config/environments/ci.rb new file mode 100755 index 00000000..33e72132 --- /dev/null +++ b/config/environments/ci.rb @@ -0,0 +1,60 @@ +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +Commitchange::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + config.cache_store = Settings.default.cache_store.to_sym + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # You can uncomment the following to test our real AWS email server on localhost: + # config.action_mailer.delivery_method = :aws_ses + # config.action_mailer.default_url_options = { host: 'commitchange.com' } + config.action_mailer.delivery_method = Settings.mailer.delivery_method.to_sym + config.action_mailer.smtp_settings = { address: Settings.mailer.address, port: Settings.mailer.port } + config.action_mailer.smtp_settings['user_name']= Settings.mailer.username if Settings.mailer.username + config.action_mailer.smtp_settings['password']= Settings.mailer.password if Settings.mailer.password + + config.action_mailer.default_url_options = { host: Settings.mailer.host } + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin + + # Raise exception on mass assignment protection for Active Record models + config.active_record.mass_assignment_sanitizer = :strict + + # Log the query plan for queries taking more than this (works) + # with SQLite, MySQL, and PostgreSQL) + config.active_record.auto_explain_threshold_in_seconds = 0.5 + + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true + + config.log_level = :debug + + config.threadsafe! + config.dependency_loading = true if $rails_rake_task + # Turn this on if you want to mess with code inside /node_modules + # config.browserify_rails.evaluate_node_modules = true + + config.middleware.use I18n::JS::Middleware + + config.after_initialize do + ActiveRecord::Base.logger = nil + end + +end \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 903476ff..775ab196 100755 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -57,4 +57,5 @@ Commitchange::Application.configure do # config.browserify_rails.evaluate_node_modules = true config.middleware.use I18n::JS::Middleware + end diff --git a/config/environments/test.rb b/config/environments/test.rb index da39a8c5..64bf4084 100755 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -38,11 +38,18 @@ Commitchange::Application.configure do # Expands the lines which load the assets config.assets.debug = true - config.log_level = :debug + config.log_level = :none config.action_controller.allow_forgery_protection = false config.cache_store = :memory_store config.threadsafe! + config.after_initialize do + ActiveRecord::Base.logger = nil + ActionController::Base.logger = nil + ActionMailer::Base.logger = nil + end + + end diff --git a/config/initializers/log_rage.rb b/config/initializers/log_rage.rb index a87ed68f..5e8470d6 100644 --- a/config/initializers/log_rage.rb +++ b/config/initializers/log_rage.rb @@ -1,5 +1,8 @@ # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later Commitchange::Application.configure do + if (Rails.env != 'test') + + config.lograge.enabled = true # add time to lograge config.lograge.custom_options = lambda do |event| @@ -8,4 +11,5 @@ Commitchange::Application.configure do exception_object: event.payload[:exception_object] # the exception instance } end + end end \ No newline at end of file diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile new file mode 100644 index 00000000..c1d27269 --- /dev/null +++ b/docker/build/Dockerfile @@ -0,0 +1,17 @@ +FROM ruby:2.3.7-stretch +ARG USER +RUN mkdir /myapp +COPY script/build/debian/prebuild.sh myapp/script/build/debian/prebuild.sh +RUN myapp/script/build/debian/prebuild.sh +COPY script/build/debian/node.sh myapp/script/build/debian/node.sh +RUN myapp/script/build/debian/node.sh +COPY script/build/debian/postgres.sh myapp/script/build/debian/postgres.sh +RUN myapp/script/build/debian/postgres.sh +COPY script/build/debian/java.sh myapp/script/build/debian/java.sh +RUN myapp/script/build/debian/java.sh +WORKDIR /myapp +COPY Gemfile /myapp/Gemfile +COPY Gemfile.lock /myapp/Gemfile.lock +RUN bundle install +CMD rake -T + diff --git a/docker/build/docker-compose.yml b/docker/build/docker-compose.yml new file mode 100644 index 00000000..2bebe9b1 --- /dev/null +++ b/docker/build/docker-compose.yml @@ -0,0 +1,23 @@ +# License: CC0-1.0 +version: '2' +services: + build: + build: + context: ../.. + dockerfile: docker/build/Dockerfile + depends_on: + - db + - memcached + environment: + - DATABASE_HOST=db + - MEMCACHE_SERVERS=memcached + volumes: + - ../../:/myapp + db: + image: postgres:9.6 + environment: + POSTGRES_USER: "admin" + POSTGRES_PASSWORD: "password" + memcached: + image: memcached + diff --git a/docker/debug/Dockerfile b/docker/debug/Dockerfile new file mode 100644 index 00000000..66785018 --- /dev/null +++ b/docker/debug/Dockerfile @@ -0,0 +1,28 @@ +FROM ruby:2.3.7-stretch +ARG USER +RUN mkdir /myapp +COPY script/build/debian/prebuild.sh myapp/script/build/debian/prebuild.sh +RUN myapp/script/build/debian/prebuild.sh +COPY script/build/debian/node.sh myapp/script/build/debian/node.sh +RUN myapp/script/build/debian/node.sh +COPY script/build/debian/postgres.sh myapp/script/build/debian/postgres.sh +RUN myapp/script/build/debian/postgres.sh +COPY script/build/debian/java.sh myapp/script/build/debian/java.sh +RUN myapp/script/build/debian/java.sh +WORKDIR /myapp +RUN groupadd -r -g 1000 $USER +RUN useradd -r -m -g $USER -u 1000 $USER +RUN chown -R $USER /usr/local/bundle +RUN chgrp -R $USER /usr/local/bundle +RUN chown -R $USER /myapp +RUN chgrp -R $USER /myapp +RUN chown -R $USER /usr/lib/node_modules +RUN chgrp -R $USER /usr/lib/node_modules +COPY Gemfile /myapp/Gemfile +COPY Gemfile.lock /myapp/Gemfile.lock +RUN bundle install +RUN chown -R $USER /myapp/Gemfile +RUN chgrp -R $USER /myapp/Gemfile.lock +USER $USER +EXPOSE 5000 +CMD foreman start diff --git a/docker-compose.yml b/docker/debug/docker-compose.yml similarity index 54% rename from docker-compose.yml rename to docker/debug/docker-compose.yml index 522377b1..4f4378ee 100644 --- a/docker-compose.yml +++ b/docker/debug/docker-compose.yml @@ -1,29 +1,37 @@ # License: CC0-1.0 version: '2' services: + web: + build: + context: ../.. + dockerfile: docker/debug/Dockerfile + args: + - USER + user: ${USER} + + environment: + - DATABASE_HOST=db + - MEMCACHE_SERVERS=memcached + - USER=${USER} + + volumes: + - ../../:/myapp + + ports: + - "5000:5000" + depends_on: + - db + - memcached db: image: postgres:9.6 environment: POSTGRES_USER: "admin" POSTGRES_PASSWORD: "password" - volumes: - - ./postgres-data:/var/lib/postgresql/data - web: - build: - context: . - args: - - USER - volumes: - - .:/myapp - ports: - - "5000:5000" - depends_on: - - db - - memcached - user: ${USER} - environment: - - USER=${USER} - - DATABASE_HOST=db - - MEMCACHE_SERVERS=memcached memcached: image: memcached + + + + + + diff --git a/package.json b/package.json index 1249e853..1f721e46 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "watch": "export HOUDINI_WATCH=1; script/build.sh", "build": "script/build.sh", "build-all": "npm ci && script/compile-assets.sh && npm run build", - "test": "rake spec && npm run build && npx jest", + "test": "rake -v spec && npm run build && npx jest", "export-button-config": "bundle exec rake settings:generate_json", "export-i18n": "bundle exec rake settings:combine_translations", "generate-openapi": "rake oapi:gen", diff --git a/run b/run index 9bb36460..bf6549c3 100755 --- a/run +++ b/run @@ -1,2 +1,2 @@ #!/usr/bin/env bash -docker-compose run web $@ +docker-compose -f docker/debug/docker-compose.yml run web $@ diff --git a/script/build/debian/java.sh b/script/build/debian/java.sh new file mode 100755 index 00000000..983907ce --- /dev/null +++ b/script/build/debian/java.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +apt-get -yy install default-jre \ No newline at end of file diff --git a/script/build/debian/node.sh b/script/build/debian/node.sh new file mode 100755 index 00000000..29c45c06 --- /dev/null +++ b/script/build/debian/node.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e + +curl -sL https://deb.nodesource.com/setup_9.x | bash - +apt-get update -qq && apt-get install -y nodejs +npm install npm@^6 -g \ No newline at end of file diff --git a/script/build/debian/postgres.sh b/script/build/debian/postgres.sh new file mode 100755 index 00000000..8f264f84 --- /dev/null +++ b/script/build/debian/postgres.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +apt-get -yy install libpq5=9.6.10-0+deb9u1 libpq-dev=9.6.10-0+deb9u1 postgresql=9.6+181+deb9u1 diff --git a/script/build/debian/prebuild.sh b/script/build/debian/prebuild.sh new file mode 100755 index 00000000..2c8fe862 --- /dev/null +++ b/script/build/debian/prebuild.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +apt-get update -qq && apt-get install -y build-essential \ No newline at end of file diff --git a/script/debian_setup.sh b/script/debian_setup.sh index 5839d3b7..d36dfa9c 100755 --- a/script/debian_setup.sh +++ b/script/debian_setup.sh @@ -2,7 +2,7 @@ set -e curl -sL https://deb.nodesource.com/setup_9.x | bash - -echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' > /etc/apt/sources.list.d/pgdg.list + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-9.6 default-jre npm install npm@^6 -g \ No newline at end of file diff --git a/script/test.sh b/script/test.sh new file mode 100755 index 00000000..38faac5c --- /dev/null +++ b/script/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +npm ci && rake db:create db:structure:load db:migrate && RAILS_ENV=test rake db:create db:structure:load test:prepare && rake spec && npm run build-all && npx jest \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 41eae771..70f7fb75 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -117,3 +117,16 @@ RSpec.configure do |config| end end end + +if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9" + module Kernel + alias :__at_exit :at_exit + def at_exit(&block) + __at_exit do + exit_status = $!.status if $!.is_a?(SystemExit) + block.call + exit exit_status if exit_status + end + end + end +end