envirobly 0.5.0 → 0.5.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: aefc0201069c2ebcf4e9038a80904d7e3c6b3217a582572db2536cf9f877367e
4
- data.tar.gz: 26b791aa16c6c38613e7ef5b32cc8f1c93eb7342327ed52968e6ee345a9fa12f
3
+ metadata.gz: 7cbc25ee0033c84e86fd94e67a3be65ee43c8fbcfd86cd962ecf9e5f616bf042
4
+ data.tar.gz: e07002a42e3490bd841f6538ab7cd565990bf55e159fe8d7ce033cff62f6c38d
5
5
  SHA512:
6
- metadata.gz: b5dd97f5d8c19a6e3690884f9f9fc9803a338db2048aaf96a9e5502f68f1d70890a1906f5a478dc998b78e39874cce3db600411a71ee615b41276d63dccdf8c4
7
- data.tar.gz: fe25c4413c314d7368e7fe6b0b05c44f3919159421b75a6511c1ee5c3ba3174ca8c5e3dc52628cd485556a1ef81e92cb2116549573b3d843ed1f753df3ba337b
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
@@ -36,7 +36,7 @@ class Envirobly::Deployment
36
36
  bucket = response.object.fetch("bucket")
37
37
 
38
38
  puts "Uploading build context, please wait..."
39
- unless commit.archive_and_upload(bucket:, credentials:)
39
+ unless commit.archive_and_upload(bucket:, credentials:).success?
40
40
  $stderr.puts "Error exporting build context. Aborting."
41
41
  exit 1
42
42
  end
@@ -8,47 +8,50 @@ class Envirobly::Git::Commit
8
8
  end
9
9
 
10
10
  def exists?
11
- run(%(cat-file -t #{@ref})).strip == "commit"
11
+ git(%(cat-file -t #{@ref})).stdout.strip == "commit"
12
12
  end
13
13
 
14
14
  def ref
15
- @normalized_ref ||= run(%(rev-parse #{@ref})).strip
15
+ @normalized_ref ||= git(%(rev-parse #{@ref})).stdout.strip
16
16
  end
17
17
 
18
18
  def message
19
- run(%(log #{@ref} -n1 --pretty=%B)).strip
19
+ git(%(log #{@ref} -n1 --pretty=%B)).stdout.strip
20
20
  end
21
21
 
22
22
  def time
23
- Time.parse run(%(log #{@ref} -n1 --date=iso --pretty=format:"%ad"))
23
+ Time.parse git(%(log #{@ref} -n1 --date=iso --pretty=format:"%ad")).stdout
24
+ end
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"
24
33
  end
25
34
 
26
35
  def file_content(path)
27
- run %(show #{@ref}:#{path})
36
+ git(%(show #{@ref}:#{path})).stdout
28
37
  end
29
38
 
30
39
  def objects_with_checksum_at(path)
31
- run(%{ls-tree #{@ref} --format='%(objectname) %(path)' #{path}}).lines.map(&:chomp).
40
+ git(%{ls-tree #{@ref} --format='%(objectname) %(path)' #{path}}).stdout.lines.map(&:chomp).
32
41
  reject { _1.split(" ").last == Envirobly::Config::DIR }
33
42
  end
34
43
 
35
44
  def archive_and_upload(bucket:, credentials:)
36
- `GIT_WORK_TREE="#{@working_dir}" GIT_DIR="#{@working_dir}/.git" git archive --format=tar.gz #{ref} | #{credentials.as_inline_env_vars} aws s3 cp - #{archive_uri(bucket)}`
37
- $?.success?
45
+ git(%(archive --format=tar.gz #{ref} | #{credentials.as_inline_env_vars} aws s3 cp - #{archive_uri(bucket)}))
38
46
  end
39
47
 
40
48
  private
41
- def run(cmd)
42
- @stdout = @stderr = @exit_code = @success = nil
43
- full_cmd = %(GIT_WORK_TREE="#{@working_dir}" GIT_DIR="#{@working_dir}/.git" git #{cmd})
44
- Open3.popen3(full_cmd) do |stdin, stdout, stderr, thread|
49
+ OUTPUT = Struct.new :stdout, :stderr, :exit_code, :success?
50
+ def git(cmd)
51
+ Open3.popen3("git #{cmd}", chdir: @working_dir) do |stdin, stdout, stderr, thread|
45
52
  stdin.close
46
- @stdout = stdout.read
47
- @stderr = stderr.read
48
- @exit_code = thread.value.exitstatus
49
- @success = thread.value.success?
53
+ OUTPUT.new stdout.read, stderr.read, thread.value.exitstatus, thread.value.success?
50
54
  end
51
- @stdout
52
55
  end
53
56
 
54
57
  def archive_uri(bucket)
@@ -1,3 +1,3 @@
1
1
  module Envirobly
2
- VERSION = "0.5.0"
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.0
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