harrison 0.5.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +29 -0
- data/CODEOWNERS +1 -0
- data/README.md +66 -23
- data/harrison.gemspec +3 -3
- data/lib/harrison/base.rb +2 -0
- data/lib/harrison/deploy.rb +0 -2
- data/lib/harrison/package.rb +204 -9
- data/lib/harrison/version.rb +1 -1
- data/spec/unit/harrison/package_spec.rb +44 -0
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ac6e8aca51fd74e1b84b13585f9bd8733d92e12a413c76818dca4de77aff614
|
4
|
+
data.tar.gz: d471919b9f85f9dc53abd62b5820b8aabdb0de9d7df278088720475f9209a3fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2516c2cdc2745f7392f5a9993b3fd0d431ba9875db6c5a77b8919c5ea3ef1a20064ca15079b533fc1c0889b06955be5f3e1d64d14e876295351cbff4526f6f6e
|
7
|
+
data.tar.gz: e08b862b1d1957d5629a529e5437f7da9fcc37a9c1b256d1cce9591e37bc7c1c45d37a2e9baf94251507dc9219b6f2ba64b0e0b469f5cf7e55200ba783d7e367
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
0.9.1
|
2
|
+
-------------------
|
3
|
+
- Bumped dependencies on net-ssh and net-scp to latest majors
|
4
|
+
|
5
|
+
0.9.0
|
6
|
+
-------------------
|
7
|
+
- Added ability to package via Docker
|
8
|
+
- Added ability to generate multiple builds from a single invocation (when building via Docker)
|
9
|
+
|
10
|
+
0.8.0
|
11
|
+
-------------------
|
12
|
+
- BREAKING: Bumped required Ruby version to >= 2.3.1
|
13
|
+
- Bumped net-ssh to 5.2.x
|
14
|
+
- Bumped net-scp to 2.0.x
|
15
|
+
|
16
|
+
0.7.0
|
17
|
+
-------------------
|
18
|
+
- Added ability to calculate build host dynamically in package task.
|
19
|
+
|
20
|
+
0.6.0
|
21
|
+
-------------------
|
22
|
+
- Added ability to package from forks. When packaging from HEAD or a branch,
|
23
|
+
harrison will now check to see if that branch is tracking a remote branch.
|
24
|
+
If so, it will attempt to package code from that remote. If the branch
|
25
|
+
being packaged is not tracking a remote branch, or if what is being packaged
|
26
|
+
is not a branch, harrison will look for a remote named "origin" and package
|
27
|
+
from there. Lastly, if there is not a remote named "origin", it will package
|
28
|
+
from the configured "git_src".
|
29
|
+
|
1
30
|
0.5.0
|
2
31
|
-------------------
|
3
32
|
- BREAKING: Bumped net-ssh to 3.2.x which results in Harrison now
|
data/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @puppetlabs/forge-team
|
data/README.md
CHANGED
@@ -119,8 +119,9 @@ Harrison.deploy do |h|
|
|
119
119
|
end
|
120
120
|
```
|
121
121
|
|
122
|
-
Next, ensure that your SSH key is authorized to log in as the `user` you have
|
123
|
-
the Harrisonfile for each task. (Or be ready to type the password
|
122
|
+
Next, ensure that your SSH key is authorized to log in as the `user` you have
|
123
|
+
specified in the Harrisonfile for each task. (Or be ready to type the password
|
124
|
+
a lot. :weary:)
|
124
125
|
|
125
126
|
### Building a Release
|
126
127
|
|
@@ -130,18 +131,25 @@ Use the `harrison package` command:
|
|
130
131
|
$ harrison package
|
131
132
|
```
|
132
133
|
|
133
|
-
By default this will build and package `HEAD` of your current branch. You may
|
134
|
-
build using the `--commit` option:
|
134
|
+
By default this will build and package `HEAD` of your current branch. You may
|
135
|
+
specify another commit to build using the `--commit` option:
|
135
136
|
|
136
137
|
```
|
137
138
|
$ harrison package --commit mybranch
|
138
139
|
```
|
139
140
|
|
140
|
-
The `--commit` option understands anything that `git rev-parse` understands.
|
141
|
-
reference must be pushed to
|
142
|
-
you can build it.*
|
141
|
+
The `--commit` option understands anything that `git rev-parse` understands.
|
142
|
+
*NOTE: The commit you reference must be pushed to a repository accessible by
|
143
|
+
your build server before you can build it.*
|
143
144
|
|
144
|
-
|
145
|
+
By default, harrison will automatically detect the correct remote repository to
|
146
|
+
attempt to package from by first checking to see if the branch being deployed
|
147
|
+
is tracking a specific remote and if not, looking for a remote named "origin"
|
148
|
+
to package from. If neither of these is available, it will fall back to the
|
149
|
+
git\_src configured in your Harrisonfile.
|
150
|
+
|
151
|
+
The packaged release artifact will, by default, be saved into a local 'pkg'
|
152
|
+
subfolder:
|
145
153
|
|
146
154
|
```
|
147
155
|
$ harrison package
|
@@ -149,8 +157,8 @@ Packaging 5a547d8 for "harrison" on build-server.example.com...
|
|
149
157
|
Sucessfully packaged 5a547d8 to pkg/20140711170226-5a547d8.tar.gz
|
150
158
|
```
|
151
159
|
|
152
|
-
You can set the destination on the command line with the `--destination`
|
153
|
-
specify a new default in your Harrisonfile:
|
160
|
+
You can set the destination on the command line with the `--destination`
|
161
|
+
option, or specify a new default in your Harrisonfile:
|
154
162
|
|
155
163
|
```
|
156
164
|
h.destination = '/tmp'
|
@@ -162,16 +170,18 @@ You can also specify a remote destination:
|
|
162
170
|
h.destination = 'jesse@artifact-host.example.com:/tmp/artifacts'
|
163
171
|
```
|
164
172
|
|
165
|
-
The username is optional and, if omitted, the build user will be used. *NOTE:
|
166
|
-
must have already accepted the SSH host key of the
|
167
|
-
artifact.*
|
173
|
+
The username is optional and, if omitted, the build user will be used. *NOTE:
|
174
|
+
Your build server must have already accepted the SSH host key of the
|
175
|
+
destination server in order to transfer the artifact.*
|
168
176
|
|
169
|
-
There are some additional options available, run `harrison package --help` to
|
177
|
+
There are some additional options available, run `harrison package --help` to
|
178
|
+
see everything available.
|
170
179
|
|
171
180
|
|
172
181
|
### Deploying a Release
|
173
182
|
|
174
|
-
Use the `harrison deploy` command passing the artifact to be deployed as an
|
183
|
+
Use the `harrison deploy` command passing the artifact to be deployed as an
|
184
|
+
argument:
|
175
185
|
|
176
186
|
```
|
177
187
|
$ harrison deploy pkg/20140711170226-5a547d8.tar.gz
|
@@ -183,10 +193,11 @@ You can also deploy from a remote artifact source:
|
|
183
193
|
$ harrison deploy jesse@artifact-host.example.com:/tmp/artifacts/20140711170226-5a547d8.tar.gz
|
184
194
|
```
|
185
195
|
|
186
|
-
*NOTE: Each target server must have already accepted the SSH host key of the
|
187
|
-
transfer the artifact.*
|
196
|
+
*NOTE: Each target server must have already accepted the SSH host key of the
|
197
|
+
source server in order to transfer the artifact.*
|
188
198
|
|
189
|
-
By default, the artifact will be deployed to the list of hosts defined in your
|
199
|
+
By default, the artifact will be deployed to the list of hosts defined in your
|
200
|
+
Harrisonfile.
|
190
201
|
|
191
202
|
You can override the target hosts by passing a `--hosts` option:
|
192
203
|
|
@@ -200,7 +211,8 @@ You can also pass an `--env` option to deploy into multi-stage environments:
|
|
200
211
|
$ harrison deploy pkg/20140711170226-5a547d8.tar.gz --env prod
|
201
212
|
```
|
202
213
|
|
203
|
-
This value can then be tested to alter the default target hosts in your
|
214
|
+
This value can then be tested to alter the default target hosts in your
|
215
|
+
Harrisonfile:
|
204
216
|
|
205
217
|
```ruby
|
206
218
|
if h.env =~ /prod/
|
@@ -210,11 +222,42 @@ else
|
|
210
222
|
end
|
211
223
|
```
|
212
224
|
|
213
|
-
|
214
|
-
|
215
|
-
|
225
|
+
The hosts option in your Harrisonfile can also be defined as a block of code
|
226
|
+
which will be evaluated in order to calculate a list of hosts to deploy to.
|
227
|
+
The code block should evaluate to an array of hostnames, for example:
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
h.hosts = Proc.new do |h; client, response, instances|
|
231
|
+
require 'aws-sdk'
|
232
|
+
|
233
|
+
AWS.config(region: 'us-west-2')
|
234
|
+
|
235
|
+
client = AWS.ec2.client
|
236
|
+
|
237
|
+
response = client.describe_instances(filters: [
|
238
|
+
{ name: 'tag:Name', values: ["app-server-*.#{h.env}.example.com"] },
|
239
|
+
{ name: 'instance-state-name', values: ['running'] },
|
240
|
+
])
|
241
|
+
|
242
|
+
instances = response.data[:reservation_set].flat_map do |r|
|
243
|
+
r[:instances_set] && r[:instances_set].collect do |i|
|
244
|
+
name_tag = i[:tag_set].find { |tag| tag[:key] == 'Name' }
|
245
|
+
|
246
|
+
name_tag[:value]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
instances
|
251
|
+
end
|
252
|
+
```
|
253
|
+
|
254
|
+
You can use the `--keep` option (or set it in the deploy section of your
|
255
|
+
Harrisonfile) to specify the total number of deploys you want to retain on each
|
256
|
+
server after a successful deployment. The default is to keep all previous
|
257
|
+
deploys around indefinitely.
|
216
258
|
|
217
|
-
There are some additional options available, run `harrison deploy --help` to
|
259
|
+
There are some additional options available, run `harrison deploy --help` to
|
260
|
+
see everything available.
|
218
261
|
|
219
262
|
|
220
263
|
## Contributing
|
data/harrison.gemspec
CHANGED
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = '>= 2.
|
20
|
+
spec.required_ruby_version = '>= 2.3.1'
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "trollop", "~> 2.1.2"
|
23
|
-
spec.add_runtime_dependency "net-ssh", "~>
|
24
|
-
spec.add_runtime_dependency "net-scp", "~>
|
23
|
+
spec.add_runtime_dependency "net-ssh", "~> 6.1"
|
24
|
+
spec.add_runtime_dependency "net-scp", "~> 3.0"
|
25
25
|
spec.add_runtime_dependency "highline", "~> 1.7.8"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.6"
|
data/lib/harrison/base.rb
CHANGED
@@ -6,9 +6,11 @@ module Harrison
|
|
6
6
|
def initialize(arg_opts=[], opts={})
|
7
7
|
# Config helpers for Harrisonfile.
|
8
8
|
self.class.option_helper(:user)
|
9
|
+
self.class.option_helper(:env)
|
9
10
|
|
10
11
|
@arg_opts = arg_opts
|
11
12
|
@arg_opts << [ :debug, "Output debug messages.", :type => :boolean, :default => false ]
|
13
|
+
@arg_opts << [ :env, "Environment to package for or deploy to. This can be examined in your Harrisonfile to calculate target hosts.", :type => :string ]
|
12
14
|
|
13
15
|
@options = opts
|
14
16
|
end
|
data/lib/harrison/deploy.rb
CHANGED
@@ -15,7 +15,6 @@ module Harrison
|
|
15
15
|
def initialize(opts={})
|
16
16
|
# Config helpers for Harrisonfile.
|
17
17
|
self.class.option_helper(:hosts)
|
18
|
-
self.class.option_helper(:env)
|
19
18
|
self.class.option_helper(:base_dir)
|
20
19
|
self.class.option_helper(:deploy_via)
|
21
20
|
self.class.option_helper(:keep)
|
@@ -24,7 +23,6 @@ module Harrison
|
|
24
23
|
# Command line opts for this action. Will be merged with common opts.
|
25
24
|
arg_opts = [
|
26
25
|
[ :hosts, "List of remote hosts to deploy to. Can also be specified in Harrisonfile.", :type => :strings ],
|
27
|
-
[ :env, "Environment to deploy to. This can be examined in your Harrisonfile to calculate target hosts.", :type => :string ],
|
28
26
|
[ :keep, "Number of recent deploys to keep after a successful deploy. (Including the most recent deploy.) Defaults to keeping all deploys forever.", :type => :integer ],
|
29
27
|
[ :confirm, "Whether to interactively confirm the list of target hosts for deployment.", :type => :flag, :default => true ],
|
30
28
|
]
|
data/lib/harrison/package.rb
CHANGED
@@ -2,6 +2,8 @@ module Harrison
|
|
2
2
|
class Package < Base
|
3
3
|
def initialize(opts={})
|
4
4
|
# Config helpers for Harrisonfile.
|
5
|
+
self.class.option_helper(:via)
|
6
|
+
self.class.option_helper(:dockerfiles)
|
5
7
|
self.class.option_helper(:host)
|
6
8
|
self.class.option_helper(:commit)
|
7
9
|
self.class.option_helper(:purge)
|
@@ -33,33 +35,75 @@ module Harrison
|
|
33
35
|
def run(&block)
|
34
36
|
return super if block_given?
|
35
37
|
|
38
|
+
# Find the URL of the remote in case it differs from git_src.
|
39
|
+
remote_url = find_remote(self.commit)
|
40
|
+
|
36
41
|
# Resolve commit ref to an actual short SHA.
|
37
42
|
resolve_commit!
|
38
43
|
|
39
|
-
|
44
|
+
return run_docker if self.via == :docker
|
45
|
+
|
46
|
+
if self.host.respond_to?(:call)
|
47
|
+
resolved_host = self.host.call(self)
|
48
|
+
self.host = resolved_host
|
49
|
+
end
|
50
|
+
|
51
|
+
# Require at least one host.
|
52
|
+
if !self.host || self.host.empty?
|
53
|
+
abort("ERROR: Unable to resolve build host.")
|
54
|
+
end
|
55
|
+
|
56
|
+
puts "Packaging #{commit} from #{remote_url} for \"#{project}\" on #{host}..."
|
40
57
|
|
41
58
|
# Make sure the folder to save the artifact to locally exists.
|
42
59
|
ensure_destination(destination)
|
43
60
|
|
61
|
+
# To avoid collisions, we use a version of the full URL as remote name.
|
62
|
+
remote_cache_name = remote_url.gsub(/[^a-z0-9_]/i, '_')
|
63
|
+
|
44
64
|
# Fetch/clone git repo on remote host.
|
45
|
-
remote_exec
|
65
|
+
remote_exec <<~ENDCMD
|
66
|
+
if [ -d cached ]
|
67
|
+
then
|
68
|
+
cd cached
|
69
|
+
if [ -d .git/refs/remotes/#{remote_cache_name} ]
|
70
|
+
then
|
71
|
+
git fetch #{remote_cache_name} -p
|
72
|
+
else
|
73
|
+
git remote add -f #{remote_cache_name} #{remote_url}
|
74
|
+
fi
|
75
|
+
else
|
76
|
+
git clone -o #{remote_cache_name} #{remote_url} cached
|
77
|
+
fi
|
78
|
+
ENDCMD
|
46
79
|
|
47
|
-
|
48
|
-
remote_exec("rm -rf #{artifact_name(commit)} && cp -a cached #{artifact_name(commit)}")
|
80
|
+
build_dir = remote_cache_name + '-' + artifact_name(commit)
|
49
81
|
|
50
|
-
#
|
51
|
-
remote_exec("
|
82
|
+
# Clean up any stale build folder of the target remote/commit.
|
83
|
+
remote_exec("rm -rf #{build_dir} && mkdir -p #{build_dir}")
|
84
|
+
|
85
|
+
# Check out target commit into the build_dir.
|
86
|
+
checkout_failure = catch :failure do
|
87
|
+
remote_exec("cd cached && GIT_WORK_TREE=../#{build_dir} git checkout --detach -f #{commit} && git checkout -f -") # TODO: When git is upgraded: --ignore-other-worktrees
|
88
|
+
|
89
|
+
# We want "checkout_failure" to be false if nothing was caught.
|
90
|
+
false
|
91
|
+
end
|
92
|
+
|
93
|
+
if checkout_failure
|
94
|
+
abort("ERROR: Unable to checkout requested git reference '#{commit}' on build server, ensure you have pushed the requested branch or tag to the remote repo.")
|
95
|
+
end
|
52
96
|
|
53
97
|
# Run user supplied build code in the context of the checked out code.
|
54
98
|
begin
|
55
|
-
@_remote_context = "#{remote_project_dir}/package/#{
|
99
|
+
@_remote_context = "#{remote_project_dir}/package/#{build_dir}"
|
56
100
|
super
|
57
101
|
ensure
|
58
102
|
@_remote_context = nil
|
59
103
|
end
|
60
104
|
|
61
105
|
# Package build folder into tgz.
|
62
|
-
remote_exec("rm -f #{artifact_name(commit)}.tar.gz && cd #{
|
106
|
+
remote_exec("rm -f #{artifact_name(commit)}.tar.gz && cd #{build_dir} && tar #{excludes_for_tar} -czf ../#{artifact_name(commit)}.tar.gz .")
|
63
107
|
|
64
108
|
if match = remote_regex.match(destination)
|
65
109
|
# Copy artifact to remote destination.
|
@@ -73,7 +117,8 @@ module Harrison
|
|
73
117
|
end
|
74
118
|
|
75
119
|
if purge
|
76
|
-
remote_exec("rm -rf #{
|
120
|
+
remote_exec("rm -rf #{build_dir}")
|
121
|
+
remote_exec("rm #{artifact_name(commit)}.tar.gz")
|
77
122
|
end
|
78
123
|
|
79
124
|
puts "Sucessfully packaged #{commit} to #{destination}/#{artifact_name(commit)}.tar.gz"
|
@@ -81,10 +126,160 @@ module Harrison
|
|
81
126
|
|
82
127
|
protected
|
83
128
|
|
129
|
+
def run_docker
|
130
|
+
require 'open3'
|
131
|
+
|
132
|
+
packages = []
|
133
|
+
|
134
|
+
git_worktree_prune_argv = [
|
135
|
+
"git",
|
136
|
+
"worktree",
|
137
|
+
"prune",
|
138
|
+
].join(' ')
|
139
|
+
|
140
|
+
if Harrison::DEBUG
|
141
|
+
system(git_worktree_prune_argv) || (throw :failure)
|
142
|
+
else
|
143
|
+
_, gwtp_err, gwtp_status = Open3.capture3(git_worktree_prune_argv)
|
144
|
+
|
145
|
+
if gwtp_status != 0
|
146
|
+
puts gwtp_err
|
147
|
+
throw :failure
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
begin
|
152
|
+
tmp_dir = Dir.mktmpdir("harrison-#{project}", "/tmp")
|
153
|
+
tmp_src_dir = File.join(tmp_dir, 'src')
|
154
|
+
|
155
|
+
git_worktree_add_argv = [
|
156
|
+
"git",
|
157
|
+
"worktree",
|
158
|
+
"add",
|
159
|
+
"--force", # allow new worktree to check out duplicate branch
|
160
|
+
tmp_src_dir,
|
161
|
+
commit,
|
162
|
+
].join(' ')
|
163
|
+
|
164
|
+
git_worktree_add_env = {
|
165
|
+
"OVERCOMMIT_DISABLE" => "1",
|
166
|
+
}
|
167
|
+
|
168
|
+
if Harrison::DEBUG
|
169
|
+
system(git_worktree_add_env, git_worktree_add_argv) || (throw :failure)
|
170
|
+
else
|
171
|
+
_, gwta_err, gwta_status = Open3.capture3(git_worktree_add_env, git_worktree_add_argv)
|
172
|
+
|
173
|
+
if gwta_status != 0
|
174
|
+
puts gwta_err
|
175
|
+
throw :failure
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
self.dockerfiles.each do |df|
|
180
|
+
df_basename = File.basename(df, '.Dockerfile')
|
181
|
+
docker_image_tag = "#{project}-harrison-#{df_basename}:latest"
|
182
|
+
|
183
|
+
docker_build_argv = [
|
184
|
+
'docker', 'build',
|
185
|
+
'--file', df,
|
186
|
+
'--tag', docker_image_tag,
|
187
|
+
'.',
|
188
|
+
].join(' ')
|
189
|
+
|
190
|
+
puts "Running: #{docker_build_argv}"
|
191
|
+
|
192
|
+
if Harrison::DEBUG
|
193
|
+
system(docker_build_argv) || (throw :failure)
|
194
|
+
else
|
195
|
+
_, build_err, build_status = Open3.capture3(docker_build_argv)
|
196
|
+
|
197
|
+
if build_status != 0
|
198
|
+
puts build_err
|
199
|
+
throw :failure
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
docker_run_argv = [
|
204
|
+
"docker", "run",
|
205
|
+
"--mount", "type=bind,source=#{tmp_src_dir},target=/src,readonly",
|
206
|
+
"--mount", "type=bind,source=\"$(pwd)/pkg\",target=/pkg",
|
207
|
+
docker_image_tag,
|
208
|
+
commit,
|
209
|
+
].join(' ')
|
210
|
+
|
211
|
+
puts "Running: #{docker_run_argv}"
|
212
|
+
|
213
|
+
if Harrison::DEBUG
|
214
|
+
system(docker_run_argv) || (throw :failure)
|
215
|
+
else
|
216
|
+
pkg_out, pkg_err, pkg_status = Open3.capture3(docker_run_argv)
|
217
|
+
|
218
|
+
if pkg_status != 0
|
219
|
+
puts pkg_err
|
220
|
+
throw :failure
|
221
|
+
end
|
222
|
+
pkg_out_lines = pkg_out.split("\n")
|
223
|
+
|
224
|
+
packages << pkg_out_lines[-1]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
git_worktree_remove_argv = [
|
229
|
+
"git",
|
230
|
+
"worktree",
|
231
|
+
"remove",
|
232
|
+
"--force", # don't care if worktree is unclean
|
233
|
+
tmp_src_dir,
|
234
|
+
].join(' ')
|
235
|
+
|
236
|
+
if Harrison::DEBUG
|
237
|
+
system(git_worktree_remove_argv) || (throw :failure)
|
238
|
+
else
|
239
|
+
_, gwtr_err, gwtr_status = Open3.capture3(git_worktree_remove_argv)
|
240
|
+
|
241
|
+
if gwtr_status != 0
|
242
|
+
puts gwtr_err
|
243
|
+
throw :failure
|
244
|
+
end
|
245
|
+
end
|
246
|
+
ensure
|
247
|
+
FileUtils.rm_rf(tmp_dir, secure: true)
|
248
|
+
end
|
249
|
+
|
250
|
+
puts "\n#{packages.join("\n")}"
|
251
|
+
end
|
252
|
+
|
84
253
|
def remote_project_dir
|
85
254
|
"#{remote_dir}/#{project}"
|
86
255
|
end
|
87
256
|
|
257
|
+
def find_remote(ref)
|
258
|
+
remote = nil
|
259
|
+
remote_url = nil
|
260
|
+
|
261
|
+
catch :failure do
|
262
|
+
# If it's a branch, try to resolve what it's tracking.
|
263
|
+
# This will exit non-zero (and throw :failure) if the ref is
|
264
|
+
# not a branch.
|
265
|
+
remote = exec("git rev-parse --symbolic-full-name #{ref}@{upstream} 2>/dev/null")&.match(/\Arefs\/remotes\/(.+)\/.+\Z/i)&.captures.first
|
266
|
+
end
|
267
|
+
|
268
|
+
# Fallback to 'origin' if not deploying a branch with a tracked
|
269
|
+
# upstream.
|
270
|
+
remote ||= 'origin'
|
271
|
+
|
272
|
+
catch :failure do
|
273
|
+
# Look for a URL for whatever remote we have. git-config exits
|
274
|
+
# non-zero if the requested value doesn't exist.
|
275
|
+
remote_url = exec("git config remote.#{remote}.url 2>/dev/null")
|
276
|
+
end
|
277
|
+
|
278
|
+
# If we found a remote_url, return that, otherwise fall back to
|
279
|
+
# configured git_src.
|
280
|
+
return remote_url || self.git_src
|
281
|
+
end
|
282
|
+
|
88
283
|
def resolve_commit!
|
89
284
|
self.commit = exec("git rev-parse --short #{self.commit} 2>/dev/null")
|
90
285
|
end
|
data/lib/harrison/version.rb
CHANGED
@@ -4,6 +4,7 @@ describe Harrison::Package do
|
|
4
4
|
before(:all) do
|
5
5
|
Harrison.class_variable_set(:@@config, Harrison::Config.new)
|
6
6
|
Harrison.config.project = 'test_project'
|
7
|
+
Harrison.config.git_src = 'git_src_from_config'
|
7
8
|
end
|
8
9
|
|
9
10
|
let(:instance) do
|
@@ -97,6 +98,49 @@ describe Harrison::Package do
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
101
|
+
describe '#find_remote' do
|
102
|
+
before(:each) do
|
103
|
+
allow(instance).to receive(:exec).with(/^git config remote.my_remote.url/).and_return('my_remote_url')
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when deploying a branch that is tracking a remote branch' do
|
107
|
+
before(:each) do
|
108
|
+
allow(instance).to receive(:exec).with(/^git rev-parse/).and_return('refs/remotes/my_remote/branch')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should return url for tracked remote' do
|
112
|
+
expect(instance.send(:find_remote, 'HEAD')).to eq 'my_remote_url'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when deploying a tree-ish with no remote tracking' do
|
117
|
+
before(:each) do
|
118
|
+
allow(instance).to receive(:exec).with(/^git rev-parse/).and_throw(:failure)
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when an \'origin\' remote exists' do
|
122
|
+
before(:each) do
|
123
|
+
allow(instance).to receive(:exec).with(/^git config remote.origin.url/).and_return('origin_url')
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should return url for origin' do
|
127
|
+
expect(instance.send(:find_remote, 'HEAD')).to eq 'origin_url'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when no \'origin\' remote exists' do
|
132
|
+
before(:each) do
|
133
|
+
allow(instance).to receive(:exec).with(/^git config remote.origin.url/).and_throw(:failure)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should return the configured git_src' do
|
137
|
+
# git_src is defined globally at the top of this file
|
138
|
+
expect(instance.send(:find_remote, 'HEAD')).to eq 'git_src_from_config'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
100
144
|
describe '#resolve_commit!' do
|
101
145
|
it 'should resolve commit reference to a short sha using git rev-parse' do
|
102
146
|
instance.commit = 'giant'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: harrison
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '6.1'
|
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: '
|
40
|
+
version: '6.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: net-scp
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: highline
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- ".rspec"
|
163
163
|
- ".travis.yml"
|
164
164
|
- CHANGELOG
|
165
|
+
- CODEOWNERS
|
165
166
|
- Gemfile
|
166
167
|
- IDEAS
|
167
168
|
- LICENSE.txt
|
@@ -199,15 +200,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
200
|
requirements:
|
200
201
|
- - ">="
|
201
202
|
- !ruby/object:Gem::Version
|
202
|
-
version:
|
203
|
+
version: 2.3.1
|
203
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
205
|
requirements:
|
205
206
|
- - ">="
|
206
207
|
- !ruby/object:Gem::Version
|
207
208
|
version: '0'
|
208
209
|
requirements: []
|
209
|
-
|
210
|
-
rubygems_version: 2.5.1
|
210
|
+
rubygems_version: 3.0.8
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: Simple artifact-based deployment for web applications.
|