-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·84 lines (72 loc) · 2.23 KB
/
deploy
File metadata and controls
executable file
·84 lines (72 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
require 'thor'
require 'colored'
require 'aws-sdk-v1'
def truncate(string, max)
string.length > max ? "#{string[0...max]}..." : string
end
s3 = AWS::S3.new
$bucket = s3.buckets['godeploy']
def list_builds(opts)
limit = opts[:limit] || 5
builds = $bucket.objects.with_prefix('builds/')
builds = builds.sort_by { |obj| obj.last_modified }.reverse
printf "%-41s %-30s %s\n", "GIT SHA", "GIT BRANCH", "BUILD DATE"
builds.take(limit).each() do |obj|
sha = obj.metadata.sha || ""
branch = obj.metadata.branch || ""
next unless sha != ""
printf "%-41s %-30s %s\n", sha, truncate(branch, 30), obj.last_modified
end
end
def tag_build(opts)
sha = opts[:sha]
tag = opts[:tag]
to = $bucket.objects["tags/#{tag}.tar.gz"]
from = $bucket.objects["builds/godeploy_#{sha}.tar.gz"]
if !from.exists?
raise "No release for #{sha}"
end
from.copy_to(to, {
metadata: {
version: sha
}
})
end
def get_current_sha(opts)
tags = $bucket.objects.with_prefix('tags/')
tags = tags.sort_by { |obj| obj.last_modified }.reverse
printf "%-15s %-41s %s\n", "TAG", "GIT SHA", "PUBLISH DATE"
tags.each() do |obj|
next unless obj.key.match('tar\.gz')
tag = obj.key.gsub(/tags\//,'').gsub(/\.tar\.gz/,'')
sha = obj.metadata['version']
printf "%-15s %-41s %s\n", tag, sha, obj.last_modified
end
end
module Deploy
class CommandSuite < Thor
desc 'builds', 'Lists most recent CircleCI builds we packages in s3'
method_option :limit, :required => true, :default => 5, :desc => 'Limit number of builds to show'
def builds
list_builds options
end
desc 'tags', 'List currently deployed tags'
def tags
get_current_sha options
end
desc 'tag', 'Tag a build'
method_option 'sha', :required => true, :desc => 'SHA to publish'
method_option 'tag', :required => true, :desc => 'Tag to publish build on'
def tag
obj = tag_build options
if obj.exists?
printf "Success!".green + " Tagged %s to %s.\n", options['sha'].cyan, options['tag'].cyan
else
printf "Failure!".red + " Could not tag %s to %s.\n", options['sha'].cyan, options['tag'].cyan
exit(1)
end
end
end
end
Deploy::CommandSuite.start(ARGV)