containers 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 693d21d25089049c59a5c47070a22ae26416d248bff32641c98f6dcce47cb9d8
4
- data.tar.gz: 3815ca80c36f79de060019e99006674718377cba79048893af0da7eea03088e1
3
+ metadata.gz: cd15c1e87342149b417b3b8671d6a435badd75d2bed6c32d4ca81d5cdce6e5b8
4
+ data.tar.gz: 9066bc4c1a4890a9eea31c5d22d92ed812090ebdb3bc45dad76f130ae686ad7f
5
5
  SHA512:
6
- metadata.gz: cbbd93da6bda8bcf772dcf5679048bf4282bc0a3d2b9a3c6d0251e4f9a154d9e415a78b7ef6abfa689502eacd3fe5571c8ce5997404c2220e60721aa3f6da391
7
- data.tar.gz: 66a9a386d8e52f19814a43a014fdcdbf8ea8c33c1a305f7048bfbc5a84a5b57696173690fd67ce1c6333575b8c56bd26a236b1e810f96297b26cbee5d78b20fb
6
+ metadata.gz: 2f6d65ae82057568913304f231b84fa46671418d2e4119469b0e6691cc5937663b33cd06fc4787b5c7fabaffd4f364774fc49b4313a2a8aee71a38d7b4b1d9d0
7
+ data.tar.gz: 184d0fe60b715ec9e90c39520b54eba1045e13c2247c35ec849d885aa371d7cfcbd510a4c98d1ffaa4f011d3fd7b661b8225c71431f3a1e735218b38cde19840
data/exe/ctrs ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "containers"
4
+
5
+ Containers::CLI.start(ARGV)
@@ -20,8 +20,39 @@ module Containers
20
20
 
21
21
  protected
22
22
 
