envirobly 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/envirobly/config.rb +19 -20
- data/lib/envirobly/deployment.rb +1 -1
- data/lib/envirobly/git/commit.rb +20 -17
- data/lib/envirobly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cbc25ee0033c84e86fd94e67a3be65ee43c8fbcfd86cd962ecf9e5f616bf042
|
4
|
+
data.tar.gz: e07002a42e3490bd841f6538ab7cd565990bf55e159fe8d7ce033cff62f6c38d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb490ba6309b3775f548522596c6a5d42504ba2ca878ef8c74b530af12733b9a9ac1ce016ece2afdb7d6c616f4121ca418a49ef3037e06790a9e3da3b916ba93
|
7
|
+
data.tar.gz: 7abc4689844be2617b74bb425c0ba8136b793d5c0c36600d58defdeadf8a84e9b31715442467c1e912b8988ee1c708c61eedb0192a2af3eadf9fc0b54bf0a327
|
data/lib/envirobly/config.rb
CHANGED
@@ -35,7 +35,7 @@ class Envirobly::Config
|
|
35
35
|
def to_deployment_params
|
36
36
|
{
|
37
37
|
environ: {
|
38
|
-
|
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 :
|
60
|
+
@project_url = dig :project
|
61
61
|
if @project_url.blank?
|
62
|
-
@errors << "Missing
|
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 |
|
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][
|
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 |
|
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,
|
87
|
-
value = service.fetch(attribute,
|
88
|
-
|
89
|
-
|
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 <<
|
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][
|
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 |
|
103
|
+
services.each do |name, service|
|
105
104
|
service.each do |attribute, value|
|
106
|
-
if value.is_a?(Hash) && @project[:services][
|
107
|
-
@project[:services][
|
108
|
-
@project[:services][
|
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][
|
109
|
+
@project[:services][name][attribute] = value
|
111
110
|
end
|
112
111
|
end
|
113
112
|
end
|
data/lib/envirobly/deployment.rb
CHANGED
@@ -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
|
data/lib/envirobly/git/commit.rb
CHANGED
@@ -8,47 +8,50 @@ class Envirobly::Git::Commit
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def exists?
|
11
|
-
|
11
|
+
git(%(cat-file -t #{@ref})).stdout.strip == "commit"
|
12
12
|
end
|
13
13
|
|
14
14
|
def ref
|
15
|
-
@normalized_ref ||=
|
15
|
+
@normalized_ref ||= git(%(rev-parse #{@ref})).stdout.strip
|
16
16
|
end
|
17
17
|
|
18
18
|
def message
|
19
|
-
|
19
|
+
git(%(log #{@ref} -n1 --pretty=%B)).stdout.strip
|
20
20
|
end
|
21
21
|
|
22
22
|
def time
|
23
|
-
Time.parse
|
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
|
-
|
36
|
+
git(%(show #{@ref}:#{path})).stdout
|
28
37
|
end
|
29
38
|
|
30
39
|
def objects_with_checksum_at(path)
|
31
|
-
|
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
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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)
|
data/lib/envirobly/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|