forked from gocd/gocd-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-docker-images
executable file
·55 lines (45 loc) · 1.54 KB
/
update-docker-images
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
#!/usr/bin/env ruby
if File.basename($PROGRAM_NAME) != 'rake'
require 'shellwords'
puts "rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
exec "rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
end
require 'rubygems'
def verify_version(version, task)
unless version
puts "Please specify a version for building the docker image"
puts "e.g. \n GO_VERSION=16.x.x-xxxx rake #{task}"
puts "or"
puts "If you want to push the built image to a repository"
puts "e.g. \n GO_VERSION=16.x.x-xxxx REPOSITORY=repository_name rake #{task}"
exit(1)
end
end
def image_name(repository, type)
return repository ? "#{repository}/#{type}" : type
end
def docker_build (repository, task, version)
verify_version(version, task)
type = "gocd-#{task}"
image = image_name(repository, type)
verbose false do
cd "phusion/#{task}" do
sh("docker build --build-arg GO_VERSION='#{version}' -t #{image} .")
if repository
short_version = version.split("-").first
sh("docker push #{image}")
sh("docker tag #{image} #{image}:#{short_version}")
sh("docker push #{image}:#{short_version}")
end
end
end
end
desc "Build and push a specific version of GoCD agent docker image"
task :agent do |t, args|
docker_build(ENV['REPOSITORY'], t, ENV['GO_VERSION'])
end
desc "Build and push a specific version of GoCD server docker image"
task :server do |t, args|
docker_build(ENV['REPOSITORY'], t, ENV['GO_VERSION'])
end
task :default => [:agent, :server]