forked from decidim/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-registry.rb
executable file
·68 lines (61 loc) · 2.68 KB
/
update-registry.rb
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
#!/usr/bin/env ruby
require_relative 'lib/decidim_version'
require_relative 'lib/ruby_repo'
require_relative 'lib/docker_image'
require_relative 'lib/helpers'
require "erb"
REGISTRY_USERNAME = ENV.fetch("REGISTRY_USERNAME", "decidim")
DECIDIM_VERSIONS_COUNT = ENV.fetch("DECIDIM_VERSION_COUNT", "2").to_i
template_docker_compose = ERB.new(File.read('templates/container-docker-compose.yml.erb'))
template_dockerfile = ERB.new(File.read('templates/container-Dockerfile.erb'))
supported_versions = []
begin
system("git", "clone", "--bare", "https://github.com/decidim/decidim.git", "decidim-repo")
Dir.chdir('decidim-repo') do
supported_versions.push(DecidimVersion.new("develop"))
if DECIDIM_VERSIONS_COUNT > 0
branches = `git branch --list 'release/*-stable' | sort -V | tail -n #{DECIDIM_VERSIONS_COUNT}`
branch_list = branches.split("\n")
supported_versions.concat(branch_list.map do |branch|
DecidimVersion.new(branch.gsub(/\s+/, ' ').strip)
end)
end
end
ensure
system("rm", "-rf", "decidim-repo")
end
image = "#{REGISTRY_USERNAME}/decidim"
errors = []
supported_versions.map do |version|
docker_image = DockerImage.new(version)
decidim_version_string = docker_image.version.join(".")
is_stable = docker_image.github_branch.include?("stable")
source_tag = "decidim:#{is_stable ? decidim_version_string : "nightly"}"
File.write("./bundle/docker-compose.yml", template_docker_compose.result_with_hash(
is_stable: is_stable,
))
File.write("./bundle/Dockerfile", template_dockerfile.result_with_hash(
docker_tag: "#{REGISTRY_USERNAME}/decidim:#{docker_image.version.first(2).join(".")}-onbuild",
))
begin
build_images(docker_image, image)
if is_stable
# Stable versions 0.27.3 => publish to 0.27 and 0.27.3
tag_versions(docker_image.version) do |version|
push_image("#{source_tag}-onbuild", "#{image}:#{version}-onbuild")
push_image("#{source_tag}-dev", "#{image}:#{version}-dev")
push_image("#{source_tag}", "#{image}:#{version}")
end
else
version = docker_image.github_branch
push_image("#{source_tag}-onbuild", "#{image}:nightly-onbuild")
push_image("#{source_tag}-dev", "#{image}:nightly-dev")
push_image("#{source_tag}", "#{image}:nightly")
end
# Clean all the images and cache before continuing
system("docker", "system", "prune", "-af")
rescue => error
errors.push("Errors on #{source_tag}. #{error}")
end
end
raise "UPDATE FAILED. #{errors.join("\n")}" if errors.count > 0