23
+ def container_name(service_name)
24
+ service_name ||= docker_default_service
25
+ return nil unless service_name
26
+ "#{app_name}-#{service_name}"
27
+ end
28
+
29
+ def service_name(container_name)
30
+ return nil unless container_name
31
+ container_name.sub(/\A#{app_name}-/, "")
32
+ end
33
+
34
+ def service_names
35
+ `containers list -s`.split("\n").reject do |line|
36
+ line.nil? || line.empty? || line.include?(Containers::Commandable::PREFIX)
37
+ end
38
+ end
39
+
23
40
  def container_names
24
- `containers list -f`.split("\n")
41
+ `containers list`.split("\n").reject do |line|
42
+ line.nil? || line.empty? || line.include?(Containers::Commandable::PREFIX)
43
+ end
44
+ end
45
+
46
+ def requested_container_names
47
+ return options[:container].compact if options[:container]
48
+ return requested_service_names.map { |name| container_name name }.compact if options[:service]
49
+ container_names
50
+ end
51
+
52
+ def requested_service_names
53
+ return options[:service].compact if options[:service]
54
+ return requested_container_names(options).map { |name| service_name name }.compact if options[:container]
55
+ service_names
25
56
  end
26
57
  end
27
58
  end
@@ -2,8 +2,10 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
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"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
6
7
  def attach(*args)
7
- execute_command "docker attach #{project_name}-#{options[:container]} #{args.join " "}"
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "docker attach #{container} #{args.join " "}"
8
10
  end
9
11
  end
@@ -2,8 +2,10 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
4
  desc "bash", "Starts a bash shell"
5
- method_option :container, type: :string, aliases: "-c", default: "shell", desc: "The short name for the container"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
6
7
  def bash(*args)
7
- execute_command "containers exec -c #{options[:container]} bash #{args.join " "}"
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "containers exec -c #{container} bash #{args.join " "}"
8
10
  end
9
11
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "bin", "Runs executables in the ./bin directory"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
7
+ def bin(*args)
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "containers exec -c #{container} bin/#{args.join " "}"
10
+ end
11
+ end
@@ -3,6 +3,6 @@
3
3
  class Containers::CLI < Thor
4
4
  desc "down", "Tears down the environment defined in docker-compose.yml"
5
5
  def down(*args)
6
- execute_command "docker compose down #{args.join " "}"
6
+ execute_command "docker compose #{docker_compose_files.map { |f| "-f #{f}" }.join " "} down #{args.join " "}"
7
7
  end
8
8
  end
@@ -2,9 +2,13 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
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"
5
+ long_desc "Also aliased as `x` for convenience"
6
+ method_option :container, type: :string, aliases: "-c", desc: "The container name"
7
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
6
8
  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
+ container = options[:container] || container_name(options[:service])
10
+ execute_command "docker exec -it #{container} #{args.join " "}"
9
11
  end
12
+
13
+ map x: :exec
10
14
  end
@@ -2,8 +2,10 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
4
  desc "inspect", "Inspects a container"
5
- method_option :container, type: :string, aliases: "-c", required: true, desc: "The short name for the container"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
6
7
  def inspect(*args)
7
- execute_command "docker inspect #{args.join " "} #{project_name}-#{options[:container]}"
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "docker inspect #{args.join " "} #{container}"
8
10
  end
9
11
  end
@@ -5,13 +5,13 @@ class Containers::CLI < Thor
5
5
  method_option :detailed, type: :boolean, aliases: "-d", desc: "List detailed container information"
6
6
  method_option :service, type: :boolean, aliases: "-s", desc: "List container service names"
7
7
  def list(*args)
8
- return execute_command "docker ps -a | grep #{project_name}" if options[:detailed]
8
+ return execute_command "docker ps -a | grep #{app_name}" if options[:detailed]
9
9
 
10
10
  if options[:service]
11
- command = "containers list -f"
12
- puts_command "#{command} | #{Rainbow("(strip project name)").green.faint}"
11
+ command = "containers list"
12
+ puts_command "#{command} | #{Rainbow("(strip app_name)").green.faint}"
13
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")
14
+ puts list.map { |item| item.gsub(/\A#{app_name}-|\s/, "") }.sort.join("\n")
15
15
  return
16
16
  end
17
17
 
@@ -0,0 +1,11 @@
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", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
7
+ def rails(*args)
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "containers bundle -c #{container} exec rails #{args.join " "}"
10
+ end
11
+ end
@@ -2,9 +2,11 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
4
  desc "restart", "Restarts container(s)"
5
- method_option :container, type: :array, aliases: "-c", desc: "A list of container short names"
5
+ method_option :container, type: :array, aliases: "-c", desc: "A list of container names (space delimited)"
6
+ method_option :service, type: :array, aliases: "-s", desc: "A list of service names (space delimited)"
6
7
  def restart(*args)
7
- containers = options[:container] || container_names
8
- containers.each { |c| execute_command "docker restart #{args.join " "} #{c}", replace_current_process: false }
8
+ requested_container_names.each do |container_name|
9
+ execute_command "docker restart #{args.join " "} #{container_name}", replace_current_process: false
10
+ end
9
11
  end
10
12
  end
@@ -0,0 +1,11 @@
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", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
7
+ def bundle(*args)
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "containers exec -c #{container} bundle #{args.join " "}"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Containers::CLI < Thor
4
+ desc "rake", "Runs ruby's rake command"
5
+ method_option :container, type: :string, aliases: "-c", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
7
+ def rake(*args)
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "containers exec -c #{container} rake #{args.join " "}"
10
+ end
11
+ end
@@ -2,9 +2,11 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
4
  desc "start", "Starts container(s)"
5
- method_option :container, type: :string, aliases: "-c", desc: "The short name for the container"
5
+ method_option :container, type: :array, aliases: "-c", desc: "A list of container names (space delimited)"
6
+ method_option :service, type: :array, aliases: "-s", desc: "A list of service names (space delimited)"
6
7
  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 }
8
+ requested_container_names.each do |container_name|
9
+ execute_command "docker start #{args.join " "} #{container_name}", replace_current_process: false
10
+ end
9
11
  end
10
12
  end
@@ -2,9 +2,11 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
4
  desc "stop", "Stops container(s)"
5
- method_option :container, type: :string, aliases: "-c", desc: "The short name for the container"
5
+ method_option :container, type: :array, aliases: "-c", desc: "A list of container names (space delimited)"
6
+ method_option :service, type: :array, aliases: "-s", desc: "A list of service names (space delimited)"
6
7
  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 }
8
+ requested_container_names.each do |container_name|
9
+ execute_command "docker stop #{args.join " "} #{container_name}", replace_current_process: false
10
+ end
9
11
  end
10
12
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  class Containers::CLI < Thor
4
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)"
5
+ method_option :container, type: :array, aliases: "-c", desc: "A list of container names (space delimited)"
6
+ method_option :service, type: :array, aliases: "-s", desc: "A list of service names (space delimited)"
6
7
  def tail(*args)
7
8
  args << "--since 5m" unless args.include?("--since")
8
- execute_command "docker compose logs #{args.join " "} -f #{options[:container].join " "}"
9
+ execute_command "docker compose #{docker_compose_files.map { |f| "-f #{f}" }.join " "} logs #{args.join " "} -f #{requested_service_names.join " "}"
9
10
  end
10
11
  end
@@ -3,6 +3,6 @@
3
3
  class Containers::CLI < Thor
4
4
  desc "up", "Brings up the environment defined in docker-compose.yml"
5
5
  def up(*args)
6
- execute_command "docker compose up -d #{args.join " "}"
6
+ execute_command "docker compose #{docker_compose_files.map { |f| "-f #{f}" }.join " "} up -d #{args.join " "}"
7
7
  end
8
8
  end
@@ -0,0 +1,11 @@
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", desc: "The container name"
6
+ method_option :service, type: :string, aliases: "-s", desc: "The service name"
7
+ def yarn(*args)
8
+ container = options[:container] || container_name(options[:service])
9
+ execute_command "containers exec -c #{container} yarn #{args.join " "}"
10
+ end
11
+ end
@@ -3,27 +3,52 @@
3
3
  module Containers::Configurable
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ def self.gitname
7
+ email = begin
8
+ `git config --get user.email`.strip
9
+ rescue
10
+ nil
11
+ end
12
+ email&.split("@")&.first || "example"
13
+ end
14
+
6
15
  DEFAULT_CONFIGURATION = {
7
- "organization_name" => "example-organization",
8
- "project_name" => File.basename(Dir.pwd).parameterize,
9
- "app_directory" => ".",
10
- "docker_directory" => "."
16
+ "organization" => {
17
+ "name" => gitname
18
+ },
19
+ "app" => {
20
+ "name" => File.basename(Dir.pwd).parameterize,
21
+ "directory" => "."
22
+ },
23
+ "docker" => {
24
+ "directory" => ".",
25
+ "default_service" => nil,
26
+ "compose_files" => ["docker-compose.yml"]
27
+ }
11
28
  }.freeze
12
29
 
13
30
  def organization_name
14
- configuration["organization_name"]
31
+ configuration["organization"]["name"]
15
32
  end
16
33
 
17
- def project_name
18
- configuration["project_name"]
34
+ def app_name
35
+ configuration["app"]["name"]
19
36
  end
20
37
 
21
38
  def app_directory
22
- configuration["app_directory"]
39
+ configuration["app"]["directory"]
23
40
  end
24
41
 
25
42
  def docker_directory
26
- configuration["docker_directory"]
43
+ configuration["docker"]["directory"]
44
+ end
45
+
46
+ def docker_default_service
47
+ configuration["docker"]["default_service"]
48
+ end
49
+
50
+ def docker_compose_files
51
+ configuration["docker"]["compose_files"]
27
52
  end
28
53
 
29
54
  def configuration
@@ -15,29 +15,29 @@ module Containers::Generator
15
15
  Pathname.new(__dir__).join "templates/#{template_name}.erb"
16
16
  end
17
17
 
18
- def raw_template(template_name)
18
+ def template_string(template_name)
19
19
  File.read template_path(template_name)
20
20
  end
21
21
 
22
- def erb_template(template_name)
23
- ERB.new raw_template(template_name)
22
+ def template(template_name)
23
+ ERB.new template_string(template_name), trim_mode: "-"
24
24
  end
