containers 0.1.0 → 0.1.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/containers/cli.rb +10 -124
  3. data/lib/containers/commands/attach.rb +9 -0
  4. data/lib/containers/commands/bash.rb +9 -0
  5. data/lib/containers/commands/bundle.rb +9 -0
  6. data/lib/containers/commands/down.rb +8 -0
  7. data/lib/containers/commands/exec.rb +10 -0
  8. data/lib/containers/commands/inspect.rb +9 -0
  9. data/lib/containers/commands/list.rb +23 -0
  10. data/lib/containers/commands/rails.rb +9 -0
  11. data/lib/containers/commands/restart.rb +10 -0
  12. data/lib/containers/commands/start.rb +10 -0
  13. data/lib/containers/commands/stop.rb +10 -0
  14. data/lib/containers/commands/tail.rb +10 -0
  15. data/lib/containers/commands/up.rb +8 -0
  16. data/lib/containers/commands/yarn.rb +9 -0
  17. data/lib/containers/concerns/commandable.rb +19 -0
  18. data/lib/containers/concerns/configurable.rb +37 -0
  19. data/lib/containers/generator/cli.rb +43 -0
  20. data/lib/containers/generator/commands/compose.rb +39 -0
  21. data/lib/containers/generator/commands/config.rb +29 -0
  22. data/lib/containers/generator/commands/dockerfile.rb +36 -0
  23. data/lib/containers/{templates → generator/templates}/Dockerfile.erb +0 -0
  24. data/lib/containers/generator/templates/containers.yml.erb +5 -0
  25. data/lib/containers/{templates → generator/templates}/docker-compose.yml.erb +5 -22
  26. data/lib/containers/{templates/redis-cache.conf → generator/templates/redis/cache.conf} +0 -0
  27. data/lib/containers/{templates/redis-queue.conf → generator/templates/redis/queue.conf} +0 -0
  28. data/lib/containers/version.rb +1 -1
  29. data/lib/containers.rb +0 -4
  30. metadata +46 -31
  31. data/Gemfile +0 -9
  32. data/Gemfile.lock +0 -106
  33. data/LICENSE.txt +0 -21
  34. data/README.md +0 -24
  35. data/Rakefile +0 -12
  36. data/containers.gemspec +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10eb220c07fba010dcc7f06bfbece1feef00f33f7521ea6c64422e0158d5f4b2
4
- data.tar.gz: fc61199216e1aa3fe368d5a26b98b775a31cf3ac0a6723fae29c25d0fe5f9912
3
+ metadata.gz: 693d21d25089049c59a5c47070a22ae26416d248bff32641c98f6dcce47cb9d8
4
+ data.tar.gz: 3815ca80c36f79de060019e99006674718377cba79048893af0da7eea03088e1
5
5
  SHA512:
6
- metadata.gz: 9d597a36e082a8d692de221f41e60d07a38bb509cf08e56d47123178ee680bd46af86f8981b57aef772772a4da587976c5894da36f943127ec5b259d50cd6d07
7
- data.tar.gz: 50dc68c00349412c3f74a799a0c47b054dea7cdd8d078a9c87987a3d79b2f84d42fbd6540414ccb00b5757b6bfcea09ccce1dd09b688b8769e473fbca4d1f040
6
+ metadata.gz: cbbd93da6bda8bcf772dcf5679048bf4282bc0a3d2b9a3c6d0251e4f9a154d9e415a78b7ef6abfa689502eacd3fe5571c8ce5997404c2220e60721aa3f6da391
7
+ data.tar.gz: 66a9a386d8e52f19814a43a014fdcdbf8ea8c33c1a305f7048bfbc5a84a5b57696173690fd67ce1c6333575b8c56bd26a236b1e810f96297b26cbee5d78b20fb
@@ -1,141 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pry-byebug"
3
4
  require "thor"
4
5
  require "rainbow"
5
- require_relative "./generator"
6
+ require "active_support/all"
7
+ require_relative "concerns/commandable"
8
+ require_relative "concerns/configurable"
9
+ require_relative "generator/cli"
6
10
 
7
11
  module Containers
8
12
  class CLI < Thor
9
- COMMAND_PREFIX = "▶"
13
+ include Commandable
14
+ include Configurable
10
15
 
