-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
110 lines (90 loc) · 3.11 KB
/
Rakefile
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'ci/reporter/rake/rspec'
require 'rspec/core/rake_task'
def version
v = ENV['BUILD_NUMBER'] || "0.#{`git rev-parse --short HEAD`.chomp.hex}"
"0.0.#{v}"
end
desc 'Run specs'
RSpec::Core::RakeTask.new(:spec => ['ci:setup:rspec'])
desc 'Clean up the build directory'
task :clean do
sh 'rm -rf build/'
end
desc 'Create a debian package'
task :package do
sh 'rm -rf build/package'
sh 'mkdir -p build/package/usr/local/lib/site_ruby/timgroup/'
sh 'cp -r lib/* build/package/usr/local/lib/site_ruby/timgroup/'
sh 'mkdir -p build/package/usr/lib/ruby/vendor_ruby/puppet/indirector/node/'
sh 'cp lib/puppet/indirector/node/stacks.rb build/package/usr/lib/ruby/vendor_ruby/puppet/indirector/node/'
sh 'mkdir -p build/package/usr/local/bin/'
sh 'cp -r bin/* build/package/usr/local/bin/'
arguments = [
'--description', 'stackbuilder',
'--url', 'https://github.com/tim-group/stackbuilder',
'-p', "build/stackbuilder_#{version}.deb",
'-n', 'stackbuilder',
'-v', "#{version}",
'-m', 'Infrastructure <[email protected]>',
'-d', 'ruby-bundle',
'-a', 'all',
'-t', 'deb',
'-s', 'dir',
'-C', 'build/package'
]
argv = arguments.map { |x| "'#{x}'" }.join(' ')
sh 'rm -f build/*.deb'
sh "fpm #{argv}"
end
desc 'Create a debian package'
task :install => [:package] do
sh 'sudo dpkg -i build/*.deb'
sh 'sudo /etc/init.d/mcollective restart;'
end
desc 'Generate CTags'
task :ctags do
sh 'ctags -R --exclude=.git --exclude=build .'
end
desc 'Run lint (Rubocop)'
task :lint do
sh 'rubocop bin lib spec'
end
namespace :docker do
$region = 'eu-west-2'
$repo = 'timgroup/stacks'
def ecr_url
account_id = %x{aws sts get-caller-identity --query Account --output text}.chomp
"#{account_id}.dkr.ecr.#{$region}.amazonaws.com"
end
def image
"#{ecr_url}/#{$repo}"
end
def tag_image(version, tag)
manifest = %x{aws ecr batch-get-image --region #{$region} --repository-name #{$repo} --image-ids imageTag=#{version} --query 'images[].imageManifest' --output text}.chomp
sh "aws ecr put-image --region #{$region} --repository-name #{$repo} --image-tag #{tag} --image-manifest '#{manifest}'"
end
desc 'Login to the docker repository'
task :login do
sh "aws ecr get-login-password --region #{$region} | docker login --username AWS --password-stdin #{ecr_url}"
end
desc 'Build the docker image'
task :build do
docker_version = `docker version --format "{{ .Client.Version }}"`.tr('^0-9.', '')
if Gem::Version.new(docker_version) >= Gem::Version.new('18.09')
ENV['DOCKER_BUILDKIT'] = '1'
end
sh "docker build --network host --build-arg version=#{version} -t stacks:#{version} ."
end
desc 'Tag and publish an unstable image'
task :publish_unstable => [:login] do
sh "docker tag stacks:#{version} #{image}:#{version}"
sh "docker push #{image}:#{version}"
tag_image(version, 'unstable')
end
desc 'Promote and publish an image to stable'
task :promote_stable, [:version] => [:login] do |_, args|
args.with_defaults :version => version
tag_image(args.version, 'stable')
tag_image(args.version, 'latest')
end
end