shiplane 0.2.19 → 0.2.20

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: b03b75bfdf471b5bb888eac4d452c033d5deea577b5af4bbb9c1b592619ab85e
4
- data.tar.gz: c74a64d196981bd6933d0b5fd0d44eb75b8f2ce8483016fbf73decc0b5841058
3
+ metadata.gz: 1e673d54a2bcd03b638734aa05a26dcba8927e5cd1666a2db72c15af9a9d2c58
4
+ data.tar.gz: 0a03a2e3274433448d283f759bfcfc47169f84abaa78461ff326941b51469069
5
5
  SHA512:
6
- metadata.gz: ef9d5a2b95141604995e131e6b1ff916b37b36659fbde655b5262f26ef473f21c5825bc74db0c271fd7564b2aed43b458531fc74f4fce2752c6e04c6d62cb469
7
- data.tar.gz: 18eb80803d06a84f944f7f41509c35ef779636863d9d93c8f78fdbd1b7d88a2b453924fc153ad5c7c34a48979e7d0b450115d40458da191732ab30d9113b5c7c
6
+ metadata.gz: 0b26b1dd7cf7d5d71b23ed071b8968f81713c45d7109b45e0bdf724e2fadd0b40017cc1641e48cfd721e826c2d100017a84ba9088e804d7146bb6cbc87e627ca
7
+ data.tar.gz: 35ef36de90463a85c7793e8156dc6bf4414049c1f821b1356b24322b0238c6f528863bbdecc3485d29eacbeaea5b04aa0819fd81433a5295273d09e14806b0b7
@@ -75,6 +75,8 @@ module Shiplane
75
75
  def build_command(artifact_name)
76
76
  [
77
77
  'docker-compose',
78
+ '-f',
79
+ docker_compose_filepath,
78
80
  '--env-file',
79
81
  build_environment_filepath,
80
82
  'build',
@@ -131,8 +133,12 @@ module Shiplane
131
133
  @shiplane_config ||= Shiplane::Configuration.new(stage: stage)
132
134
  end
133
135
 
136
+ def docker_compose_filepath
137
+ @docker_compose_filepath ||= File.join(project_folder, 'docker-compose.yml')
138
+ end
139
+
134
140
  def docker_config
135
- @docker_config ||= YAML.load(File.new(File.join(project_folder, 'docker-compose.yml')))
141
+ @docker_config ||= YAML.load(File.new(docker_compose_filepath), aliases: true)
136
142
  end
137
143
 
138
144
  def buildable_artifacts
@@ -201,8 +207,8 @@ module Shiplane
201
207
  end
202
208
 
203
209
  class StepFailureException < RuntimeError
204
- def initialize(command, artifact_name)
205
- message = "Command [#{command}] failed for artifact: #{artifact_name}" if artifact_name
210
+ def initialize(command, artifact_name, error_message: nil)
211
+ message = "Command [#{command}] failed for artifact: #{artifact_name}#{error_message ? "\nError Message Received: #{error_message}" : ''}" if artifact_name
206
212
  super(message)
207
213
  end
208
214
  end
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'open3'
2
3
 
3
4
  module Shiplane
4
5
  class CheckoutArtifact
@@ -21,6 +22,18 @@ module Shiplane
21
22
  @appname ||= project_config['appname']
22
23
  end
23
24
 
25
+ def current_sha
26
+ stdout, *_ = Open3.capture3("git rev-parse HEAD")
27
+
28
+ stdout
29
+ end
30
+
31
+ def current_short_sha
32
+ stdout, *_ = Open3.capture3("git rev-parse --short HEAD")
33
+
34
+ stdout
35
+ end
36
+
24
37
  def bitbucket_origin?
25
38
  project_config['version_control_host'] == 'bitbucket'
26
39
  end
@@ -34,11 +47,11 @@ module Shiplane
34
47
  end
35
48
 
36
49
  def bitbucket_token
37
- @bitbucket_token ||= ENV['BITBUCKET_APP_PASSWORD']
50
+ @bitbucket_token ||= ENV['BITBUCKET_TOKEN']
38
51
  end
39
52
 
40
53
  def bitbucket_username
41
- @bitbucket_username ||= ENV['BITBUCKET_APP_USERNAME']
54
+ @bitbucket_username ||= ENV['BITBUCKET_USERNAME']
42
55
  end
43
56
 
44
57
  def git_url
@@ -72,15 +85,25 @@ module Shiplane
72
85
  puts "Checking out Application #{appname}[#{sha}]..."
73
86
  make_directory
74
87
 
75
- success = system("echo 'Downloading #{git_url}/archive/#{sha}.tar.gz --output #{archive_filename}'")
76
- success = success && download_archive
77
- success = success && unpack_archive
88
+ success = send(checkout_strategy[:method])
78
89
 
79
90
  raise "Errors encountered while downloading archive" unless success
80
91
  puts "Finished checking out Application"
81
92
  tasks.each(&method(:send))
82
93
  end
83
94
 
95
+ def checkout_strategies
96
+ @checkout_strategies ||= [
97
+ { method: :archive_and_unpack_commit, conditions: -> { commit_exists? } },
98
+ { method: :download_archive, conditions: -> { !bitbucket_origin? } },
99
+ { method: :checkout_via_git, conditions: -> { true } },
100
+ ]
101
+ end
102
+
103
+ def checkout_strategy
104
+ @checkout_strategy ||= checkout_strategies.find{|strategy| strategy[:conditions].call }
105
+ end
106
+
84
107
  def archive_filename
85
108
  @archive_filename ||= "#{appname}-#{sha}.tar.gz"
86
109
  end
@@ -90,12 +113,80 @@ module Shiplane
90
113
  end
91
114
 
92
115
  def download_archive
93
- return true if File.exist? archive_path
116
+ puts "Downloading #{git_url} --output #{archive_filename}"
117
+ puts "Deploying SHA different from current version. Checking out from Git Repository"
118
+
119
+ success = system("curl -L #{git_url} --output #{archive_path}")
120
+ success && unpack_archive
121
+ end
122
+
123
+ def git_host_url
124
+ return "bitbucket.org" if bitbucket_origin?
125
+ return "github.com" if github_origin?
126
+
127
+ # TODO
128
+ raise 'Gitlab needs fixing'
129
+ end
130
+
131
+ def target_sha_is_current?
132
+ sha == current_short_sha.strip || sha == current_sha.strip
133
+ end
94
134
 
95
- system("curl -L #{git_url} --output #{archive_path}")
135
+ def copy_current_directory
136
+ puts "Current directory is target SHA. Copying for build"
137
+
138
+ FileUtils.cp_r(".", build_directory)
139
+ end
140
+
141
+ def archive_and_unpack_commit
142
+ puts "Creating archive from local git repo in #{archive_filename}..."
143
+ success = system("git archive --format=tar.gz -o #{archive_path} #{sha}")
144
+
145
+ puts "Unpacking archive to #{build_directory}..."
146
+ FileUtils.rm_rf(build_directory) if File.directory?(build_directory)
147
+ FileUtils.mkdir_p build_directory
148
+
149
+ success && system("(cd #{app_directory} && tar -xzf #{appname}-#{sha}.tar.gz -C #{build_directory})")
150
+ end
151
+
152
+ def git_clone_url
153
+ "https://#{bitbucket_username}:#{bitbucket_token}@#{git_host_url}/#{project_config['origin']}.git"
154
+ end
155
+
156
+ def target_sha_is_current?
157
+ sha == current_short_sha.strip || sha == current_sha.strip
158
+ end
159
+
160
+ def commit_exists?
161
+ system("git rev-parse #{sha}")
162
+ end
163
+
164
+ def checkout_via_git
165
+ FileUtils.rm_rf(build_directory) if File.directory?(build_directory)
166
+ FileUtils.mkdir_p build_directory
167
+
168
+ success = true
169
+ puts "Cloning from #{git_clone_url}..."
170
+ success = success && system("git clone --depth=1 #{git_clone_url} #{build_directory}")
171
+ FileUtils.cd build_directory do
172
+ puts "Fetching Single SHA"
173
+ fetch_success = system("git fetch origin #{sha} && git reset --hard FETCH_HEAD")
174
+
175
+ unless fetch_success
176
+ puts "Unable to fetch single commit. Fetching FULL history"
177
+ fetch_success = system("git fetch --unshallow && git fetch origin #{sha} && git reset --hard #{sha}")
178
+ end
179
+
180
+ success = success && fetch_success
181
+
182
+ puts "Removing Git folders before building..."
183
+ success = success && FileUtils.rm_rf("#{build_directory}/.git")
184
+ end
185
+ success
96
186
  end
97
187
 
98
188
  def unpack_archive
189
+ puts "Unpacking archive to #{build_directory}..."
99
190
  FileUtils.rm_rf(build_directory) if File.directory?(build_directory)
100
191
  FileUtils.mkdir_p build_directory
101
192
 
@@ -14,7 +14,7 @@ module Shiplane
14
14
  end
15
15
 
16
16
  def compose_hash
17
- @compose_hash ||= YAML.load(compose_file)
17
+ @compose_hash ||= YAML.load(compose_file, aliases: true)
18
18
  end
19
19
 
20
20
  def whitelisted_hash
@@ -12,7 +12,7 @@ module Shiplane
12
12
  end
13
13
 
14
14
  def config
15
- @config ||= YAML.load_file(shiplane_config_file)
15
+ @config ||= YAML.load_file(shiplane_config_file, aliases: true)
16
16
  end
17
17
 
18
18
  def build_config
data/lib/shiplane/host.rb CHANGED
@@ -82,7 +82,7 @@ module Shiplane
82
82
  end
83
83
 
84
84
  def self.config
85
- @config ||= YAML.load(File.read(config_filepath))
85
+ @config ||= YAML.load(File.read(config_filepath), aliases: true)
86
86
  end
87
87
 
88
88
  def self.config_filepath
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shiplane
4
- VERSION = "0.2.19"
4
+ VERSION = "0.2.20"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiplane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Epperson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-29 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shiplane_bootstrappers_chef
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.19
19
+ version: 0.2.20
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.19
26
+ version: 0.2.20
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: shiplane_deployers_capistrano_docker
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.19
33
+ version: 0.2.20
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.19
40
+ version: 0.2.20
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dotenv
43
43
  requirement: !ruby/object:Gem::Requirement