kuby-core 0.6.1 → 0.7.0

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: 9f538fa630fc43f4767cd6241a79dde985f09e8fe4ce6a08387eb1dcb21b2a51
4
- data.tar.gz: 44da54f5d067a64896bbd23dff200ec56eaf2bbe9183acb8d22c4df906933e98
3
+ metadata.gz: 7d3f784993d379920477923911af9c73a7ac0f661a8831a3fdc21feea83e9d89
4
+ data.tar.gz: 97390f124219ba7e697253c551bbef2527b15d7234793a76431ebdde73e996ed
5
5
  SHA512:
6
- metadata.gz: a589af5cea6a7b81e2b0a707f701e6b341b668e53303dce6288ec1c1ba28c6fca2e4cab835f52ad5a189753c8e82463092ec9dac3a08b9dbd7e0944690b7d50e
7
- data.tar.gz: 1678ac5ccf413eb2778c0f9870554cab5b0b397cc98a5300f381940770389bb335abd0e2ddcad180b42040ea91a4d73688cc17065c8448bbcf907fdcd5c2821e
6
+ metadata.gz: 95fceaebbb3959fb3b872b570b9202deb4dfd4a44dc363c25b20398f9e2a199091eb5fdecbeb07caceb2be104b94c07f3294e8b8158737416e2b83efe7e65ebe
7
+ data.tar.gz: 248b60b0c0ab90d10c780ce69e3f63ff6aa4b222cef82c5121abf2acb4b462c6534b245556a2683649ccf57440e758d5846e93322828f127c66784701ea11127
@@ -1,3 +1,8 @@
1
+ ## 0.7.0
2
+ * Automatically perform `docker login` if not already logged into the Docker registry.
3
+ * Fix timestamp tag parsing issue causing deploy to fail with no available tags.
4
+ - Issue turned out to be ignoring the month of October in the validation regex.
5
+
1
6
  ## 0.6.1
2
7
  * Fix issue causing database.yml to not be rewritten to point at correct database host.
3
8
 
@@ -10,6 +10,38 @@ module Kuby
10
10
  @executable = executable || `which docker`.strip
11
11
  end
12
12
 
13
+ def config_file
14
+ if File.exist?(default_config_file)
15
+ default_config_file
16
+ end
17
+ end
18
+
19
+ def default_config_file
20
+ File.join(Dir.home, '.docker', 'config.json')
21
+ end
22
+
23
+ def login(url:, username:, password:)
24
+ cmd = [
25
+ executable, 'login', url, '--username', username, '--password-stdin'
26
+ ]
27
+
28
+ open3_w({}, cmd) do |stdin, _wait_threads|
29
+ stdin.puts(password)
30
+ end
31
+
32
+ unless last_status.success?
33
+ raise LoginError, 'build failed: docker command exited with '\
34
+ "status code #{last_status.exitstatus}"
35
+ end
36
+ end
37
+
38
+ def auths
39
+ return [] unless config_file
40
+
41
+ config = JSON.parse(File.read(config_file))
42
+ config.fetch('auths', {}).keys
43
+ end
44
+
13
45
  def build(dockerfile:, image_url:, tags:)
14
46
  cmd = [
15
47
  executable, 'build',
@@ -2,6 +2,7 @@ module Kuby
2
2
  module Docker
3
3
  class BuildError < StandardError; end
4
4
  class PushError < StandardError; end
5
+ class LoginError < StandardError; end
5
6
 
6
7
  class MissingTagError < StandardError
7
8
  attr_reader :tag
@@ -28,6 +28,10 @@ module Kuby
28
28
  end
29
29
  end
30
30
 
31
+ def image_hostname
32
+ @image_hostname ||= URI(image_host).host
33
+ end
34
+
31
35
  def image_repo
32
36
  @image_repo ||= if image_url.include?('/')
33
37
  parse_url(image_url).path.sub(/\A\//, '')
@@ -1,7 +1,7 @@
1
1
  module Kuby
2
2
  module Docker
3
3
  class TimestampTag
4
- RE = /20[\d]{2}(?:0[1-9]|11|12)(?:0[1-9]|1[1-9]|2[1-9]|3[01])/.freeze
4
+ RE = /\A20[\d]{2}(?:0[1-9]|10|11|12)(?:0[1-9]|1[1-9]|2[1-9]|3[01])\z/.freeze
5
5
  FORMAT = '%Y%m%d%H%M%S'.freeze
6
6
 
7
7
  def self.try_parse(str)
@@ -39,6 +39,24 @@ module Kuby
39
39
  end
40
40
 
41
41
  def push
42
+ hostname = docker.metadata.image_hostname
43
+
44
+ unless docker.cli.auths.include?(hostname)
45
+ Kuby.logger.info("Attempting to log in to registry at #{hostname}")
46
+
47
+ begin
48
+ docker.cli.login(
49
+ url: docker.metadata.image_host,
50
+ username: docker.credentials.username,
51
+ password: docker.credentials.password
52
+ )
53
+ rescue Kuby::Docker::LoginError => e
54
+ Kuby.logger.fatal("Couldn't log in to the registry at #{hostname}")
55
+ Kuby.logger.fatal(e.message)
56
+ return
57
+ end
58
+ end
59
+
42
60
  image_url = docker.metadata.image_url
43
61
 
44
62
  begin
@@ -50,6 +68,7 @@ module Kuby
50
68
  'Docker image before running this task.'
51
69
 
52
70
  Kuby.logger.fatal(msg)
71
+ Kuby.logger.fatal(e.message)
53
72
  end
54
73
  end
55
74
 
@@ -1,3 +1,3 @@
1
1
  module Kuby
2
- VERSION = '0.6.1'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-06 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize