dctl_rb 0.4.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd25c95274d81568271c730fb7162171ee0e8a432ee451c2c9a8ea500ef4aba5
4
- data.tar.gz: fc162add3502d9741b89eca1e67920da9a7775adfac89ab4b520e2b3422ef7c4
3
+ metadata.gz: 3934427beaf11b1a77bf3d3c7eee40df99af3875e91862810d7b722956d7f12d
4
+ data.tar.gz: ec0e64e8db1ba461406d3f7b70c72d74523a6d259252350227058b05cc3ac9b4
5
5
  SHA512:
6
- metadata.gz: 199f823503954b1ad893f930c202e6091fb0f5801cde315812826da5607adf38b29403c13ea212243786f6b92b9c08ece7aa925749f746889cfa95f09dc157c6
7
- data.tar.gz: 155973810386b77f1a5e7654ccaf0a2dcb69153ee946611a7c4702f521320022ee814c0ccc7bec43dba837305e8494e42639dde3bcc2abc5ecb09529191f2bb9
6
+ metadata.gz: be5ca89fd24dbf67d148a54a3753f059b44e9da45a4fd624532a7623e47c761cd775d68e4929ffcfeee9a7801de098d16d70320f2a263c43c2ae282013b5b07c
7
+ data.tar.gz: 18d3627016b31b6307bce7777d197b5e9dfb0bbbb7db5336ab5588dbf20050e876c2d29d48faa5982667ce2db9a76c08b560658e75f39a1fd041a512d185d374
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dctl_rb (0.4.0)
4
+ dctl_rb (0.4.1)
5
5
  config (>= 1, < 2)
6
6
  rainbow (>= 2.2, < 3)
7
7
  thor (~> 0.17, >= 0.17.0)
@@ -14,6 +14,7 @@ GEM
14
14
  i18n (~> 0.7)
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
+ byebug (9.1.0)
17
18
  concurrent-ruby (1.0.5)
18
19
  config (1.6.1)
19
20
  activesupport (>= 3.0)
@@ -78,6 +79,7 @@ PLATFORMS
78
79
 
79
80
  DEPENDENCIES
80
81
  bundler (~> 1.16)
82
+ byebug (~> 9.1)
81
83
  dctl_rb!
82
84
  rake (~> 10.0)
83
85
  rspec (~> 3.0)
data/dctl_rb.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "bundler", "~> 1.16"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "byebug", "~> 9.1"
35
36
 
36
37
  spec.add_dependency "thor", "~> 0.17", ">= 0.17.0"
37
38
  spec.add_dependency "config", ">= 1", "< 2"
data/lib/dctl/main.rb ADDED
@@ -0,0 +1,160 @@
1
+ module Dctl
2
+ class Main
3
+ attr_reader :env, :settings
4
+
5
+ def initialize(env: "dev")
6
+ @env = env
7
+ load_config!
8
+ end
9
+
10
+ ##
11
+ # Generate the full tag for the given image, concatenating the org,
12
+ # project, env, image name, and version.
13
+ #
14
+ # @example
15
+ # image_tag("app") # => jutonz/dctl-dev-app:1
16
+ def image_tag(image)
17
+ org = settings.org
18
+ project = settings.project
19
+ version = versions[image] || 1
20
+
21
+ "#{org}/#{project}-#{env}-#{image}:#{version}"
22
+ end
23
+
24
+ ##
25
+ # Returns the path to the given image's data directory (which includes at
26
+ # minimum the Dockerfile, plus any other relevant files the user may have
27
+ # placed there).
28
+ def image_dir(image)
29
+ relative = File.join "docker", env, image
30
+ File.expand_path relative, Dir.pwd
31
+ end
32
+
33
+ def image_dockerfile(image)
34
+ File.expand_path "Dockerfile", image_dir(image)
35
+ end
36
+
37
+ def expand_images(*images)
38
+ images = versions.keys if images.empty?
39
+ images = Array(images)
40
+
41
+ images.each { |i| check_image_name(i) }
42
+
43
+ images
44
+ end
45
+
46
+ ##
47
+ # Returns the path to the .dctl.yml file for the current project
48
+ def config_path
49
+ path = File.expand_path ".dctl.yml", Dir.pwd
50
+
51
+ unless File.exist? path
52
+ error = "Could not find config file at #{path}"
53
+ puts Rainbow(error).red
54
+ exit 1
55
+ end
56
+
57
+ path
58
+ end
59
+
60
+ ##
61
+ # Confirms that there is an entry for the given image in the compose file
62
+ # for this environment, and that the image tag within is formatted as we
63
+ # expect it to be.
64
+ #
65
+ # Prints a warning if the tag has the wrong name, but errors out if the
66
+ # service tag is not present
67
+ #
68
+ # Expected names look like org/project-env-image:version
69
+ def check_image_name(image)
70
+ tag = image_tag(image)
71
+
72
+ # Check that a service exists for the image
73
+ service = parsed_compose_file.dig "services", image
74
+ unless service
75
+ error = "The service \"#{image}\" is not present in the compose " \
76
+ "file for this environment. Please add a service entry for " \
77
+ "#{image} to #{compose_file_path}\n"
78
+ puts Rainbow(error).fg :red
79
+
80
+ puts <<~EOL
81
+ It might look something like this:
82
+
83
+ version: '3'
84
+ services:
85
+ #{image}:
86
+ image: #{image_tag(image)}
87
+ EOL
88
+ exit 1
89
+ end
90
+
91
+ # Check that the image has the correct tag
92
+ expected_tag = image_tag(image)
93
+ actual_tag = service["image"]
94
+ if actual_tag != expected_tag
95
+ warning = "Expected the tag for the image \"#{image}\" to be " \
96
+ "\"#{expected_tag}\", but it was \"#{actual_tag}\". While not " \
97
+ "critical, this can cause issues with some commands."
98
+ puts Rainbow(warning).fg :orange
99
+ end
100
+ end
101
+
102
+ def versions
103
+ @versions ||= begin
104
+ images = parsed_compose_file["services"].keys
105
+ version_map = {}
106
+
107
+ images.each do |image|
108
+ version_map[image] = parsed_compose_file["services"][image]["image"].split(":").last
109
+ end
110
+
111
+ version_map
112
+ end
113
+ end
114
+
115
+ def parsed_compose_file
116
+ @parsed_compose_file ||= YAML.load_file compose_file_path
117
+ end
118
+
119
+ ##
120
+ # Ensure the current project's .dctl.yml contains all the requisite keys.
121
+ def check_settings!
122
+ required_keys = %w(
123
+ org
124
+ project
125
+ )
126
+
127
+ required_keys.each do |key|
128
+ unless Settings.send key
129
+ error = "Config is missing required key '#{key}'. Please add it " \
130
+ "to #{config_path} and try again."
131
+ error += "\n\nFor more info, see https://github.com/jutonz/dctl_rb#required-keys"
132
+ puts Rainbow(error).red
133
+ exit 1
134
+ end
135
+ end
136
+ end
137
+
138
+ ##
139
+ # Load the current project's config file, complaining if it does not exist
140
+ # or is malformed.
141
+ def load_config!
142
+ Config.load_and_set_settings(config_path)
143
+ check_settings!
144
+
145
+ @settings = Settings
146
+ end
147
+
148
+ def compose_file_path
149
+ path = File.expand_path "docker/#{env}/docker-compose.yml"
150
+
151
+ unless File.exist? path
152
+ err = "There is no docker compose file for env #{env} (I expected to find it at #{path})"
153
+ puts Rainbow(err).red
154
+ exit 1
155
+ end
156
+
157
+ path
158
+ end
159
+ end
160
+ end
data/lib/dctl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dctl
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/dctl.rb CHANGED
@@ -1,118 +1,8 @@
1
1
  require "rainbow"
2
- require "dctl/version"
3
2
  require "config"
4
3
 
5
- module Dctl
6
- class Main
7
- attr_reader :env, :settings
8
-
9
- def initialize(env: "dev")
10
- @env = env
11
- load_config!
12
- end
13
-
14
- ##
15
- # Generate the full tag for the given image, concatenating the org,
16
- # project, env, image name, and version.
17
- #
18
- # @example
19
- # image_tag("app") # => jutonz/dctl-dev-app:1
20
- def image_tag(image)
21
- org = settings.org
22
- project = settings.project
23
- version = versions[image]
24
-
25
- "#{org}/#{project}-#{env}-#{image}:#{version}"
26
- end
27
-
28
- ##
29
- # Returns the path to the given image's data directory (which includes at
30
- # minimum the Dockerfile, plus any other relevant files the user may have
31
- # placed there).
32
- def image_dir(image)
33
- relative = File.join "docker", env, image
34
- File.expand_path relative, Dir.pwd
35
- end
36
-
37
- def image_dockerfile(image)
38
- File.expand_path "Dockerfile", image_dir(image)
39
- end
40
-
41
- def expand_images(*images)
42
- images = versions.keys if images.empty?
43
- images = Array(images)
44
- end
45
-
46
- ##
47
- # Returns the path to the .dctl.yml file for the current project
48
- def config_path
49
- path = File.expand_path ".dctl.yml", Dir.pwd
50
-
51
- unless File.exist? path
52
- error = "Could not find config file at #{path}"
53
- puts Rainbow(error).red
54
- exit 1
55
- end
56
-
57
- path
58
- end
59
-
60
- def versions
61
- @versions ||= begin
62
- images = parsed_compose_file["services"].keys
63
- version_map = {}
64
-
65
- images.each do |image|
66
- version_map[image] = parsed_compose_file["services"][image]["image"].split(":").last
67
- end
68
-
69
- version_map
70
- end
71
- end
72
-
73
- def parsed_compose_file
74
- @parsed_compose_file ||= YAML.load_file compose_file_path
75
- end
76
-
77
- ##
78
- # Ensure the current project's .dctl.yml contains all the requisite keys.
79
- def check_settings!
80
- required_keys = %w(
81
- org
82
- project
83
- )
84
-
85
- required_keys.each do |key|
86
- unless Settings.send key
87
- error = "Config is missing required key '#{key}'. Please add it " \
88
- "to #{config_path} and try again."
89
- error += "\n\nFor more info, see https://github.com/jutonz/dctl_rb#required-keys"
90
- puts Rainbow(error).red
91
- exit 1
92
- end
93
- end
94
- end
95
-
96
- ##
97
- # Load the current project's config file, complaining if it does not exist
98
- # or is malformed.
99
- def load_config!
100
- Config.load_and_set_settings(config_path)
101
- check_settings!
102
-
103
- @settings = Settings
104
- end
105
-
106
- def compose_file_path
107
- path = File.expand_path "docker/#{env}/docker-compose.yml"
108
-
109
- unless File.exist? path
110
- err = "There is no docker compose file for env #{env} (I expected to find it at #{path})"
111
- puts Rainbow(err).red
112
- exit 1
113
- end
4
+ require "dctl/version"
5
+ require "dctl/main"
114
6
 
115
- path
116
- end
117
- end
7
+ module Dctl
118
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dctl_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Toniazzo
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: thor
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +149,7 @@ files:
135
149
  - dctl_rb.gemspec
136
150
  - exe/dctl
137
151
  - lib/dctl.rb
152
+ - lib/dctl/main.rb
138
153
  - lib/dctl/version.rb
139
154
  homepage: https://github.com/jutonz/dctl_rb
140
155
  licenses: