envirobly 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca86599ff3741799e0a3faf9d3386c3c937713b15c8fb063dc6c647879eacfd1
4
- data.tar.gz: d22ece59c009474e6f3bf465e96452eddfc344c344e1a64e4255c88c828d7e12
3
+ metadata.gz: 7cbc25ee0033c84e86fd94e67a3be65ee43c8fbcfd86cd962ecf9e5f616bf042
4
+ data.tar.gz: e07002a42e3490bd841f6538ab7cd565990bf55e159fe8d7ce033cff62f6c38d
5
5
  SHA512:
6
- metadata.gz: 341a285db112636480ec428f8647ecddc573ce063e64a57e0a79f289bebad4567397c428179d0b109e2e9b443d1e0853f9a4edadbae7280744b42e79381ee834
7
- data.tar.gz: efed0f09a1fa8a33095d4a838c04a8c2657b7673e986796bc5df68f962e181ad7db975678532a31e2f86f2b2b9efe3ba2fb823b0a7582a91bc5adfc37c2d7253
6
+ metadata.gz: eb490ba6309b3775f548522596c6a5d42504ba2ca878ef8c74b530af12733b9a9ac1ce016ece2afdb7d6c616f4121ca418a49ef3037e06790a9e3da3b916ba93
7
+ data.tar.gz: 7abc4689844be2617b74bb425c0ba8136b793d5c0c36600d58defdeadf8a84e9b31715442467c1e912b8988ee1c708c61eedb0192a2af3eadf9fc0b54bf0a327
@@ -35,7 +35,7 @@ class Envirobly::Config
35
35
  def to_deployment_params
36
36
  {
37
37
  environ: {
38
- logical_id: @environment,
38
+ name: @environment,
39
39
  project_url: @project_url
40
40
  },
41
41
  commit: {
@@ -57,17 +57,17 @@ class Envirobly::Config
57
57
  end
58
58
 
59
59
  def set_project_url
60
- @project_url = dig :remote, :origin
60
+ @project_url = dig :project
61
61
  if @project_url.blank?
62
- @errors << "Missing a `remote.origin` link to project."
62
+ @errors << "Missing `project: <url>` top level attribute."
63
63
  end
64
64
  end
65
65
 
66
66
  def transform_env_var_values!
67
- @project.fetch(:services, {}).each do |logical_id, service|
67
+ @project.fetch(:services, {}).each do |name, service|
68
68
  service.fetch(:env, {}).each do |key, value|
69
69
  if value.is_a?(Hash) && value.has_key?(:file)
70
- @project[:services][logical_id][:env][key] = @commit.file_content(value.fetch(:file)).strip
70
+ @project[:services][name][:env][key] = @commit.file_content(value.fetch(:file)).strip
71
71
  end
72
72
  end
73
73
  end
@@ -75,39 +75,38 @@ class Envirobly::Config
75
75
 
76
76
  NON_BUILDABLE_TYPES = %w[ postgres mysql valkey ]
77
77
  BUILD_DEFAULTS = {
78
- dockerfile: "Dockerfile",
79
- build_context: "."
78
+ dockerfile: [ "Dockerfile", :file_exists? ],
79
+ build_context: [ ".", :dir_exists? ]
80
80
  }
81
81
  def append_image_tags!
82
- @project.fetch(:services, {}).each do |logical_id, service|
82
+ @project.fetch(:services, {}).each do |name, service|
83
83
  next if NON_BUILDABLE_TYPES.include?(service[:type]) || service[:image].present?
84
84
  checksums = []
85
85
 
86
- BUILD_DEFAULTS.each do |attribute, default|
87
- value = service.fetch(attribute, default)
88
- checksum = @commit.objects_with_checksum_at value
89
- if checksum.empty?
90
- @errors << "Service `#{logical_id}` specifies `#{attribute}` as `#{value}` which doesn't exist in this commit."
86
+ BUILD_DEFAULTS.each do |attribute, options|
87
+ value = service.fetch(attribute, options.first)
88
+ unless @commit.public_send(options.second, value)
89
+ @errors << "Service `#{name}` specifies `#{attribute}` as `#{value}` which doesn't exist in this commit."
91
90
  else
92
- checksums << checksum
91
+ checksums << @commit.objects_with_checksum_at(value)
93
92
  end
94
93
  end
95
94
 
96
95
  if checksums.size == 2
97
- @project[:services][logical_id][:image_tag] = Digest::SHA1.hexdigest checksums.to_json
96
+ @project[:services][name][:image_tag] = Digest::SHA1.hexdigest checksums.to_json
98
97
  end
99
98
  end
100
99
  end
101
100
 
102
101
  def merge_environment_overrides!
103
102
  return unless services = @project.dig(:environments, @environment.to_sym)
104
- services.each do |logical_id, service|
103
+ services.each do |name, service|
105
104
  service.each do |attribute, value|
106
- if value.is_a?(Hash) && @project[:services][logical_id][attribute].is_a?(Hash)
107
- @project[:services][logical_id][attribute].merge! value
108
- @project[:services][logical_id][attribute].compact!
105
+ if value.is_a?(Hash) && @project[:services][name][attribute].is_a?(Hash)
106
+ @project[:services][name][attribute].merge! value
107
+ @project[:services][name][attribute].compact!
109
108
  else
110
- @project[:services][logical_id][attribute] = value
109
+ @project[:services][name][attribute] = value
111
110
  end
112
111
  end
113
112
  end
@@ -23,6 +23,15 @@ class Envirobly::Git::Commit
23
23
  Time.parse git(%(log #{@ref} -n1 --date=iso --pretty=format:"%ad")).stdout
24
24
  end
25
25
 
26
+ def file_exists?(path)
27
+ git(%(cat-file -t #{@ref}:#{path})).stdout.strip == "blob"
28
+ end
29
+
30
+ def dir_exists?(path)
31
+ suffix = path.end_with?("/") ? nil : "/"
32
+ git(%(cat-file -t #{@ref}:#{path}#{suffix})).stdout.strip == "tree"
33
+ end
34
+
26
35
  def file_content(path)
27
36
  git(%(show #{@ref}:#{path})).stdout
28
37
  end
@@ -1,3 +1,3 @@
1
1
  module Envirobly
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envirobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-19 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor