From e43d00c077833e1e17d91476e7b587889cf55bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 11:18:42 +0300 Subject: [PATCH 1/9] KBP-144 #time 1h implement docker development environment --- lib/cybele.rb | 1 + lib/cybele/app_builder.rb | 1 + lib/cybele/generators/app_generator.rb | 13 ++++++ lib/cybele/helpers/docker.rb | 28 +++++++++++++ spec/features/new_default_project_spec.rb | 25 +++++++++++ templates/docker/Dockerfile.erb | 49 ++++++++++++++++++++++ templates/docker/docker-compose.yml.erb | 42 +++++++++++++++++++ templates/docker/docker_env_local.erb | 10 +++++ templates/docker/docker_env_production.erb | 3 ++ templates/docker/docker_env_sample.erb | 10 +++++ templates/docker/docker_env_staging.erb | 3 ++ templates/docker/start-app.sh.erb | 7 ++++ templates/docker/start-sidekiq.sh.erb | 15 +++++++ 13 files changed, 207 insertions(+) create mode 100644 lib/cybele/helpers/docker.rb create mode 100644 templates/docker/Dockerfile.erb create mode 100644 templates/docker/docker-compose.yml.erb create mode 100644 templates/docker/docker_env_local.erb create mode 100644 templates/docker/docker_env_production.erb create mode 100644 templates/docker/docker_env_sample.erb create mode 100644 templates/docker/docker_env_staging.erb create mode 100644 templates/docker/start-app.sh.erb create mode 100644 templates/docker/start-sidekiq.sh.erb diff --git a/lib/cybele.rb b/lib/cybele.rb index 08f5805..42dbf13 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -15,4 +15,5 @@ require 'cybele/helpers/mailer' require 'cybele/helpers/paperclip' require 'cybele/helpers/devise' +require 'cybele/helpers/docker' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 3026c1b..81bd8ee 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -15,6 +15,7 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::Mailer include Cybele::Helpers::Paperclip include Cybele::Helpers::Devise + include Cybele::Helpers::Docker def readme template 'README.md.erb', diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index 51a9b5a..5ed4779 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -60,6 +60,12 @@ class AppGenerator < Rails::Generators::AppGenerator default: false, group: :cybele, desc: 'Skip haml and haml-rails integration. Default: don\'t skip' + class_option :skip_docker, + type: :boolean, + aliases: nil, + default: false, + group: :cybele, + desc: 'Skip docker development environment. Default: don\'t skip' def initialize(*args) super @@ -75,6 +81,7 @@ def initialize(*args) option_with_ask_yes(:skip_simple_form) option_with_ask_yes(:skip_show_for) option_with_ask_yes(:skip_haml) + option_with_ask_yes(:skip_docker) @options.freeze end @@ -213,6 +220,12 @@ def gitignore_files_and_folders build :setup_gitignore_folders end + def docker_development_env + return if @options[:skip_docker] + say 'Setup docker development environment', :green + build :setup_docker_development_env + end + def goodbye say 'Congratulations! That\'s all...', :green end diff --git a/lib/cybele/helpers/docker.rb b/lib/cybele/helpers/docker.rb new file mode 100644 index 0000000..84c2ad4 --- /dev/null +++ b/lib/cybele/helpers/docker.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Cybele + module Helpers + module Docker + def setup_docker_development_env + # Create docker files + template 'docker/docker-compose.yml.erb', + 'docker-compose.yml', + force: true + template 'docker/Dockerfile.erb', + 'Dockerfile', + force: true + template 'docker/start-app.sh.erb', + 'bin/start-app.sh', + force: true + template 'docker/start-sidekiq.sh.erb', + 'bin/start-sidekiq.sh', + force: true + + append_file('env.sample', template_content('docker/docker_env_sample.erb')) + append_file('.env.local', template_content('docker/docker_env_local.erb')) + append_file('.env.staging', template_content('docker/docker_env_staging.erb')) + append_file('.env.production', template_content('docker/docker_env_production.erb')) + end + end + end +end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 3c41e1b..f635ee9 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -207,4 +207,29 @@ it 'uses devise' do devise_test_helper end + + it 'uses docker development environment' do + expect(File).to exist(file_project_path('docker-compose.yml')) + expect(File).to exist(file_project_path('Dockerfile')) + expect(File).to exist(file_project_path('bin/start-app.sh')) + expect(File).to exist(file_project_path('bin/start-sidekiq.sh')) + + env_sample_file = content('env.sample') + expect(env_sample_file).to match('REDISTOGO_URL=redis://redis:6379/0') + expect(env_sample_file).to match('RACK_ENV=development') + expect(env_sample_file).to match('POSTGRESQL_HOST=postgres') + expect(env_sample_file).to match('REDIS_HOST=redis') + + env_local_file = content('.env.local') + expect(env_local_file).to match('REDISTOGO_URL=redis://redis:6379/0') + expect(env_local_file).to match('RACK_ENV=development') + expect(env_local_file).to match('POSTGRESQL_HOST=postgres') + expect(env_local_file).to match('REDIS_HOST=redis') + + env_staging_file = content('.env.staging') + expect(env_staging_file).to match('REDISTOGO_URL=') + + env_production_file = content('.env.production') + expect(env_production_file).to match('REDISTOGO_URL=') + end end diff --git a/templates/docker/Dockerfile.erb b/templates/docker/Dockerfile.erb new file mode 100644 index 0000000..790185a --- /dev/null +++ b/templates/docker/Dockerfile.erb @@ -0,0 +1,49 @@ +FROM ruby:2.3.3 +MAINTAINER dev@lab2023.com + +# Install apt based dependencies required to run Rails as +# well as RubyGems. As the Ruby image itself is based on a +# Debian image, we use apt-get to install those. +# Add for locales locales \ +RUN apt-get update && apt-get install -y \ + build-essential \ + qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x \ + nodejs \ + cmake + + +# Use en_US.UTF-8 as our locale +# RUN locale-gen en_US.UTF-8 +# ENV LANG en_US.UTF-8 +# ENV LANGUAGE en_US:en +# ENV LC_ALL en_US.UTF-8 + +# Configure the main working directory. This is the base +# directory used in any further RUN, COPY, and ENTRYPOINT +# commands. +RUN mkdir -p /app +WORKDIR /app + +# Copy the Gemfile as well as the Gemfile.lock and install +# the RubyGems. This is a separate step so the dependencies +# will be cached unless changes to one of those two files +# are made. +# COPY Gemfile Gemfile.lock ./ +# RUN gem install bundler && bundle install --jobs 20 --retry 5 +ENV BUNDLE_PATH /gems_box + +# Copy the main application. +COPY . ./ + +# Expose port 3000 to the Docker host, so we can access it +# from the outside. +EXPOSE 3000 + +# Configure an entry point, so we don't need to specify +# "bundle exec" for each of our commands. +# ENTRYPOINT ["bundle", "exec"] + +# The main command to run when the container starts. Also +# tell the Rails dev server to bind to all interfaces by +# default. +CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] \ No newline at end of file diff --git a/templates/docker/docker-compose.yml.erb b/templates/docker/docker-compose.yml.erb new file mode 100644 index 0000000..205ca1a --- /dev/null +++ b/templates/docker/docker-compose.yml.erb @@ -0,0 +1,42 @@ +version: '2.1' +services: + app: + build: . + env_file: ./.env.local + command: bash ./bin/start-app.sh + volumes: + - .:/app + ports: + - "3000:3000" + links: + - postgres + - redis + volumes_from: + - box + box: + image: busybox + volumes: + - /gems_box + postgres: + image: postgres:9.5 + ports: + - "5433:5432" + redis: + image: redis:3.2 + env_file: ./.env.local + command: redis-server + ports: + - '6380:6379' + volumes: + - ./tmp/data:/data + sidekiq: + build: . + env_file: ./.env.local + volumes: + - .:/app + volumes_from: + - box + links: + - postgres + - redis + command: bash ./bin/start-sidekiq.sh \ No newline at end of file diff --git a/templates/docker/docker_env_local.erb b/templates/docker/docker_env_local.erb new file mode 100644 index 0000000..df04f73 --- /dev/null +++ b/templates/docker/docker_env_local.erb @@ -0,0 +1,10 @@ + + +REDISTOGO_URL=redis://redis:6379/0 + +##### Docker compose environments + +# Set Rails/Rack environment +RACK_ENV=development +POSTGRESQL_HOST=postgres +REDIS_HOST=redis \ No newline at end of file diff --git a/templates/docker/docker_env_production.erb b/templates/docker/docker_env_production.erb new file mode 100644 index 0000000..007e134 --- /dev/null +++ b/templates/docker/docker_env_production.erb @@ -0,0 +1,3 @@ + + +REDISTOGO_URL= diff --git a/templates/docker/docker_env_sample.erb b/templates/docker/docker_env_sample.erb new file mode 100644 index 0000000..df04f73 --- /dev/null +++ b/templates/docker/docker_env_sample.erb @@ -0,0 +1,10 @@ + + +REDISTOGO_URL=redis://redis:6379/0 + +##### Docker compose environments + +# Set Rails/Rack environment +RACK_ENV=development +POSTGRESQL_HOST=postgres +REDIS_HOST=redis \ No newline at end of file diff --git a/templates/docker/docker_env_staging.erb b/templates/docker/docker_env_staging.erb new file mode 100644 index 0000000..007e134 --- /dev/null +++ b/templates/docker/docker_env_staging.erb @@ -0,0 +1,3 @@ + + +REDISTOGO_URL= diff --git a/templates/docker/start-app.sh.erb b/templates/docker/start-app.sh.erb new file mode 100644 index 0000000..2edf13f --- /dev/null +++ b/templates/docker/start-app.sh.erb @@ -0,0 +1,7 @@ +#!/bin/bash + +bundle check || bundle install + +rm -rf ./tmp/pids/server.pid + +bundle exec rails server -p 3000 -b '0.0.0.0' \ No newline at end of file diff --git a/templates/docker/start-sidekiq.sh.erb b/templates/docker/start-sidekiq.sh.erb new file mode 100644 index 0000000..7d27452 --- /dev/null +++ b/templates/docker/start-sidekiq.sh.erb @@ -0,0 +1,15 @@ +#!/bin/bash + +bundle check || bundle install +bundle config git.allow_insecure true + +echo 'Stopping sidekiq if exists' +bundle exec sidekiqctl stop tmp/pids/sidekiq.pid + +echo 'Stopped sidekiq' +rm -rf ./tmp/pids/sidekiq.pid + +echo 'Starting sidekiq' +bundle exec sidekiq -C config/sidekiq.yml + +echo 'Started sidekiq' \ No newline at end of file From 7015df2320db04ae7f49d22af8a5a6c6eb77d81a Mon Sep 17 00:00:00 2001 From: FatihAvsan Date: Tue, 21 Nov 2017 11:52:06 +0300 Subject: [PATCH 2/9] KBP-138 #time 1.5h - added ssl control staging and production --- lib/cybele/app_builder.rb | 7 +++++++ lib/cybele/generators/app_generator.rb | 5 +++++ spec/features/new_default_project_spec.rb | 4 ++++ spec/features/new_not_default_project_spec.rb | 4 ++++ spec/support/gem_test_helpers.rb | 9 +++++++++ 5 files changed, 29 insertions(+) diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 3026c1b..454237d 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -32,6 +32,13 @@ def add_gems append_file('Gemfile', template_content('Gemfile.erb')) end + def force_ssl_setting + gsub_file 'config/environments/production.rb', + /# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?" + gsub_file 'config/environments/staging.rb', + /# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?" + end + def add_editor_config copy_file 'editorconfig', '.editorconfig' end diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index 51a9b5a..e7fd791 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -187,6 +187,11 @@ def setup_bullet_config build :configure_bullet end + def force_ssl + say 'Add ssl control into staging.rb and production.rb', :green + build :force_ssl_setting + end + def setup_paperclip_and_add_aws say 'Setting up paperclip, editing settings.yml and env files', :green build :configure_paperclip diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 3c41e1b..ea3321b 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -207,4 +207,8 @@ it 'uses devise' do devise_test_helper end + + it 'uses ssl_setting' do + force_ssl + end end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 8bb6500..1890d34 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -187,4 +187,8 @@ it 'uses devise' do devise_test_helper end + + it 'uses ssl_setting' do + force_ssl + end end diff --git a/spec/support/gem_test_helpers.rb b/spec/support/gem_test_helpers.rb index 71a60b2..93f8b12 100644 --- a/spec/support/gem_test_helpers.rb +++ b/spec/support/gem_test_helpers.rb @@ -145,4 +145,13 @@ def config_test_helper config_test_file = content('config/environments/test.rb') expect(config_test_file).to match(/^Rails.application.configure/) end + + def force_ssl + config_staging_file = content('config/environments/staging.rb') + expect(config_staging_file).to match('config.force_ssl') + + config_production_file = content('config/environments/staging.rb') + expect(config_production_file).to match('config.force_ssl') + end + end From ce012b8b61ad15203876e28564a1e9017d02494e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 14:46:22 +0300 Subject: [PATCH 3/9] KBP-144 #time 20m implement docker development environment specs --- spec/features/new_default_project_spec.rb | 2 +- spec/features/new_not_default_project_spec.rb | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 8894670..0ee4a22 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -6,7 +6,7 @@ before(:all) do drop_dummy_database remove_project_directory - run_cybele + run_cybele('--skip-create-database') setup_app_dependencies end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 434aeb1..c9a5420 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -7,7 +7,7 @@ drop_dummy_database remove_project_directory run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for'\ - ' --skip-haml') + ' --skip-haml --skip-docker') setup_app_dependencies end @@ -195,4 +195,23 @@ it 'uses gitignore' do git_ignore_test end + + it "don't use docker development environment" do + expect(File).not_to exist(file_project_path('docker-compose.yml')) + expect(File).not_to exist(file_project_path('Dockerfile')) + expect(File).not_to exist(file_project_path('bin/start-app.sh')) + expect(File).not_to exist(file_project_path('bin/start-sidekiq.sh')) + + env_sample_file = content('env.sample') + expect(env_sample_file).not_to match('REDISTOGO_URL=redis://redis:6379/0') + + env_local_file = content('.env.local') + expect(env_local_file).not_to match('REDISTOGO_URL=redis://redis:6379/0') + + env_staging_file = content('.env.staging') + expect(env_staging_file).not_to match('REDISTOGO_URL=') + + env_production_file = content('.env.production') + expect(env_production_file).not_to match('REDISTOGO_URL=') + end end From 07f3b0770fa24831813d0ac9bda82477351c496e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 14:56:14 +0300 Subject: [PATCH 4/9] Add pronto to gem development dependencies --- .gitignore | 3 ++- cybele.gemspec | 3 +++ example.pronto.yml | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 example.pronto.yml diff --git a/.gitignore b/.gitignore index 8602e15..10625ee 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ *.bundle/install.log Gemfile.lock tmp/ -.DS_Store \ No newline at end of file +.DS_Store +.pronto.yml \ No newline at end of file diff --git a/cybele.gemspec b/cybele.gemspec index 290b1b6..bff17a7 100644 --- a/cybele.gemspec +++ b/cybele.gemspec @@ -26,6 +26,9 @@ Gem::Specification.new do |spec| spec.add_dependency 'bundler', '~> 1.5' spec.add_runtime_dependency 'rails', '~> 5.0', Cybele::RAILS_VERSION spec.add_development_dependency 'rspec', '~> 3.5' + spec.add_development_dependency 'pronto', '~> 0.9.5' + spec.add_development_dependency 'pronto-flay', '~> 0.9.0' + spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0' spec.extra_rdoc_files = %w[README.md MIT-LICENSE] end diff --git a/example.pronto.yml b/example.pronto.yml new file mode 100644 index 0000000..6756f37 --- /dev/null +++ b/example.pronto.yml @@ -0,0 +1,8 @@ +all: + exclude: + - 'spec/**/*' +bitbucket: + slug: 'lab2023corp/cybele' + username: 'username' + password: 'password' +max_warnings: 150 \ No newline at end of file From 6ec9e085c20c070026174fcc2d8e390682596e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 15:04:11 +0300 Subject: [PATCH 5/9] KBP-144 #time 5m code refactor for pronto result --- lib/cybele/helpers/docker.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/cybele/helpers/docker.rb b/lib/cybele/helpers/docker.rb index 84c2ad4..3cc7869 100644 --- a/lib/cybele/helpers/docker.rb +++ b/lib/cybele/helpers/docker.rb @@ -18,6 +18,12 @@ def setup_docker_development_env 'bin/start-sidekiq.sh', force: true + docker_dotenv_files + end + + private + + def docker_dotenv_files append_file('env.sample', template_content('docker/docker_env_sample.erb')) append_file('.env.local', template_content('docker/docker_env_local.erb')) append_file('.env.staging', template_content('docker/docker_env_staging.erb')) From 365bb6a3ce25105a93a7b3c374f165b104632494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 15:10:30 +0300 Subject: [PATCH 6/9] KBP-144 #time 5m code refactor for pronto result --- lib/cybele/helpers/docker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cybele/helpers/docker.rb b/lib/cybele/helpers/docker.rb index 3cc7869..e34574e 100644 --- a/lib/cybele/helpers/docker.rb +++ b/lib/cybele/helpers/docker.rb @@ -25,9 +25,9 @@ def setup_docker_development_env def docker_dotenv_files append_file('env.sample', template_content('docker/docker_env_sample.erb')) - append_file('.env.local', template_content('docker/docker_env_local.erb')) - append_file('.env.staging', template_content('docker/docker_env_staging.erb')) - append_file('.env.production', template_content('docker/docker_env_production.erb')) + %w[local staging production].each do |env| + append_file(".env.#{env}", template_content("docker/docker_env_#{env}.erb")) + end end end end From 95659f9d0f83bd2e5b63933ed4d5bdc1673db912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 16:05:47 +0300 Subject: [PATCH 7/9] KBP-145 #time 1h add pronto and rubocop to created project --- lib/cybele.rb | 1 + lib/cybele/app_builder.rb | 1 + lib/cybele/generators/app_generator.rb | 6 ++++ lib/cybele/helpers/pronto.rb | 27 ++++++++++++++ spec/features/new_default_project_spec.rb | 4 +++ spec/features/new_not_default_project_spec.rb | 4 +++ spec/spec_helper.rb | 1 + spec/support/pronto_test_helpers.rb | 18 ++++++++++ templates/Gemfile.erb | 6 ++++ templates/pronto/.rubocop.yml.erb | 35 +++++++++++++++++++ templates/pronto/example.pronto.yml.erb | 27 ++++++++++++++ templates/pronto/rubo.erb | 24 +++++++++++++ 12 files changed, 154 insertions(+) create mode 100644 lib/cybele/helpers/pronto.rb create mode 100644 spec/support/pronto_test_helpers.rb create mode 100644 templates/pronto/.rubocop.yml.erb create mode 100644 templates/pronto/example.pronto.yml.erb create mode 100755 templates/pronto/rubo.erb diff --git a/lib/cybele.rb b/lib/cybele.rb index 94ae3d6..462624d 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -17,4 +17,5 @@ require 'cybele/helpers/devise' require 'cybele/helpers/docker' require 'cybele/helpers/error_pages' +require 'cybele/helpers/pronto' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index d5dc9ea..dbd3016 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -17,6 +17,7 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::Devise include Cybele::Helpers::ErrorPages include Cybele::Helpers::Docker + include Cybele::Helpers::Pronto def readme template 'README.md.erb', diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index ac365fa..54acb49 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -88,6 +88,7 @@ def initialize(*args) def customize_gemfile say 'Customize gem file', :green build :add_gems + bundle_command 'update thor' build :add_simple_form_gem unless @options[:skip_simple_form] build :add_show_for_gem unless @options[:skip_show_for] build :add_haml_gems unless @options[:skip_haml] @@ -231,6 +232,11 @@ def docker_development_env build :setup_docker_development_env end + def setup_pronto_config + say 'Setup pronto config', :green + build :configure_pronto + end + def goodbye say 'Congratulations! That\'s all...', :green end diff --git a/lib/cybele/helpers/pronto.rb b/lib/cybele/helpers/pronto.rb new file mode 100644 index 0000000..9a80238 --- /dev/null +++ b/lib/cybele/helpers/pronto.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Cybele + module Helpers + module Pronto + def configure_pronto + # Create pronto files + template 'pronto/example.pronto.yml.erb', + 'example.pronto.yml', + force: true + template 'pronto/example.pronto.yml.erb', + '.pronto.yml', + force: true + template 'pronto/.rubocop.yml.erb', + '.rubocop.yml', + force: true + template 'pronto/rubo.erb', + 'bin/rubo', + force: true + run 'chmod +x bin/rubo' + + # Ignore secret information file + append_file('.gitignore', '.pronto.yml') + end + end + end +end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 0ee4a22..b38c9c8 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -240,4 +240,8 @@ env_production_file = content('.env.production') expect(env_production_file).to match('REDISTOGO_URL=') end + + it 'uses pronto' do + pronto_test + end end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index c9a5420..19cdc56 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -214,4 +214,8 @@ env_production_file = content('.env.production') expect(env_production_file).not_to match('REDISTOGO_URL=') end + + it 'uses pronto' do + pronto_test + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9f7b36d..6f5f285 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,6 +20,7 @@ config.include ErrorPagesTestHelper config.include GitIgnoreTestHelper config.include MailTestHelpers + config.include ProntoTestHelpers config.before(:all) do create_tmp_directory diff --git a/spec/support/pronto_test_helpers.rb b/spec/support/pronto_test_helpers.rb new file mode 100644 index 0000000..5123d76 --- /dev/null +++ b/spec/support/pronto_test_helpers.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module ProntoTestHelpers + def pronto_test + gemfile_file = content('Gemfile') + expect(gemfile_file).to match("gem 'pronto'") + expect(gemfile_file).to match("gem 'pronto-flay'") + expect(gemfile_file).to match("gem 'pronto-rubocop'") + + expect(File).to exist(file_project_path('example.pronto.yml')) + expect(File).to exist(file_project_path('.pronto.yml')) + expect(File).to exist(file_project_path('.rubocop.yml')) + expect(File).to exist(file_project_path('bin/rubo')) + + gemfile_file = content('.gitignore') + expect(gemfile_file).to match('.pronto.yml') + end +end diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index eeef807..f1687c3 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -1,4 +1,7 @@ +# General requirement +gem 'thor', '~> 0.19.4' + # For never accidentally send emails to real people from staging environment. gem 'recipient_interceptor', '~> 0.1.2' @@ -28,6 +31,9 @@ group :development, :test do gem 'better_errors', '~> 2.4' gem 'bullet', '~> 5.6', '>= 5.6.1' gem 'letter_opener', '~> 1.4', '>= 1.4.1' + gem 'pronto', '~> 0.9.5' + gem 'pronto-flay', '~> 0.9.0', require: false + gem 'pronto-rubocop', '~> 0.9.0', require: false end # A set of common locale data and translations to internationalize and/or localize your Rails applications. diff --git a/templates/pronto/.rubocop.yml.erb b/templates/pronto/.rubocop.yml.erb new file mode 100644 index 0000000..ac3e575 --- /dev/null +++ b/templates/pronto/.rubocop.yml.erb @@ -0,0 +1,35 @@ +AllCops: + Includes: + - 'Rakefile' + - 'config.ru' + - 'Gemfile' + Excludes: + - Guardfile + - bin/** + - db/**/** + - spec/**/**/**/** + - test/**/**/**/** + - tmp/**/**/**/** + +Documentation: + Enabled: false + +Metrics/LineLength: + Max: 100 + Exclude: + - 'Gemfile' + +Metrics/MethodLength: + CountComments: false + Max: 15 + +Metrics/BlockLength: + CountComments: false + Max: 40 + Exclude: + - 'Rakefile' + - '**/*.rake' + - 'spec/**/*.rb' + +Style/FrozenStringLiteralComment: + EnforcedStyle: when_needed diff --git a/templates/pronto/example.pronto.yml.erb b/templates/pronto/example.pronto.yml.erb new file mode 100644 index 0000000..4dbd5bc --- /dev/null +++ b/templates/pronto/example.pronto.yml.erb @@ -0,0 +1,27 @@ +all: + exclude: + - 'spec/**/*' +bitbucket: + slug: 'lab2023corp/<%= app_name%>' + username: 'username' + password: 'password' +max_warnings: 50 +verbose: true + +## for local changes before the commit +# before git add . +# pronto run --unstaged +# after git add . +# pronto run --staged + +## for branch commits analyze different between develop +# pronto run +# pronto run -c origin/develop + +## for pull request +# pronto run -f bitbucket_pr +# pronto run -f bitbucket_pr -c origin/develop + +## for commit +# pronto run -f bitbucket +# pronto run -f bitbucket -c origin/develop \ No newline at end of file diff --git a/templates/pronto/rubo.erb b/templates/pronto/rubo.erb new file mode 100755 index 0000000..16acc3b --- /dev/null +++ b/templates/pronto/rubo.erb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'English' +require 'rubocop' + +DISABLE_DIRECTORY = %w[db].freeze +ADDED_OR_MODIFIED = /A|AM|^M/ + +changed_files = `git status --porcelain`.split(/\n/).select do |file_name_with_status| + file_name_with_status =~ ADDED_OR_MODIFIED +end +changed_files = changed_files.map do |file_name_with_status| + file_name_with_status.split(' ')[1] +end +changed_files = changed_files.select do |file_name| + directory = file_name.split('/')[0] + !DISABLE_DIRECTORY.include?(directory) && File.extname(file_name) == '.rb' +end +changed_files = changed_files.join(' ') + +system("rubocop #{changed_files}") unless changed_files.empty? + +exit $CHILD_STATUS.to_s[-1].to_i From 505c73b3e85729850e7ab637e45f4fe25d699b40 Mon Sep 17 00:00:00 2001 From: FatihAvsan Date: Tue, 21 Nov 2017 16:05:52 +0300 Subject: [PATCH 8/9] KBP-138 #time 20m - added RAILS_FORCE_SSL environments --- lib/cybele/app_builder.rb | 2 ++ spec/spec_helper.rb | 2 +- .../{ssl_test_helper.rb => force_ssl_test_helper.rb} | 8 +++++++- templates/ssl/ssl_env_production.erb | 1 + templates/ssl/ssl_env_staging.erb | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) rename spec/support/{ssl_test_helper.rb => force_ssl_test_helper.rb} (56%) create mode 100644 templates/ssl/ssl_env_production.erb create mode 100644 templates/ssl/ssl_env_staging.erb diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 98be1dd..31bece2 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -38,6 +38,8 @@ def force_ssl_setting /# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?" gsub_file 'config/environments/staging.rb', /# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?" + append_file('.env.staging', template_content('ssl/ssl_env_staging.erb')) + append_file('.env.production', template_content('ssl/ssl_env_production.erb')) end def add_editor_config diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0392084..c567926 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,7 @@ config.include ErrorPagesTestHelper config.include GitIgnoreTestHelper config.include MailTestHelpers - config.include SSLTestHelper + config.include ForceSSLTestHelper config.before(:all) do create_tmp_directory diff --git a/spec/support/ssl_test_helper.rb b/spec/support/force_ssl_test_helper.rb similarity index 56% rename from spec/support/ssl_test_helper.rb rename to spec/support/force_ssl_test_helper.rb index ee1d388..127b117 100644 --- a/spec/support/ssl_test_helper.rb +++ b/spec/support/force_ssl_test_helper.rb @@ -1,11 +1,17 @@ # frozen_string_literal: true -module SSLTestHelper +module ForceSSLTestHelper def force_ssl config_staging_file = content('config/environments/staging.rb') expect(config_staging_file).to match('config.force_ssl') config_production_file = content('config/environments/staging.rb') expect(config_production_file).to match('config.force_ssl') + + env_staging_file = content('.env.staging') + expect(env_staging_file).to match('RAILS_FORCE_SSL=') + + env_production_file = content('.env.production') + expect(env_production_file).to match('RAILS_FORCE_SSL=') end end diff --git a/templates/ssl/ssl_env_production.erb b/templates/ssl/ssl_env_production.erb new file mode 100644 index 0000000..1fb1a27 --- /dev/null +++ b/templates/ssl/ssl_env_production.erb @@ -0,0 +1 @@ +RAILS_FORCE_SSL= \ No newline at end of file diff --git a/templates/ssl/ssl_env_staging.erb b/templates/ssl/ssl_env_staging.erb new file mode 100644 index 0000000..1fb1a27 --- /dev/null +++ b/templates/ssl/ssl_env_staging.erb @@ -0,0 +1 @@ +RAILS_FORCE_SSL= \ No newline at end of file From 407d8e5e7925879e94cba8ab7314e2bbe4598dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Akbudak?= Date: Tue, 21 Nov 2017 17:00:27 +0300 Subject: [PATCH 9/9] Add dependency for thor and development info to README --- README.md | 5 +++++ cybele.gemspec | 1 + 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 628ffa3..03f44d6 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,11 @@ If you discover any bugs or want to drop a line, feel free to create an issue on http://github.com/lab2023/cybele/issues +## Development +* Clone project +* Run: brew install cmake +* Run: bundle + ## Contributing Cybele uses [rDoc](http://rubydoc.info/gems/cybele) and [SemVer](http://semver.org/), and takes it seriously. diff --git a/cybele.gemspec b/cybele.gemspec index bff17a7..4b838c0 100644 --- a/cybele.gemspec +++ b/cybele.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'bundler', '~> 1.5' spec.add_runtime_dependency 'rails', '~> 5.0', Cybele::RAILS_VERSION spec.add_development_dependency 'rspec', '~> 3.5' + spec.add_development_dependency 'thor', '~> 0.19.4' spec.add_development_dependency 'pronto', '~> 0.9.5' spec.add_development_dependency 'pronto-flay', '~> 0.9.0' spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0'