25
25
 
26
26
  def render_template(template_name, vars = {})
27
27
  view = Struct.new(*vars.keys).new(*vars.values).instance_eval { binding }
28
- erb_template(template_name).result view
28
+ template(template_name).result view
29
29
  end
30
30
 
31
31
  def render_external_template(template, vars = {})
32
32
  view = Struct.new(*vars.keys).new(*vars.values).instance_eval { binding }
33
33
 
34
- raw_template = if template.start_with?("http")
34
+ template_string = if template.start_with?("http")
35
35
  Net::HTTP.get URI.parse(template)
36
36
  else
37
37
  File.read template
38
38
  end
39
39
 
40
- ERB.new(raw_template).result view
40
+ ERB.new(template_string).result view
41
41
  end
42
42
  end
43
43
  end
@@ -11,19 +11,25 @@ class Containers::Generator::CLI < Thor
11
11
  def compose
12
12
  FileUtils.mkdir_p docker_directory
13
13
  path = File.expand_path("#{docker_directory}/docker-compose.yml")
14
+ exists = File.exist?(path)
15
+ original = File.read(path) if exists
14
16
 
15
- continue = if File.exist?(path)
16
- ask("#{Rainbow("docker-compose.yml already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
17
+ continue = if exists
18
+ ask("#{Rainbow("docker-compose.yml already exists").red} Overwrite?", default: "n").to_s.upcase == "Y"
17
19
  else
18
20
  true
19
21
  end
20
22
 
21
23
  return unless continue
22
24
 
25
+ FileUtils.rm_f path
26
+
23
27
  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)
28
+ organization: {name: ask("What is the organization name?", default: organization_name).to_s},
29
+ app: {
30
+ name: ask("What is the app name?", default: app_name).to_s.parameterize,
31
+ directory: File.expand_path(ask("What is the path to the app directory? ", default: app_directory).to_s)
32
+ }
27
33
  }
28
34
 
29
35
  contents = if options[:template]
@@ -35,5 +41,11 @@ class Containers::Generator::CLI < Thor
35
41
  puts_command Rainbow("(Create #{path})").green.faint
36
42
  File.write path, contents
37
43
  puts Rainbow("docker-compose.yml created successfully").green.bright
44
+ rescue => error
45
+ puts Rainbow("Unexpected error! #{error.message}").red.bright
46
+ if exists && original
47
+ puts Rainbow("Restoring the original file.").green.faint
48
+ File.write path, original
49
+ end
38
50
  end
39
51
  end
@@ -8,22 +8,36 @@ class Containers::Generator::CLI < Thor
8
8
  desc "config", "Creates a .containers.yml config file for the project"
9
9
  def config
10
10
  path = File.expand_path(".containers.yml")
11
+ exists = File.exist?(path)
12
+ original = File.read(path) if exists
11
13
 
12
- continue = if File.exist?(path)
13
- ask("#{Rainbow(".containers.yml already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
14
+ continue = if exists
15
+ ask("#{Rainbow(".containers.yml already exists").red} Overwrite?", default: "n").to_s.upcase == "Y"
14
16
  else
15
17
  true
16
18
  end
17
19
 
18
20
  return unless continue
19
21
 
22
+ FileUtils.rm_f path
23
+
20
24
  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
+ organization_name: ask("What is the organization name?", default: organization_name).to_s.parameterize,
26
+ app_name: ask("What is the app name?", default: app_name).to_s.parameterize,
27
+ app_directory: File.expand_path(ask("What is the path to the app directory? ", default: app_directory).to_s),
28
+ docker: {
29
+ directory: File.expand_path(ask("What is the path to the Docker directory? ", default: docker_directory).to_s),
30
+ default_service: ask("What is the default Docker service?", default: docker_default_service).to_s,
31
+ compose_files: docker_compose_files
32
+ }
25
33
  }
26
34
 
27
35
  File.write path, render_template("containers.yml", vars)