11
- alias_method :execute, :exec
16
+ Dir["commands/**/*.rb", base: __dir__].each { |f| require_relative f }
12
17
 
13
18
  desc "generate", "Commands used to generate files for the project"
14
- subcommand "generate", Generator
19
+ subcommand "generate", Generator::CLI
15
20
 
16
- desc "up", "Brings up the environment defined in docker-compose.yml"
17
- def up(*args)
18
- execute_command "docker compose up -d #{args.join " "}"
19
- end
20
-
21
- desc "down", "Tears down the environment defined in docker-compose.yml"
22
- def down(*args)
23
- execute_command "docker compose down #{args.join " "}"
24
- end
25
-
26
- desc "list", "Lists all containers for this project"
27
- method_option :detailed, type: :boolean, aliases: "-d", desc: "List detailed container information"
28
- method_option :service, type: :boolean, aliases: "-s", desc: "List container service names"
29
- def list(*args)
30
- return execute_command "docker ps -a | grep #{project_name}" if options[:detailed]
31
-
32
- if options[:service]
33
- command = "containers list -f"
34
- puts_command "#{command} | #{Rainbow("(strip project name)").green.faint}"
35
- list = `#{command}`.split("\n").reject { |item| item.strip == "" || item.include?(COMMAND_PREFIX) }
36
- puts list.map { |item| item.gsub(/\A#{project_name}-|\s/, "") }.sort.join("\n")
37
- return
38
- end
39
-
40
- command = "containers list -d"
41
- puts_command "#{command} | #{Rainbow("(strip docker details)").green.faint}"
42
- list = `#{command}`.split("\n").reject { |item| item.strip == "" || item.include?(COMMAND_PREFIX) }
43
- puts list.map { |item| item.split(" ").last.strip }.sort.join("\n")
44
- end
45
-
46
- desc "inspect", "Inspects a container"
47
- method_option :container, type: :string, aliases: "-c", required: true, desc: "The short name for the container"
48
- def inspect(*args)
49
- execute_command "docker inspect #{args.join " "} #{project_name}-#{options[:container]}"
50
- end
51
-
52
- desc "attach", "Attaches to a running container"
53
- method_option :container, type: :string, aliases: "-c", required: true, desc: "The short name for the container"
54
- def attach(*args)
55
- execute_command "docker attach #{project_name}-#{options[:container]} #{args.join " "}"
56
- end
57
-
58
- desc "exec", "Executes a command in a container"
59
- method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
60
- def exec(*args)
61
- options[:container] = "shell" if options[:container].to_s.strip == ""
62
- execute_command "docker exec -it #{project_name}-#{options[:container]} #{args.join " "}"
63
- end
64
-
65
- desc "tail", "Tails container logs"
66
- method_option :container, type: :array, aliases: "-c", required: true, desc: "The short name for the container (also supports a list of names)"
67
- def tail(*args)
68
- args << "--since 5m" unless args.include?("--since")
69
- execute_command "docker compose logs #{args.join " "} -f #{options[:container].join " "}"
70
- end
71
-
72
- desc "start", "Starts container(s)"
73
- method_option :container, type: :string, aliases: "-c", desc: "The short name for the container"
74
- def start(*args)
75
- return execute_command "docker start #{args.join " "} #{project_name}-#{options[:container]}" if options[:container]
76
- container_names.each { |c| execute_command "docker start #{args.join " "} #{c}", replace_current_process: false }
77
- end
78
-
79
- desc "stop", "Stops container(s)"
80
- method_option :container, type: :string, aliases: "-c", desc: "The short name for the container"
81
- def stop(*args)
82
- return execute_command "docker stop #{args.join " "} #{project_name}-#{options[:container]}" if options[:container]
83
- container_names.each { |c| execute_command "docker stop #{args.join " "} #{c}", replace_current_process: false }
84
- end
85
-
86
- desc "restart", "Restarts container(s)"
87
- method_option :container, type: :array, aliases: "-c", desc: "A list of container short names"
88
- def restart(*args)
89
- containers = options[:container] || container_names
90
- containers.each { |c| execute_command "docker restart #{args.join " "} #{c}", replace_current_process: false }
91
- end
92
-
93
- desc "bash", "Starts a bash shell"
94
- method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
95
- def bash(*args)
96
- execute_command "containers exec -c #{options[:container]} bash #{args.join " "}"
97
- end
98
-
99
- desc "bundle", "Runs the bundle command"
100
- method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
101
- def bundle(*args)
102
- execute_command "containers exec -c #{options[:container]} bundle #{args.join " "}"
103
- end
104
-
105
- desc "yarn", "Runs the yarn command"
106
- method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
107
- def yarn(*args)
108
- execute_command "containers exec -c #{options[:container]} yarn #{args.join " "}"
109
- end
110
-
111
- desc "rails", "Runs the Rails command"
112
- method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
113
- def rails(*args)
114
- execute_command "containers bundle -c #{options[:container]} exec rails #{args.join " "}"
115
- end
116
-
117
- private
21
+ protected
118
22
 
119
23
  def container_names
120
24
  `containers list -f`.split("\n")
121
25
  end
122
-
123
- def project_name
124
- squish(File.basename(Dir.pwd)).gsub(/\s|_/, "-")
125
- end
126
-
127
- def squish(string)
128
- string.gsub(/\s+/, " ").strip
129
- end
130
-
131
- def execute_command(command, replace_current_process: true)
132
- command = squish(command)
133
- puts_command command
134
- replace_current_process ? execute(command) : puts(`#{command}`)
135
- end
136
-
137
- def puts_command(command)
138
- puts "#{Rainbow(COMMAND_PREFIX).green.faint} #{Rainbow(command).green.bright}"
139
- end
140
26
  end
141
27
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "attach", "Attaches to a running container"
5
+ method_option :container, type: :string, aliases: "-c", required: true, desc: "The short name for the container"
6
+ def attach(*args)
7
+ execute_command "docker attach #{project_name}-#{options[:container]} #{args.join " "}"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "bash", "Starts a bash shell"
5
+ method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
6
+ def bash(*args)
7
+ execute_command "containers exec -c #{options[:container]} bash #{args.join " "}"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "bundle", "Runs the bundle command"
5
+ method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
6
+ def bundle(*args)
7
+ execute_command "containers exec -c #{options[:container]} bundle #{args.join " "}"
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "down", "Tears down the environment defined in docker-compose.yml"
5
+ def down(*args)
6
+ execute_command "docker compose down #{args.join " "}"
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "exec", "Executes a command in a container"
5
+ method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
6
+ def exec(*args)
7
+ options[:container] = "shell" if options[:container].to_s.strip == ""
8
+ execute_command "docker exec -it #{project_name}-#{options[:container]} #{args.join " "}"
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "inspect", "Inspects a container"
5
+ method_option :container, type: :string, aliases: "-c", required: true, desc: "The short name for the container"
6
+ def inspect(*args)
7
+ execute_command "docker inspect #{args.join " "} #{project_name}-#{options[:container]}"
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "list", "Lists all containers for this project"
5
+ method_option :detailed, type: :boolean, aliases: "-d", desc: "List detailed container information"
6
+ method_option :service, type: :boolean, aliases: "-s", desc: "List container service names"
7
+ def list(*args)
8
+ return execute_command "docker ps -a | grep #{project_name}" if options[:detailed]
9
+
10
+ if options[:service]
11
+ command = "containers list -f"
12
+ puts_command "#{command} | #{Rainbow("(strip project name)").green.faint}"
13
+ list = `#{command}`.split("\n").reject { |item| item.strip == "" || item.include?(PREFIX) }
14
+ puts list.map { |item| item.gsub(/\A#{project_name}-|\s/, "") }.sort.join("\n")
15
+ return
16
+ end
17
+
18
+ command = "containers list -d"
19
+ puts_command "#{command} | #{Rainbow("(strip docker details)").green.faint}"
20
+ list = `#{command}`.split("\n").reject { |item| item.strip == "" || item.include?(PREFIX) }
21
+ puts list.map { |item| item.split(" ").last.strip }.sort.join("\n")
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "rails", "Runs the Rails command"
5
+ method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
6
+ def rails(*args)
7
+ execute_command "containers bundle -c #{options[:container]} exec rails #{args.join " "}"
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "restart", "Restarts container(s)"
5
+ method_option :container, type: :array, aliases: "-c", desc: "A list of container short names"
6
+ def restart(*args)
7
+ containers = options[:container] || container_names
8
+ containers.each { |c| execute_command "docker restart #{args.join " "} #{c}", replace_current_process: false }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "start", "Starts container(s)"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The short name for the container"
6
+ def start(*args)
7
+ return execute_command "docker start #{args.join " "} #{project_name}-#{options[:container]}" if options[:container]
8
+ container_names.each { |c| execute_command "docker start #{args.join " "} #{c}", replace_current_process: false }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "stop", "Stops container(s)"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The short name for the container"
6
+ def stop(*args)
7
+ return execute_command "docker stop #{args.join " "} #{project_name}-#{options[:container]}" if options[:container]
8
+ container_names.each { |c| execute_command "docker stop #{args.join " "} #{c}", replace_current_process: false }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "tail", "Tails container logs"
5
+ method_option :container, type: :array, aliases: "-c", required: true, desc: "The short name for the container (also supports a list of names)"
6
+ def tail(*args)
7
+ args << "--since 5m" unless args.include?("--since")
8
+ execute_command "docker compose logs #{args.join " "} -f #{options[:container].join " "}"
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "up", "Brings up the environment defined in docker-compose.yml"
5
+ def up(*args)
6
+ execute_command "docker compose up -d #{args.join " "}"
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "yarn", "Runs the yarn command"
5
+ method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
6
+ def yarn(*args)
7
+ execute_command "containers exec -c #{options[:container]} yarn #{args.join " "}"
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Containers::Commandable
4
+ extend ActiveSupport::Concern
5
+
6
+ PREFIX = "▶"
7
+
8
+ alias_method :execute, :exec
9
+
10
+ def puts_command(command)
11
+ puts "#{Rainbow(PREFIX).green.faint} #{Rainbow(command).green.bright}"
12
+ end
13
+
14
+ def execute_command(command, replace_current_process: true)
15
+ command = command.squish
16
+ puts_command command
17
+ replace_current_process ? execute(command) : puts(`#{command}`)
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Containers::Configurable
4
+ extend ActiveSupport::Concern
5
+
6
+ DEFAULT_CONFIGURATION = {
7
+ "organization_name" => "example-organization",
8
+ "project_name" => File.basename(Dir.pwd).parameterize,
9
+ "app_directory" => ".",
10
+ "docker_directory" => "."
11
+ }.freeze
12
+
13
+ def organization_name
14
+ configuration["organization_name"]
15
+ end
16
+
17
+ def project_name
18
+ configuration["project_name"]
19
+ end
20
+
21
+ def app_directory
22
+ configuration["app_directory"]
23
+ end
24
+
25
+ def docker_directory
26
+ configuration["docker_directory"]
27
+ end
28
+
29
+ def configuration
30
+ @configuration ||=
31
+ if File.exist?(".containers.yml")
32
+ YAML.load_file(".containers.yml")
33
+ else
34
+ DEFAULT_CONFIGURATION
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module Containers::Generator
8
+ class CLI < Thor
9
+ include Containers::Commandable
10
+ Dir["commands/**/*.rb", base: __dir__].each { |f| require_relative f }
11
+
12
+ protected
13
+
14
+ def template_path(template_name)
15
+ Pathname.new(__dir__).join "templates/#{template_name}.erb"
16
+ end
17
+
18
+ def raw_template(template_name)
19
+ File.read template_path(template_name)
20
+ end
21
+
22
+ def erb_template(template_name)
23
+ ERB.new raw_template(template_name)
24
+ end
25
+
26
+ def render_template(template_name, vars = {})
27
+ view = Struct.new(*vars.keys).new(*vars.values).instance_eval { binding }
28
+ erb_template(template_name).result view
29
+ end
30
+
31
+ def render_external_template(template, vars = {})
32
+ view = Struct.new(*vars.keys).new(*vars.values).instance_eval { binding }
33
+
34
+ raw_template = if template.start_with?("http")
35
+ Net::HTTP.get URI.parse(template)
36
+ else
37
+ File.read template
38
+ end
39
+
40
+ ERB.new(raw_template).result view
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require_relative "../../concerns/configurable"
5
+
6
+ class Containers::Generator::CLI < Thor
7
+ include ::Containers::Configurable
8
+
9
+ desc "compose", "Creates a docker-compose.yml file for the project"
10
+ method_option :template, type: :string, aliases: "-t", desc: "The docker-compose.yml template to use (can be a local file or a URL)"
11
+ def compose
12
+ FileUtils.mkdir_p docker_directory
13
+ path = File.expand_path("#{docker_directory}/docker-compose.yml")
14
+
15
+ continue = if File.exist?(path)
16
+ ask("#{Rainbow("docker-compose.yml already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
17
+ else
18
+ true
19
+ end
20
+
21
+ return unless continue
22
+
23
+ vars = {
24
+ organization_name: ask("What is the organization name? (lowercase, dasherized)", default: organization_name).to_s,
25
+ project_name: ask("What is the project name? (lowercase, dasherized)", default: project_name).to_s,
26
+ app_directory: File.expand_path(ask("What is the application directory? ", default: app_directory).to_s)
27
+ }
28
+
29
+ contents = if options[:template]
30
+ render_external_template options[:template], vars
31
+ else
32
+ render_template "docker-compose.yml", vars
33
+ end
34
+
35
+ puts_command Rainbow("(Create #{path})").green.faint
36
+ File.write path, contents
37
+ puts Rainbow("docker-compose.yml created successfully").green.bright
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../concerns/configurable"
4
+
5
+ class Containers::Generator::CLI < Thor
6
+ include ::Containers::Configurable
7
+
8
+ desc "config", "Creates a .containers.yml config file for the project"
9
+ def config
10
+ path = File.expand_path(".containers.yml")
11
+
12
+ continue = if File.exist?(path)
13
+ ask("#{Rainbow(".containers.yml already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
14
+ else
15
+ true
16
+ end
17
+
18
+ return unless continue
19
+
20
+ vars = {
21
+ organization_name: ask("What is the organization name? (lowercase, dasherized)", default: organization_name).to_s,
22
+ project_name: ask("What is the project name? (lowercase, dasherized)", default: project_name).to_s,
23
+ app_directory: File.expand_path(ask("What is the application directory? ", default: app_directory).to_s),
24
+ docker_directory: File.expand_path(ask("What is the docker directory? ", default: docker_directory).to_s)
25
+ }
26
+
27
+ File.write path, render_template("containers.yml", vars)
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require_relative "../../concerns/configurable"
5
+
6
+ class Containers::Generator::CLI < Thor
7
+ include ::Containers::Configurable
8
+
9
+ desc "dockerfile", "Creates a Dockerfile for the project"
10
+ method_option :template, type: :string, aliases: "-t", desc: "The Dockerfile template to use (can be a local file or a URL)"
11
+ def dockerfile
12
+ FileUtils.mkdir_p docker_directory
13
+ path = File.expand_path("#{docker_directory}/Dockerfile")
14
+
15
+ continue = if File.exist?(path)
16
+ ask("#{Rainbow("Dockerfile already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
17
+ else
18
+ true
19
+ end
20
+
21
+ return unless continue
22
+
23
+ ruby_version = ask("What Ruby version does this project use?", default: "3.1.2").to_s
24
+ vars = {ruby_version: ruby_version}
25
+
26
+ contents = if options[:template]
27
+ render_external_template options[:template], vars
28
+ else
29
+ render_template "Dockerfile", vars
30
+ end
31
+
32
+ puts_command Rainbow("(Create #{path})").green.faint
33
+ File.write path, contents
34
+ puts Rainbow("Dockerfile created successfully").green.bright
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ ---
2
+ organization_name: <%= organization_name %>
3
+ project_name: <%= project_name %>
4
+ app_directory: <%= app_directory %>
5
+ docker_directory: <%= docker_directory %>
@@ -18,19 +18,14 @@ x-default-app: &default_app
18
18
  working_dir: /<%= project_name %>
19
19
  tty: true
20
20
  stdin_open: true
21
- env_file: .env
21
+ env_file: <%= File.join app_directory, ".env" %>
22
22
  environment:
23
23
  <<: *default_env
24
- networks:
25
- - main
26
24
  volumes:
27
- - ./:/<%= project_name %>:cached
25
+ - <%= app_directory %>:/<%= project_name %>:cached
28
26
  - bundle:/bundle:delegated
29
27
  - node_modules:/<%= project_name %>/node_modules:delegated
30
28
 
31
- networks:
32
- main:
33
-
34
29
  # TODO: dump pg database then rename db -> postgres
35
30
  volumes:
36
31
  bundle:
@@ -50,8 +45,6 @@ services:
50
45
  restart: unless-stopped
51
46
  environment:
52
47
  POSTGRES_PASSWORD: password
53
- networks:
54
- - main
55
48
  expose:
56
49
  - 5432
57
50
  volumes:
@@ -64,13 +57,11 @@ services:
64
57
  image: redis:6.2.6-alpine3.14
65
58
  container_name: <%= project_name %>-redis-cable
66
59
  restart: unless-stopped
67
- networks:
68
- - main
69
60
  expose:
70
61
  - 6379
71
62
  volumes:
72
63
  - redis_cable:/data:delegated
73
- - ./config/redis-queue.conf:/usr/local/etc/redis/redis.conf:cached
64
+ - <%= File.expand_path File.join(File.dirname(__FILE__), "redis/queue.conf") %>:/usr/local/etc/redis/redis.conf:cached
74
65
 
75
66
  # ----------------------------------------------------------------------------
76
67
  # Redis - Cache datastore
@@ -79,13 +70,11 @@ services:
79
70
  image: redis:6.2.6-alpine3.14
80
71
  container_name: <%= project_name %>-redis-cache
81
72
  restart: unless-stopped
82
- networks:
83
- - main
84
73
  expose:
85
74
  - 6379
86
75
  volumes:
87
76
  - redis_cache:/data:delegated
88
- - ./config/redis-cache.conf:/usr/local/etc/redis/redis.conf:cached
77
+ - <%= File.expand_path File.join(File.dirname(__FILE__), "redis/cache.conf") %>:/usr/local/etc/redis/redis.conf:cached
89
78
 
90
79
  # ----------------------------------------------------------------------------
91
80
  # Redis - Queue datastore
@@ -94,13 +83,11 @@ services:
94
83
  image: redis:6.2.6-alpine3.14
95
84
  container_name: <%= project_name %>-redis-queue
96
85
  restart: unless-stopped
97
- networks:
98
- - main
99
86
  expose:
100
87
  - 6379
101
88
  volumes:
102
89
  - redis_queue:/data:delegated
103
- - ./config/redis-queue.conf:/usr/local/etc/redis/redis.conf:cached
90
+ - <%= File.expand_path File.join(File.dirname(__FILE__), "redis/queue.conf") %>:/usr/local/etc/redis/redis.conf:cached
104
91
 
105
92
  # ----------------------------------------------------------------------------
106
93
  # Shell - Intended for tinkering and running misc commands
@@ -176,8 +163,6 @@ services:
176
163
  ANYCABLE_REDIS_URL: redis://redis_cable:6379/0
177
164
  ANYCABLE_RPC_HOST: anycable_rpc:50051
178
165
  ANYCABLE_DEBUG: 1
179
- networks:
180
- - main
181
166
  ports:
182
167
  - ${PORT_ANYCABLE:-3001}:8080
183
168
  depends_on:
@@ -195,8 +180,6 @@ services:
195
180
  ANYCABLE_REDIS_URL: redis://redis_cable:6379/0
196
181
  ANYCABLE_RPC_HOST: 0.0.0.0:50051
197
182
  ANYCABLE_DEBUG: 1
198
- networks:
199
- - main
200
183
  command: /bin/bash -c "bundle exec anycable"
201
184
  depends_on:
202
185
  - anycable_ws
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Containers
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/containers.rb CHANGED
@@ -1,8 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thor"
4
3
  require_relative "containers/version"
5
4
  require_relative "containers/cli"
6
-
7
- module Containers
8
- end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: containers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hopsoft
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-03 00:00:00.000000000 Z
11
+ date: 2022-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.1
19
+ version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.1
26
+ version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.1
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.1
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: github_changelog_generator
42
+ name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.16.4
48
- type: :development
47
+ version: '6.0'
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.16.4
54
+ version: '6.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: ruby_jard
56
+ name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.3.1
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.3.1
68
+ version: '0'
69
69
  description: Manage local development environments with Docker
70
70
  email:
71
71
  - natehop@gmail.com
@@ -74,20 +74,35 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - Gemfile
78
- - Gemfile.lock
79
- - LICENSE.txt
80
- - README.md
81
- - Rakefile
82
- - containers.gemspec
83
77
  - exe/containers
84
78
  - lib/containers.rb
85
79
  - lib/containers/cli.rb
80
+ - lib/containers/commands/attach.rb
81
+ - lib/containers/commands/bash.rb
82
+ - lib/containers/commands/bundle.rb
83
+ - lib/containers/commands/down.rb
84
+ - lib/containers/commands/exec.rb
85
+ - lib/containers/commands/inspect.rb
86
+ - lib/containers/commands/list.rb
87
+ - lib/containers/commands/rails.rb
88
+ - lib/containers/commands/restart.rb
89
+ - lib/containers/commands/start.rb
90
+ - lib/containers/commands/stop.rb
91
+ - lib/containers/commands/tail.rb
92
+ - lib/containers/commands/up.rb
93
+ - lib/containers/commands/yarn.rb
94
+ - lib/containers/concerns/commandable.rb
95
+ - lib/containers/concerns/configurable.rb
86
96
  - lib/containers/generator.rb
87
- - lib/containers/templates/Dockerfile.erb
88
- - lib/containers/templates/docker-compose.yml.erb
89
- - lib/containers/templates/redis-cache.conf
90
- - lib/containers/templates/redis-queue.conf
97
+ - lib/containers/generator/cli.rb
98
+ - lib/containers/generator/commands/compose.rb
99
+ - lib/containers/generator/commands/config.rb
100
+ - lib/containers/generator/commands/dockerfile.rb
101
+ - lib/containers/generator/templates/Dockerfile.erb
102
+ - lib/containers/generator/templates/containers.yml.erb
103
+ - lib/containers/generator/templates/docker-compose.yml.erb
104
+ - lib/containers/generator/templates/redis/cache.conf
105
+ - lib/containers/generator/templates/redis/queue.conf
91
106
  - lib/containers/version.rb
92
107
  - sig/containers.rbs
93
108
  homepage: https://github.com/hopsoft/containers
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in containers.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
- gem "minitest", "~> 5.0"
data/Gemfile.lock DELETED
@@ -1,106 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- containers (0.1.0)
5
- rainbow (~> 3.1.1)
6
- thor (~> 1.2.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (7.0.3.1)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 1.6, < 2)
14
- minitest (>= 5.1)
15
- tzinfo (~> 2.0)
16
- addressable (2.8.0)
17
- public_suffix (>= 2.0.2, < 5.0)
18
- async (2.0.3)
19
- console (~> 1.10)
20
- io-event (~> 1.0.0)
21
- timers (~> 4.1)
22
- async-http (0.56.6)
23
- async (>= 1.25)
24
- async-io (>= 1.28)
25
- async-pool (>= 0.2)
26
- protocol-http (~> 0.22.0)
27
- protocol-http1 (~> 0.14.0)
28
- protocol-http2 (~> 0.14.0)
29
- traces (~> 0.4.0)
30
- async-http-faraday (0.11.0)
31
- async-http (~> 0.42)
32
- faraday
33
- async-io (1.33.0)
34
- async
35
- async-pool (0.3.10)
36
- async (>= 1.25)
37
- byebug (11.1.3)
38
- coderay (1.1.3)
39
- concurrent-ruby (1.1.10)
40
- console (1.15.3)
41
- fiber-local
42
- faraday (2.3.0)
43
- faraday-net_http (~> 2.0)
44
- ruby2_keywords (>= 0.0.4)
45
- faraday-http-cache (2.4.0)
46
- faraday (>= 0.8)
47
- faraday-net_http (2.0.3)
48
- fiber-local (1.0.0)
49
- github_changelog_generator (1.16.4)
50
- activesupport
51
- async (>= 1.25.0)
52
- async-http-faraday
53
- faraday-http-cache
54
- multi_json
55
- octokit (~> 4.6)
56
- rainbow (>= 2.2.1)
57
- rake (>= 10.0)
58
- i18n (1.12.0)
59
- concurrent-ruby (~> 1.0)
60
- io-event (1.0.9)
61
- method_source (1.0.0)
62
- minitest (5.16.2)
63
- multi_json (1.15.0)
64
- octokit (4.25.1)
65
- faraday (>= 1, < 3)
66
- sawyer (~> 0.9)
67
- protocol-hpack (1.4.2)
68
- protocol-http (0.22.6)
69
- protocol-http1 (0.14.4)
70
- protocol-http (~> 0.22)
71
- protocol-http2 (0.14.2)
72
- protocol-hpack (~> 1.4)
73
- protocol-http (~> 0.18)
74
- pry (0.13.1)
75
- coderay (~> 1.1)
76
- method_source (~> 1.0)
77
- public_suffix (4.0.7)
78
- rainbow (3.1.1)
79
- rake (13.0.6)
80
- ruby2_keywords (0.0.5)
81
- ruby_jard (0.3.1)
82
- byebug (>= 9.1, < 12.0)
83
- pry (~> 0.13.0)
84
- tty-screen (~> 0.8.1)
85
- sawyer (0.9.2)
86
- addressable (>= 2.3.5)
87
- faraday (>= 0.17.3, < 3)
88
- thor (1.2.1)
89
- timers (4.3.3)
90
- traces (0.4.1)
91
- tty-screen (0.8.1)
92
- tzinfo (2.0.5)
93
- concurrent-ruby (~> 1.0)
94
-
95
- PLATFORMS
96
- arm64-darwin-21
97
-
98
- DEPENDENCIES
99
- containers!
100
- github_changelog_generator (~> 1.16.4)
101
- minitest (~> 5.0)
102
- rake (~> 13.0)
103
- ruby_jard (~> 0.3.1)
104
-
105
- BUNDLED WITH
106
- 2.3.17
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2022 Hopsoft
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,24 +0,0 @@
1
- # Containers
2
-
3
- ## TODOs
4
-
5
- ### Questions to prompt on generate
6
-
7
- - [ ] container logging?
8
- - [ ] admin tooling?
9
-
10
- #### Punt on these for now
11
-
12
- ```
13
- containers generate compose
14
- containers add anycable
15
- containers remove anycable
16
- ```
17
-
18
- - [ ] sinatra?
19
- - [ ] rails?
20
- - [ ] anycable?
21
- - [ ] actioncable?
22
- - [ ] caching? (redis)
23
- - [ ] background jobs?
24
- - [ ] backend? (sidekiq, ...)
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
10
- end
11
-
12
- task default: :test
data/containers.gemspec DELETED
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/containers/version"
4
-
5
- Gem::Specification.new do |gem|
6
- gem.name = "containers"
7
- gem.version = Containers::VERSION
8
- gem.authors = ["Hopsoft"]
9
- gem.email = ["natehop@gmail.com"]
10
-
11
- gem.summary = "Manage local development environments with Docker"
12
- gem.description = "Manage local development environments with Docker"
13
- gem.homepage = "https://github.com/hopsoft/containers"
14
- gem.license = "MIT"
15
- gem.required_ruby_version = ">= 2.6.0"
16
-
17
- # gem.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- gem.metadata["homepage_uri"] = gem.homepage
20
- gem.metadata["source_code_uri"] = gem.homepage
21
- gem.metadata["changelog_uri"] = "#{gem.homepage}/CHANGELOG.md"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- gem.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- gem.bindir = "exe"
31
- gem.executables = gem.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- gem.require_paths = ["lib"]
33
-
34
- gem.add_dependency "rainbow", "~> 3.1.1"
35
- gem.add_dependency "thor", "~> 1.2.1"
36
-
37
- gem.add_development_dependency "github_changelog_generator", "~> 1.16.4"
38
- gem.add_development_dependency "ruby_jard", "~> 0.3.1"
39
-
40
- # For more information and examples about making a new gem, check out our
41
- # guide at: https://bundler.io/guides/creating_gem.html
42
- end