potassium 5.2.0 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 586c6642ed62cba7a9a9aadba36fc53ea14f3dda6bd182c1e4e66e5818a4c19f
4
- data.tar.gz: 8d12fa2fbf200d8664945c8187c4d257e3a5b5285057032a95eacb03ad088be4
3
+ metadata.gz: 88890214b6b2c25983461ebce4351f5d988d02af8616c5b5a5dc9ff6628a9a80
4
+ data.tar.gz: 2bd3d019f36148439c4b271cba2a3db65d3c1d9720eab2cf0509202c2c4553c3
5
5
  SHA512:
6
- metadata.gz: 60726b985ce4c24e7be3f92ecb9f8f9532b171b995768eef00e3afc8aa4ab6480d7f39a48efcb4a2b4da0d48154caa2f66a5f4eea5cf9269569c5955a7155fa3
7
- data.tar.gz: 8bb3ee2bac542101adc27bc41a5ea6823cbb6a94a0a76bbcff731a3139c8d050f6b7d3d8ca8ba7b1715bb64b269999c0e393d5d712e278f745ccbbadfad24479
6
+ metadata.gz: 8982526dca4d0faf9a5ab380c1105c59dc7dfbb71d1c8bb63118367ea172924c4fb2d3468226d2392fb414b426c1bcc458c6b90caf12145b8997d6b6bd8ee11e
7
+ data.tar.gz: 9279a00b0ede0b3a1ca12e206229ff872475196cacc74231130fc1da4380357d00df8594b1c5036d8f0b59acce08483a69ffdccd28423f8a388013d71a3d511e
@@ -22,3 +22,6 @@ indent_size = 2
22
22
 
23
23
  [*.md]
24
24
  trim_trailing_whitespace = false
25
+
26
+ [Makefile]
27
+ indent_style = tab
@@ -1,6 +1,21 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 5.2.1
4
+
5
+ Features:
6
+ - Databases are now provided as docker containers
7
+
8
+ Changes:
9
+ - Update postgres to 11
10
+ - Update mysql to 5.7
11
+ - Update rubocop to `~> 0.65.0`
12
+ - Puma worker timeout is extended to 1 day in development env
13
+ - Spring is loaded only in development env
14
+ - Remove version requirement for `pg`
15
+
16
+ Fix:
17
+ - Update mysql2 to `~> 0.5.0` (required for rails 5+)
18
+ - Use `RACK_TIMEOUT` env var instead deprecated setter
4
19
 
5
20
  ## 5.2.0
6
21
 
