docker-postgres-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 712c0d4de2be2bceb2bea99fb4fa89795848f85a84a7d6662f53c3eccbccc9ae
4
+ data.tar.gz: 1434fdab742f24591597deb0db4340a478bf288d2f66109810c6571c4df0849a
5
+ SHA512:
6
+ metadata.gz: c9dff1c216f0707a41da32730de7476ee745e00823b4a12bf64b09e0fb886de48cbc471d9b19f054c77c52a27053a6dc15c4da8205f23fd719c1199c181f052c
7
+ data.tar.gz: a160c8b256e8f34491a5aee18fb11073bd701c7d9b8f4b51e2ee908924e268464b3be6bcf99fdc94be7d0a828f69c57d9b92c334bf596e2f2fd262eaacb09f2d
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # README
2
+ We always need easy and fast database env setting for rails
3
+ docker-postgres gem builded for develop database enviroment
4
+
5
+ ### Require
6
+ * macOS or linux (Not support window, using mkdir)
7
+ * Installed Docker
8
+ * database.yml in rails project (needed database, username, password, port)
9
+
10
+ # Install
11
+ ### Install in Gemfile
12
+ Gemfile
13
+ ```yaml
14
+ gem 'docker-postgres-rails', :git => "git://github.com/x1wins/docker-postgres-rails.git"
15
+ ```
16
+
17
+ ### Or Source download and gem build
18
+ ```bash
19
+ $ gem build docker-postgres-rails.gemspec
20
+ Successfully built RubyGem
21
+ Name: docker-postgres-rails
22
+ Version: 0.0.0
23
+ File: docker-postgres-rails-0.0.0.gem
24
+ ```
25
+ ```bash
26
+ $ gem install docker-postgres-rails
27
+ Successfully installed docker-postgres-rails-0.0.0
28
+ Parsing documentation for docker-postgres-rails-0.0.0
29
+ Done installing documentation for docker-postgres-rails after 0 seconds
30
+ 1 gem installed
31
+ ```
32
+ Added docker-postgres-rails in Gemfile
33
+ ```yaml
34
+ gem 'docker-postgres-rails'
35
+ ```
36
+
37
+ Uninstall gem
38
+ ```bash
39
+ $ gem uninstall docker-postgres-rails
40
+ Successfully uninstalled docker-postgres-rails-0.0.0
41
+ ```
42
+
43
+ # Usage
44
+ ### Step 0
45
+ ```bash
46
+ rails generate docker_pg
47
+ This will create:
48
+ lib/tasks/docker_pg.rake
49
+ ```
50
+
51
+ ### Step 1
52
+ You must set database.yml
53
+ ```yaml
54
+ default: &default
55
+ adapter: postgresql
56
+ encoding: unicode
57
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
58
+
59
+ development:
60
+ <<: *default
61
+ database: docker_postgres_rails_development
62
+ username: docker_postgres_rails
63
+ password: mysecretpassword
64
+ host: localhost
65
+ port: 5432
66
+
67
+ test:
68
+ <<: *default
69
+ database: docker_postgres_rails_test
70
+
71
+ production:
72
+ <<: *default
73
+ database: docker_postgres_rails_production
74
+ username: docker_postgres_rails
75
+ password: <%= ENV['DOCKER_POSTGRES_RAILS_DATABASE_PASSWORD'] %>
76
+ ```
77
+
78
+ ### Step 2
79
+ This command create database volume path
80
+ ```bash
81
+ $ rake docker:pg:init
82
+ ```
83
+
84
+ ### Step 3
85
+ Runing dockerized PostgreSQL
86
+ ```bash
87
+ $ rake docker:pg:run
88
+ ```
89
+ ```bash
90
+ $ docker ps
91
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92
+ 4ec621c7914b postgres "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 0.0.0.0:5432->5432/tcp docker_postgres_rails_development
93
+ ```
94
+
95
+ ## It's all
data/bin/bundle ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||=
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version
67
+ end
68
+
69
+ def bundler_requirement
70
+ return "#{Gem::Requirement.default}.a" unless bundler_version
71
+
72
+ bundler_gem_version = Gem::Version.new(bundler_version)
73
+
74
+ requirement = bundler_gem_version.approximate_recommendation
75
+
76
+ return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77
+
78
+ requirement += ".a" if bundler_gem_version.prerelease?
79
+
80
+ requirement
81
+ end
82
+
83
+ def load_bundler!
84
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
85
+
86
+ activate_bundler
87
+ end
88
+
89
+ def activate_bundler
90
+ gem_error = activation_error_handling do
91
+ gem "bundler", bundler_requirement
92
+ end
93
+ return if gem_error.nil?
94
+ require_error = activation_error_handling do
95
+ require "bundler/version"
96
+ end
97
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99
+ exit 42
100
+ end
101
+
102
+ def activation_error_handling
103
+ yield
104
+ nil
105
+ rescue StandardError, LoadError => e
106
+ e
107
+ end
108
+ end
109
+
110
+ m.load_bundler!
111
+
112
+ if m.invoked_as_script?
113
+ load Gem.bin_path("bundler", "bundle")
114
+ end
data/bin/rails ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ APP_PATH = File.expand_path('../config/application', __dir__)
8
+ require_relative '../config/boot'
9
+ require 'rails/commands'
data/bin/rake ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ require_relative '../config/boot'
8
+ require 'rake'
9
+ Rake.application.run
data/bin/setup ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
+
7
+ def system!(*args)
8
+ system(*args) || abort("\n== Command #{args} failed ==")
9
+ end
10
+
11
+ FileUtils.chdir APP_ROOT do
12
+ # This script is a way to setup or update your development environment automatically.
13
+ # This script is idempotent, so that you can run it at anytime and get an expectable outcome.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies
21
+ # system('bin/yarn')
22
+
23
+ # puts "\n== Copying sample files =="
24
+ # unless File.exist?('config/database.yml')
25
+ # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
26
+ # end
27
+
28
+ puts "\n== Preparing database =="
29
+ system! 'bin/rails db:prepare'
30
+
31
+ puts "\n== Removing old logs and tempfiles =="
32
+ system! 'bin/rails log:clear tmp:clear'
33
+
34
+ puts "\n== Restarting application server =="
35
+ system! 'bin/rails restart'
36
+ end
data/bin/spring ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads Spring without using Bundler, in order to be fast.
4
+ # It gets overwritten when you run the `spring binstub` command.
5
+
6
+ unless defined?(Spring)
7
+ require 'rubygems'
8
+ require 'bundler'
9
+
10
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11
+ spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
12
+ if spring
13
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14
+ gem 'spring', spring.version
15
+ require 'spring/binstub'
16
+ end
17
+ end
data/bin/webpack ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
+ ENV["NODE_ENV"] ||= "development"
5
+
6
+ require "pathname"
7
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
+ Pathname.new(__FILE__).realpath)
9
+
10
+ require "bundler/setup"
11
+
12
+ require "webpacker"
13
+ require "webpacker/webpack_runner"
14
+
15
+ APP_ROOT = File.expand_path("..", __dir__)
16
+ Dir.chdir(APP_ROOT) do
17
+ Webpacker::WebpackRunner.run(ARGV)
18
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
+ ENV["NODE_ENV"] ||= "development"
5
+
6
+ require "pathname"
7
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
+ Pathname.new(__FILE__).realpath)
9
+
10
+ require "bundler/setup"
11
+
12
+ require "webpacker"
13
+ require "webpacker/dev_server_runner"
14
+
15
+ APP_ROOT = File.expand_path("..", __dir__)
16
+ Dir.chdir(APP_ROOT) do
17
+ Webpacker::DevServerRunner.run(ARGV)
18
+ end
data/bin/yarn ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path('..', __dir__)
3
+ Dir.chdir(APP_ROOT) do
4
+ begin
5
+ exec "yarnpkg", *ARGV
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate docker_pg
6
+
7
+ This will create:
8
+ lib/tasks/docker_pg.rake
@@ -0,0 +1,7 @@
1
+ class DockerPgGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('templates', __dir__)
3
+
4
+ def copy_docker_pg_file
5
+ copy_file "docker_pg.rake", "lib/tasks/docker_pg.rake"
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ namespace :docker do
2
+ namespace :pg do
3
+ config = Rails.configuration.database_configuration
4
+ database = config[Rails.env]["database"]
5
+ username = config[Rails.env]["username"]
6
+ password = config[Rails.env]["password"]
7
+ port = config[Rails.env]["port"]
8
+ name = database
9
+ path = '$HOME/docker/volumes/' + name
10
+
11
+ desc "Craete Dockerized postgreSQL volume"
12
+ task init: :environment do
13
+ mkdir = "mkdir -p #{path}"
14
+ run_bash(mkdir)
15
+ run_bash("ls -la #{path}")
16
+ end
17
+
18
+ desc "Run Dockerized postgreSQL"
19
+ task run: :environment do
20
+ postgresql_cmd = """
21
+ [[ $(docker ps --filter \"name=^/#{name}\" --format '{{.Names}}') == #{name} ]] || \
22
+ docker run --rm --name #{name} \
23
+ -v #{path}:/var/lib/postgresql/data \
24
+ -e POSTGRES_DB=#{database} \
25
+ -e POSTGRES_USER=#{username} \
26
+ -e POSTGRES_PASSWORD=#{password} \
27
+ -p #{port}:5432 -d postgres
28
+ """
29
+ run_bash postgresql_cmd
30
+ end
31
+ end
32
+
33
+ def run_bash cmd
34
+ system("echo \"#{cmd}\"")
35
+ system("bash -c #{cmd.shellescape}")
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docker-postgres-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chang-Woo Rhee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ description: create volume, docker run Postgresql
28
+ email: x1wins@changwoo.net
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - bin/bundle
35
+ - bin/rails
36
+ - bin/rake
37
+ - bin/setup
38
+ - bin/spring
39
+ - bin/webpack
40
+ - bin/webpack-dev-server
41
+ - bin/yarn
42
+ - lib/generators/docker_pg/USAGE
43
+ - lib/generators/docker_pg/docker_pg_generator.rb
44
+ - lib/generators/docker_pg/templates/docker_pg.rake
45
+ homepage: https://github.com/x1wins/docker-postgres-rails
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.1.1
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Docker postgresql init, run with rails rake
68
+ test_files: []