36
+ rescue => error
37
+ puts Rainbow("Unexpected error! #{error.message}").red.bright
38
+ if exists && original
39
+ puts Rainbow("Restoring the original file.").green.faint
40
+ File.write path, original
41
+ end
28
42
  end
29
43
  end
@@ -11,15 +11,19 @@ class Containers::Generator::CLI < Thor
11
11
  def dockerfile
12
12
  FileUtils.mkdir_p docker_directory
13
13
  path = File.expand_path("#{docker_directory}/Dockerfile")
14
+ exists = File.exist?(path)
15
+ original = File.read(path) if exists
14
16
 
15
- continue = if File.exist?(path)
16
- ask("#{Rainbow("Dockerfile already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
17
+ continue = if exists
18
+ ask("#{Rainbow("Dockerfile already exists").red} Overwrite?", default: "n").to_s.upcase == "Y"
17
19
  else
18
20
  true
19
21
  end
20
22
 
21
23
  return unless continue
22
24
 
25
+ FileUtils.rm_f path
26
+
23
27
  ruby_version = ask("What Ruby version does this project use?", default: "3.1.2").to_s
24
28
  vars = {ruby_version: ruby_version}
25
29
 
@@ -32,5 +36,11 @@ class Containers::Generator::CLI < Thor
32
36
  puts_command Rainbow("(Create #{path})").green.faint
33
37
  File.write path, contents
34
38
  puts Rainbow("Dockerfile created successfully").green.bright
39
+ rescue => error
40
+ puts Rainbow("Unexpected error! #{error.message}").red.bright
41
+ if exists && original
42
+ puts Rainbow("Restoring the original file.").green.faint
43
+ File.write path, original
44
+ end
35
45
  end
36
46
  end
@@ -1,5 +1,15 @@
1
1
  ---
2
- organization_name: <%= organization_name %>
3
- project_name: <%= project_name %>
4
- app_directory: <%= app_directory %>
5
- docker_directory: <%= docker_directory %>
2
+ organization:
3
+ name: <%= organization_name %>
4
+
5
+ app:
6
+ name: <%= app_name %>
7
+ directory: <%= app_directory %>
8
+
9
+ docker:
10
+ directory: <%= docker[:directory] %>
11
+ default_service: <%= docker[:default_service] %>
12
+ compose_files:
13
+ <% docker[:compose_files].each do |file| -%>
14
+ - <%= file %>
15
+ <% end -%>
@@ -14,17 +14,17 @@ x-default-env: &default_env
14
14
 
15
15
  x-default-app: &default_app
16
16
  build: .
17
- image: <%= organization_name %>/<%= project_name %>
18
- working_dir: /<%= project_name %>
17
+ image: <%= organization[:name] %>/<%= app[:name] %>
18
+ working_dir: /<%= app[:name] %>
19
19
  tty: true
20
20
  stdin_open: true
21
- env_file: <%= File.join app_directory, ".env" %>
21
+ env_file: <%= File.join app[:directory], ".env" %>
22
22
  environment:
23
23
  <<: *default_env
24
24
  volumes:
25
- - <%= app_directory %>:/<%= project_name %>:cached
25
+ - <%= app[:directory] %>:/<%= app[:name] %>:cached
26
26
  - bundle:/bundle:delegated
27
- - node_modules:/<%= project_name %>/node_modules:delegated
27
+ - node_modules:/<%= app[:name] %>/node_modules:delegated
28
28
 
29
29
  # TODO: dump pg database then rename db -> postgres
30
30
  volumes:
@@ -41,7 +41,7 @@ services:
41
41
  # ----------------------------------------------------------------------------
42
42
  postgres:
43
43
  image: postgres:13.4-alpine3.14
44
- container_name: <%= project_name %>-postgres
44
+ container_name: <%= app[:name] %>-postgres
45
45
  restart: unless-stopped
46
46
  environment:
47
47
  POSTGRES_PASSWORD: password
@@ -55,7 +55,7 @@ services:
55
55
  # ----------------------------------------------------------------------------
56
56
  redis_cable:
57
57
  image: redis:6.2.6-alpine3.14
58
- container_name: <%= project_name %>-redis-cable
58
+ container_name: <%= app[:name] %>-redis-cable
59
59
  restart: unless-stopped
60
60
  expose:
61
61
  - 6379
@@ -68,7 +68,7 @@ services:
68
68
  # ----------------------------------------------------------------------------
69
69
  redis_cache:
70
70
  image: redis:6.2.6-alpine3.14
71
- container_name: <%= project_name %>-redis-cache
71
+ container_name: <%= app[:name] %>-redis-cache
72
72
  restart: unless-stopped
73
73
  expose:
74
74
  - 6379
@@ -81,7 +81,7 @@ services:
81
81
  # ----------------------------------------------------------------------------
82
82
  redis_queue:
83
83
  image: redis:6.2.6-alpine3.14
84
- container_name: <%= project_name %>-redis-queue
84
+ container_name: <%= app[:name] %>-redis-queue
85
85
  restart: unless-stopped
86
86
  expose:
87
87
  - 6379
@@ -94,7 +94,7 @@ services:
94
94
  # ----------------------------------------------------------------------------
95
95
  shell:
96
96
  <<: *default_app
97
- container_name: <%= project_name %>-shell
97
+ container_name: <%= app[:name] %>-shell
98
98
  command: /bin/bash -c "tail -f /dev/null"
99
99
 
100
100
  # ----------------------------------------------------------------------------
@@ -102,7 +102,7 @@ services:
102
102
  # ----------------------------------------------------------------------------
103
103
  js:
104
104
  <<: *default_app
105
- container_name: <%= project_name %>-js
105
+ container_name: <%= app[:name] %>-js
106
106
  command: /bin/bash -c "yarn && yarn build --watch"
107
107
 
108
108
  # ----------------------------------------------------------------------------
@@ -110,7 +110,7 @@ services:
110
110
  # ----------------------------------------------------------------------------
111
111
  css:
112
112
  <<: *default_app
113
- container_name: <%= project_name %>-css
113
+ container_name: <%= app[:name] %>-css
114
114
  command: /bin/bash -c "yarn build:css --watch"
115
115
  depends_on:
116
116
  - js
@@ -120,7 +120,7 @@ services:
120
120
  # ----------------------------------------------------------------------------
121
121
  web:
122
122
  <<: *default_app
123
- container_name: <%= project_name %>-web
123
+ container_name: <%= app[:name] %>-web
124
124
  command: >
125
125
  /bin/bash -c "bundle &&
126
126
  rm -f tmp/pids/server.pid &&
@@ -145,7 +145,7 @@ services:
145
145
  # ----------------------------------------------------------------------------
146
146
  worker:
147
147
  <<: *default_app
148
- container_name: <%= project_name %>-worker
148
+ container_name: <%= app[:name] %>-worker
149
149
  command: /bin/bash -c "bin/rails log:clear &&
150
150
  bundle exec sidekiq -C config/sidekiq.yml"
151
151
  depends_on:
@@ -156,7 +156,7 @@ services:
156
156
  # ----------------------------------------------------------------------------
157
157
  anycable_ws:
158
158
  image: anycable/anycable-go:1.2
159
- container_name: <%= project_name %>-anycable-ws
159
+ container_name: <%= app[:name] %>-anycable-ws
160
160
  restart: unless-stopped
161
161
  environment:
162
162
  ANYCABLE_HOST: "0.0.0.0"
@@ -173,7 +173,7 @@ services:
173
173
  # ----------------------------------------------------------------------------
174
174
  anycable_rpc:
175
175
  <<: *default_app
176
- container_name: <%= project_name %>-anycable-rpc
176
+ container_name: <%= app[:name] %>-anycable-rpc
177
177
  restart: unless-stopped
178
178
  environment:
179
179
  <<: *default_env
@@ -191,10 +191,10 @@ services:
191
191
  # ----------------------------------------------------------------------------
192
192
  logs:
193
193
  image: amir20/dozzle
194
- container_name: <%= project_name %>-logs
194
+ container_name: <%= app[:name] %>-logs
195
195
  volumes:
196
196
  - /var/run/docker.sock:/var/run/docker.sock
197
197
  ports:
198
198
  - ${PORT_LOGS:-3004}:8080
199
199
  restart: unless-stopped
200
- command: "--filter name=<%= project_name %>*"
200
+ command: "--filter name=<%= app[:name] %>*"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Containers
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: containers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-20 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rainbow
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: thor
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +67,33 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '1.2'
41
69
  - !ruby/object:Gem::Dependency
42
- name: activesupport
70
+ name: magic_frozen_string_literal
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
46
74
  - !ruby/object:Gem::Version
47
- version: '6.0'
48
- type: :runtime
75
+ version: '0'
76
+ type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
- version: '6.0'
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: pry-byebug
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -66,34 +108,51 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: standardrb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: Manage local development environments with Docker
70
126
  email:
71
127
  - natehop@gmail.com
72
128
  executables:
73
129
  - containers
130
+ - ctrs
74
131
  extensions: []
75
132
  extra_rdoc_files: []
76
133
  files:
77
134
  - exe/containers
135
+ - exe/ctrs
78
136
  - lib/containers.rb
79
137
  - lib/containers/cli.rb
80
138
  - lib/containers/commands/attach.rb
81
139
  - lib/containers/commands/bash.rb
82
- - lib/containers/commands/bundle.rb
140
+ - lib/containers/commands/bin.rb
83
141
  - lib/containers/commands/down.rb
84
142
  - lib/containers/commands/exec.rb
85
143
  - lib/containers/commands/inspect.rb
86
144
  - lib/containers/commands/list.rb
87
- - lib/containers/commands/rails.rb
145
+ - lib/containers/commands/rails/rails.rb
88
146
  - lib/containers/commands/restart.rb
147
+ - lib/containers/commands/ruby/bundle.rb
148
+ - lib/containers/commands/ruby/rake.rb
89
149
  - lib/containers/commands/start.rb
90
150
  - lib/containers/commands/stop.rb
91
151
  - lib/containers/commands/tail.rb
92
152
  - lib/containers/commands/up.rb
93
- - lib/containers/commands/yarn.rb
153
+ - lib/containers/commands/yarn/yarn.rb
94
154
  - lib/containers/concerns/commandable.rb
95
155
  - lib/containers/concerns/configurable.rb
96
- - lib/containers/generator.rb
97
156
  - lib/containers/generator/cli.rb
98
157
  - lib/containers/generator/commands/compose.rb
99
158
  - lib/containers/generator/commands/config.rb
@@ -127,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
186
  - !ruby/object:Gem::Version
128
187
  version: '0'
129
188
  requirements: []
130
- rubygems_version: 3.3.7
189
+ rubygems_version: 3.4.10
131
190
  signing_key:
132
191
  specification_version: 4
133
192
  summary: Manage local development environments with Docker
@@ -1,9 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "erb"
4
-
5
- class Generator < Thor
6
- desc "dockerfile", "Creates a Dockerfile for the project"
7
- def dockerfile
8
- path = File.expand_path("Dockerfile")
9
-
10
- continue = if File.exist?(path)
11
- ask("#{Rainbow("Dockerfile already exists").red} Overwrite?", default: "Y").to_s.upcase == "Y"
12
- else
13
- true
14
- end
15
-
16
- return unless continue
17
-
18
- ruby_version = ask("What Ruby version does this project use?", default: "3.1.2").to_s
19
- File.write path, render("Dockerfile", ruby_version: ruby_version)
20
- end
21
-
22
- desc "compose", "Creates a docker-compose.yml file for the project"
23
- def compose
24
- end
25
-
26
- private
27
-
28
- def root_path
29
- File.expand_path(File.join(__dir__, "..", ".."))
30
- end
31
-
32
- def template(name)
33
- ERB.new(File.read(File.join(root_path, "lib/containers/templates/#{name}.erb")))
34
- end
35
-
36
- def render(template_name, vars = {})
37
- view = Struct.new(*vars.keys).new(*vars.values).instance_eval { binding }
38
- template(template_name).result view
39
- end
40
- end