data/README.md CHANGED
@@ -42,7 +42,7 @@ Potassium Rails apps includes the following gems and technologies:
42
42
  - [EditorConfig](http://editorconfig.org) for keeping all our editor configurations the same.
43
43
  - [pry](http://pryrepl.org) and [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug) for a less painful debugging experience.
44
44
  - [RSpec](http://rspec.info) for unit and integration testing.
45
- - [FactoryBot](https://github.com/thoughtbot/factory_bot] for test factories.
45
+ - [FactoryBot](https://github.com/thoughtbot/factory_bot) for test factories.
46
46
  - [Guard](http://guardgem.org) for continuous testing and other watch-related tasks.
47
47
  - [AWS-SDK](https://github.com/aws/aws-sdk-ruby) for file uploads, sdks, etc and because we use AWS.
48
48
  - [Puma](https://github.com/puma/puma) to serve HTTP requests
@@ -0,0 +1,46 @@
1
+ PROJECT ?= <%= get(:underscorized_app_name) %>
2
+ DOCKER_COMPOSE_FILE ?= docker-compose.yml
3
+
4
+ DOCKER_COMPOSE_ARGS ?= -p $(PROJECT) -f $(DOCKER_COMPOSE_FILE)
5
+
6
+ SHELL := /bin/bash
7
+
8
+ run: help
9
+
10
+ BOLD ?= $(shell tput bold)
11
+ NORMAL ?= $(shell tput sgr0)
12
+
13
+ help:
14
+ @echo Install dependencies:
15
+ @echo " ${BOLD}make setup${NORMAL}"
16
+ @echo ""
17
+ @echo Runing the services like mysql:
18
+ @echo " ${BOLD}make services-up${NORMAL}"
19
+ @echo ""
20
+ @echo "Reset the environment (rm mysql db):"
21
+ @echo " ${BOLD}make services-down${NORMAL}"
22
+ @echo ""
23
+
24
+ setup:
25
+ bin/setup
26
+
27
+ services: services-up
28
+
29
+ services-ps:
30
+ docker-compose $(DOCKER_COMPOSE_ARGS) ps
31
+
32
+ services-up:
33
+ docker-compose $(DOCKER_COMPOSE_ARGS) up -d
34
+
35
+ services-stop:
36
+ docker-compose $(DOCKER_COMPOSE_ARGS) stop
37
+
38
+ services-down:
39
+ docker-compose $(DOCKER_COMPOSE_ARGS) down --volumes
40
+
41
+ services-logs:
42
+ docker-compose $(DOCKER_COMPOSE_ARGS) logs -f
43
+
44
+ services-port:
45
+ @set -o pipefail; \
46
+ docker-compose $(DOCKER_COMPOSE_ARGS) port ${SERVICE} ${PORT} 2> /dev/null | cut -d':' -f2 || echo ${PORT}
@@ -8,12 +8,12 @@ readme:
8
8
 
9
9
  $ ./bin/setup
10
10
 
11
- It assumes you have a machine equipped with Ruby, <%= get(:database).to_s.titleize %>, etc. If not, set up
12
- your machine with [boxen].
11
+ It assumes you have a machine equipped with Ruby, Node.js, Docker and make.
13
12
 
14
13
  The script will do the following among other things:
15
14
 
16
15
  - Install the dependecies
16
+ - Create a docker container for your database
17
17
  - Prepare your database
18
18
  - Adds heroku remotes
19
19
 
@@ -22,7 +22,6 @@ readme:
22
22
  $ heroku local
23
23
 
24
24
  [Heroku Local]: https://devcenter.heroku.com/articles/heroku-local
25
- [boxen]: http://github.com/platanus/our-boxen
26
25
  ci:
27
26
  title: "Continuous Integrations"
28
27
  body: |
@@ -13,6 +13,9 @@ bundle check || bundle install
13
13
  # Install javascript dependencies
14
14
  bin/yarn install
15
15
 
16
+ # Set up required services
17
+ make services-up
18
+
16
19
  # Set up database
17
20
  bin/rails db:setup
18
21
 
@@ -2,9 +2,9 @@ development: &default
2
2
  adapter: mysql2
3
3
  database: <%= get(:underscorized_app_name) %>_development
4
4
  encoding: utf8
5
- username: root
6
- host: <%%= ENV["BOXEN_MYSQL_HOST"] || ENV["MYSQL_HOST"] || "127.0.0.1" %>
7
- port: <%%= ENV["BOXEN_MYSQL_PORT"] || ENV["MYSQL_PORT"] || 3306 %>
5
+ host: <%%= ENV["DB_HOST"] || "127.0.0.1" %>
6
+ port: <%%= ENV["DB_PORT"] || 3306 %>
7
+ username: <%%= ENV["DB_USER"] || "root" %>
8
8
  min_messages: warning
9
9
  pool: <%%= Integer(ENV.fetch("DB_POOL", 5)) %>
10
10
  reaping_frequency: <%%= Integer(ENV.fetch("DB_REAPING_FREQUENCY", 10)) %>
@@ -2,9 +2,9 @@ development: &default
2
2
  adapter: postgresql
3
3
  database: <%= get(:underscorized_app_name) %>_development
4
4
  encoding: utf8
5
- host: <%%= ENV["BOXEN_POSTGRESQL_HOST"] || ENV["POSTGRESQL_HOST"] || "127.0.0.1" %>
6
- port: <%%= ENV["BOXEN_POSTGRESQL_PORT"] || ENV["POSTGRESQL_PORT"] || 5432 %>
7
- username: <%%= ENV["POSTGRESQL_USER"] %>
5
+ host: <%%= ENV["DB_HOST"] || "127.0.0.1" %>
6
+ port: <%%= ENV["DB_PORT"] || 5432 %>
7
+ username: <%%= ENV["DB_USER"] || 'postgres' %>
8
8
  min_messages: warning
9
9
  pool: <%%= Integer(ENV.fetch("DB_POOL", 5)) %>
10
10
  reaping_frequency: <%%= Integer(ENV.fetch("DB_REAPING_FREQUENCY", 10)) %>
@@ -20,7 +20,11 @@ preload_app!
20
20
 
21
21
  rackup DefaultRackup
22
22
  port ENV.fetch('PORT', 3000)
23
- environment ENV.fetch("RACK_ENV", "development")
23
+ rack_env = ENV.fetch("RACK_ENV", "development")
24
+ environment rack_env
25
+
26
+ # Set 1 day timeout for workers while developing
27
+ worker_timeout 1.day.seconds.to_i if rack_env == "development"
24
28
 
25
29
  on_worker_boot do
26
30
  # Worker specific setup for Rails 4.1+
@@ -0,0 +1,6 @@
1
+ ---
2
+ version: '3'
3
+
4
+ services:
5
+
6
+ volumes:
@@ -1,7 +1,7 @@
1
1
  class DockerHelpers
2
2
  def initialize(compose_path)
3
3
  @compose_path = compose_path
4
- @compose = YAML.load(File.read(compose_path))
4
+ @compose = YAML.safe_load(File.read(compose_path))
5
5
  end
6
6
 
7
7
  def add_link(target_service, linked_service)
@@ -23,14 +23,23 @@ class DockerHelpers
23
23
  end
24
24
 
25
25
  def add_service(name, definition)
26
- service = {}
27
- service[name] = YAML.load(definition)
28
- @compose['services'].merge!(service)
29
- save
26
+ add_leaf('services', name, definition)
27
+ end
28
+
29
+ def add_volume(name, definition = '')
30
+ add_leaf('volumes', name, definition)
30
31
  end
31
32
 
32
33
  private
33
34
 
35
+ def add_leaf(root_name, leaf_name, definition)
36
+ leaf = {}
37
+ leaf[leaf_name] = YAML.safe_load(definition)
38
+ @compose[root_name] = {} unless @compose[root_name].is_a? Hash
39
+ @compose[root_name].merge!(leaf)
40
+ save
41
+ end
42
+
34
43
  def save
35
44
  File.open(@compose_path, 'w') { |f| f.write @compose.to_yaml }
36
45
  end
@@ -17,7 +17,7 @@ class Recipes::Ci < Rails::AppBuilder
17
17
  if selected?(:database, :mysql)
18
18
  srv =
19
19
  <<~YAML
20
- image: "mysql:5.6.23"
20
+ image: mysql:#{Potassium::MYSQL_VERSION}
21
21
  environment:
22
22
  MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
23
23
  YAML
@@ -29,7 +29,7 @@ class Recipes::Ci < Rails::AppBuilder
29
29
  elsif selected?(:database, :postgresql)
30
30
  srv =
31
31
  <<~YAML
32
- image: "postgres:9.4.5"
32
+ image: "postgres:#{Potassium::POSTGRES_VERSION}"
33
33
  environment:
34
34
  POSTGRES_USER: postgres
35
35
  POSTGRES_PASSWORD: ''
@@ -30,8 +30,8 @@ class Recipes::Database < Rails::AppBuilder
30
30
 
31
31
  def databases(database)
32
32
  databases = {
33
- postgresql: { name: 'postgresql', gem_name: 'pg', version: '~> 0.21', relational: true },
34
- mysql: { name: 'mysql', gem_name: 'mysql2', version: '~> 0.3.18', relational: true }
33
+ postgresql: { name: 'postgresql', gem_name: 'pg', relational: true },
34
+ mysql: { name: 'mysql', gem_name: 'mysql2', version: '~> 0.5.0', relational: true }
35
35
  }
36
36
  databases[database]
37
37
  end
@@ -0,0 +1,88 @@
1
+ class Recipes::DatabaseContainer < Rails::AppBuilder
2
+ CONTAINER_VARS = {
3
+ postgresql: { port: 5432, user: 'postgres' },
4
+ mysql: { port: 3306, user: 'root' }
5
+ }
6
+
7
+ POSTGRESQL_SERVICE =
8
+ <<~YAML
9
+ image: postgres:#{Potassium::POSTGRES_VERSION}
10
+ ports:
11
+ - #{CONTAINER_VARS[:postgresql][:port]}
12
+ environment:
13
+ POSTGRES_USER: #{CONTAINER_VARS[:postgresql][:user]}
14
+ POSTGRES_PASSWORD: ''
15
+ volumes:
16
+ - postgresql_data:/var/lib/postgresql/data
17
+ YAML
18
+
19
+ MYSQL_SERVICE =
20
+ <<~YAML
21
+ image: "mysql:#{Potassium::MYSQL_VERSION}"
22
+ ports:
23
+ - #{CONTAINER_VARS[:mysql][:port]}
24
+ environment:
25
+ MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
26
+ volumes:
27
+ - mysql_data:/var/lib/mysql
28
+ YAML
29
+
30
+ def create
31
+ copy_file '../assets/docker-compose.yml', 'docker-compose.yml'
32
+
33
+ compose = DockerHelpers.new('docker-compose.yml')
34
+
35
+ db_type = get(:database)
36
+ compose.add_service(db_type.to_s, self.class.const_get("#{db_type}_service".upcase))
37
+ compose.add_volume("#{db_type}_data")
38
+ template '../assets/Makefile.erb', 'Makefile'
39
+
40
+ run 'make services-up'
41
+
42
+ set_env(db_type, CONTAINER_VARS[db_type][:port], CONTAINER_VARS[db_type][:user])
43
+ set_dot_env(db_type, CONTAINER_VARS[db_type][:port], CONTAINER_VARS[db_type][:user])
44
+ end
45
+
46
+ def install
47
+ database_config = YAML.safe_load(IO.read('config/database.yml'), [], [], true)
48
+ database = database_config['development']['adapter'].gsub(/\d+/, '').to_sym
49
+ set :database, database
50
+
51
+ template "../assets/config/database_#{database}.yml.erb", 'config/database.yml'
52
+
53
+ setup_text = # setup file is templated on project creation, manual install is needed
54
+ <<~TEXT
55
+ # Set up required services
56
+ make services-up
57
+
58
+ TEXT
59
+
60
+ insert_into_file 'bin/setup', setup_text, before: "# Set up database"
61
+ run 'bin/setup'
62
+ info "A new container with a #{get(:database)} database has been created."
63
+ end
64
+
65
+ def installed?
66
+ file_exist?("docker-compose.yml")
67
+ end
68
+
69
+ private
70
+
71
+ def set_env(_service_name, _port, _user)
72
+ ENV["DB_PORT"] = `make services-port SERVICE=#{_service_name} PORT=#{_port}`.squish
73
+ ENV["DB_USER"] = _user
74
+ end
75
+
76
+ def set_dot_env(_service_name, _port, _user)
77
+ env_text =
78
+ <<~TEXT
79
+
80
+ # Database
81
+ DB_HOST=127.0.0.1
82
+ DB_PORT=$(make services-port SERVICE=#{_service_name} PORT=#{_port})
83
+ DB_USER=#{_user}
84
+
85
+ TEXT
86
+ insert_into_file '.env.development', env_text, after: "WEB_CONCURRENCY=1\n"
87
+ end
88
+ end
@@ -0,0 +1,7 @@
1
+ class Recipes::Listen < Rails::AppBuilder
2
+ def create
3
+ gather_gems(:development) do
4
+ gather_gem('listen')
5
+ end
6
+ end
7
+ end
@@ -5,8 +5,5 @@ class Recipes::Puma < Rails::AppBuilder
5
5
  end
6
6
 
7
7
  copy_file '../assets/config/puma.rb', 'config/puma.rb', force: true
8
-
9
- # Configure rack-timout
10
- application "Rack::Timeout.timeout = (ENV[\"RACK_TIMEOUT\"] || 10).to_i", env: "production"
11
8
  end
12
9
  end
@@ -1,9 +1,15 @@
1
1
  class Recipes::Rails < Rails::AppBuilder
2
2
  def create
3
3
  gather_gem("bootsnap", require: false)
4
+ gather_gems(:development) do
5
+ gather_gem("spring")
6
+ end
4
7
 
5
8
  environment 'config.force_ssl = true', env: 'production'
9
+ disable_automatic_nonce_generation
10
+ end
6
11
 
12
+ def disable_automatic_nonce_generation
7
13
  line = "Rails.application.config.content_security_policy_nonce_generator = \
8
14
  -> request { SecureRandom.base64(16) }"
9
15
  initializer = "config/initializers/content_security_policy.rb"
@@ -9,7 +9,6 @@ end
9
9
 
10
10
  run_action(:cleaning) do
11
11
  clean_gemfile
12
- gather_gem("spring")
13
12
  end
14
13
 
15
14
  run_action(:add_utils) do
@@ -43,10 +42,12 @@ run_action(:recipe_loading) do
43
42
  create :ci
44
43
  create :style
45
44
  create :puma
45
+ create :env
46
+ create :database_container
46
47
  create :database
47
48
  create :annotate
49
+ create :listen
48
50
  create :ruby
49
- create :env
50
51
  create :yarn
51
52
  create :editorconfig
52
53
  create :aws_sdk
@@ -1,6 +1,8 @@
1
1
  module Potassium
2
- VERSION = "5.2.0"
3
- RUBY_VERSION = "2.5.1"
2
+ VERSION = "5.2.1"
3
+ RUBY_VERSION = "2.5.5"
4
4
  RAILS_VERSION = "~> 5.2.1"
5
- RUBOCOP_VERSION = "~> 0.49.1"
5
+ RUBOCOP_VERSION = "~> 0.65.0"
6
+ POSTGRES_VERSION = "11.3"
7
+ MYSQL_VERSION = "5.7"
6
8
  end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "DatabaseContainer" do
4
+ before(:all) do
5
+ drop_dummy_database
6
+ end
7
+
8
+ before do
9
+ remove_project_directory
10
+ create_dummy_project("database" => database)
11
+ end
12
+
13
+ after do
14
+ `docker-compose -f #{project_path}/docker-compose.yml down`
15
+ end
16
+
17
+ [:postgresql, :mysql].each do |db_type|
18
+ context "when database is #{db_type}" do
19
+ let!(:database) { db_type }
20
+
21
+ it "creates a #{db_type} database container" do
22
+ env_file = IO.read("#{project_path}/.env.development")
23
+ compose_file = IO.read("#{project_path}/docker-compose.yml")
24
+ compose_content = YAML.safe_load(compose_file, symbolize_names: true)
25
+ setup_file = IO.read("#{project_path}/bin/setup")
26
+
27
+ service_name = compose_content[:services].keys.first
28
+ db_port = compose_content[:services][service_name][:ports].first
29
+
30
+ expect(env_file)
31
+ .to include("DB_PORT=$(make services-port SERVICE=#{service_name} PORT=#{db_port})")
32
+ expect(env_file).to include("DB_HOST=127.0.0.1")
33
+ expect(File.exist?("#{project_path}/Makefile")).to be true
34
+ expect(setup_file).to include("make services-up")
35
+ end
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potassium
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-07 00:00:00.000000000 Z
11
+ date: 2019-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.49.1
75
+ version: 0.65.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.49.1
82
+ version: 0.65.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -195,6 +195,7 @@ files:
195
195
  - lib/potassium/assets/.env.development.erb
196
196
  - lib/potassium/assets/.pryrc
197
197
  - lib/potassium/assets/Dockerfile.ci
198
+ - lib/potassium/assets/Makefile.erb
198
199
  - lib/potassium/assets/Procfile
199
200
  - lib/potassium/assets/README.md.erb
200
201
  - lib/potassium/assets/README.yml
@@ -221,6 +222,7 @@ files:
221
222
  - lib/potassium/assets/config/sentry.rb.erb
222
223
  - lib/potassium/assets/config/storage.yml
223
224
  - lib/potassium/assets/docker-compose.ci.yml
225
+ - lib/potassium/assets/docker-compose.yml
224
226
  - lib/potassium/assets/es-CL.yml
225
227
  - lib/potassium/assets/lib/tasks/auto_annotate_models.rake
226
228
  - lib/potassium/assets/package.json
@@ -266,6 +268,7 @@ files:
266
268
  - lib/potassium/recipes/ci.rb
267
269
  - lib/potassium/recipes/cleanup.rb
268
270
  - lib/potassium/recipes/database.rb
271
+ - lib/potassium/recipes/database_container.rb
269
272
  - lib/potassium/recipes/devise.rb
270
273
  - lib/potassium/recipes/draper.rb
271
274
  - lib/potassium/recipes/editorconfig.rb
@@ -275,6 +278,7 @@ files:
275
278
  - lib/potassium/recipes/github.rb
276
279
  - lib/potassium/recipes/heroku.rb
277
280
  - lib/potassium/recipes/i18n.rb
281
+ - lib/potassium/recipes/listen.rb
278
282
  - lib/potassium/recipes/mailer.rb
279
283
  - lib/potassium/recipes/paperclip.rb
280
284
  - lib/potassium/recipes/power_types.rb
@@ -305,6 +309,7 @@ files:
305
309
  - spec/features/active_storage_spec.rb
306
310
  - spec/features/background_processor_spec.rb
307
311
  - spec/features/ci_spec.rb
312
+ - spec/features/database_container_spec.rb
308
313
  - spec/features/database_spec.rb
309
314
  - spec/features/draper_spec.rb
310
315
  - spec/features/error_reporting_spec.rb
@@ -339,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
339
344
  version: '0'
340
345
  requirements: []
341
346
  rubyforge_project:
342
- rubygems_version: 2.7.6
347
+ rubygems_version: 2.7.6.2
343
348
  signing_key:
344
349
  specification_version: 4
345
350
  summary: An application generator from Platanus
@@ -349,6 +354,7 @@ test_files:
349
354
  - spec/features/active_storage_spec.rb
350
355
  - spec/features/background_processor_spec.rb
351
356
  - spec/features/ci_spec.rb
357
+ - spec/features/database_container_spec.rb
352
358
  - spec/features/database_spec.rb
353
359
  - spec/features/draper_spec.rb
354
360
  - spec/features/error_reporting_spec.rb