-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
114 lines (93 loc) · 3.21 KB
/
Copy pathRakefile
File metadata and controls
114 lines (93 loc) · 3.21 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
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
111
112
113
114
# frozen_string_literal: true
require 'erb'
require 'fileutils'
require 'tempfile'
require 'yaml'
require 'open-uri'
Dir.glob('lib/*.rb').each { |l| load l unless File.exist?("local/#{l[4..-1]}") } if Dir.exist?('lib')
Dir.glob('local/*.rb').each { |l| load l } if Dir.exist?('local')
if File.exist?('metadata.yaml')
local_metadata = YAML.safe_load(File.read('metadata.yaml'))
else
puts('WARNING: metadata.yaml not found.')
local_metadata = {}
end
puts('WARNING: Rakefile library not found.') unless File.exist?('lib')
if File.exist?('lib/metadata-defaults.yaml')
default_metadata = YAML.safe_load(File.read('lib/metadata-defaults.yaml'))
else
puts('WARNING: metadata defaults not found.')
default_metadata = {}
end
if File.exist?('metadata.yaml') && File.exist?('lib')
$images = build_objects_array(
metadata: local_metadata,
default_metadata: default_metadata
)
end
desc 'Install Rakefile support files'
task :install do
URI.parse('https://github.com/itsbcit/docker-rakefile/releases/latest/download/lib.zip').open do |archive|
FileUtils.remove_entry('lib') if File.exist?('lib')
tempfile = Tempfile.new(['lib', '.zip'])
File.open(tempfile.path, 'wb') do |f|
f.write(archive.read)
end
system('unzip', tempfile.path)
tempfile.unlink
end
end
desc 'Update Rakefile to latest release version'
task :update do
Rake::Task[:install].invoke
URI.parse('https://github.com/itsbcit/docker-rakefile/releases/latest/download/Rakefile').open do |rakefile|
File.open('Rakefile', 'wb') do |f|
f.write(rakefile.read)
end
end
end
Dir.glob('lib/tasks/*.rake').each { |l| load l unless File.exist?("local/tasks/#{l[10..-1]}") } if Dir.exist?('lib/tasks')
Dir.glob('local/tasks/*.rake').each { |l| load l } if Dir.exist?('local/tasks')
###########################
# GitHub Actions Template #
# @ripienaar https://www.devco.net/archives/2010/11/18/a_few_rake_tips.php
# Brilliant.
def render_template(template, output, scope)
tmpl = File.read(template)
erb = ERB.new(tmpl, trim_mode: "-")
File.open(output, "w") do |f|
f.puts erb.result(scope)
end
end
# def read_csv(csv)
# # TODO build a method that reads a csv file and builds an object for each line of the csv, then builds a workflow file from that object
# end
# end
desc "Update Jenkinsfile template for ESS Job"
task :default do
header1 = "DO NOT EDIT THIS FILE. EDIT 'GitHubActions.erb' and run 'rake'"
container_names = [
'container-test',
'container-prod'
]
dockerfile_paths = [
'test/Dockerfile',
'prod/Dockerfile'
]
container_tags = [
'ekraft2/container-test:test',
'ekraft2/container-test:prod'
]
#TODO Setup job so it reads and assigns values from lines entered just above here in csv format
# Create counter for each container url to be applied properly
counter = 0
container_names.each do |container|
container_name = container
dockerfile_path = dockerfile_paths[counter]
container_tag = container_tags[counter]
# Name repo file and render template
workflow_file_name = container.gsub(' ','-').downcase
render_template("GitHubActions.erb", ".github/workflows/workflow-#{workflow_file_name}.yml", binding)
counter +=1
end
end