-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
221 lines (181 loc) · 6.41 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
require 'tempfile'
container_name = ENV['ISHIGAKI_CONTAINER_NAME'] || "ishigaki"
snapshot_name = "#{container_name}:snapshot"
full_version = File.read("VERSION").to_s.strip
major_version = full_version.split(".").slice(0..1).join(".")
minor_version = full_version.split(".").slice(0)
task :default => :refresh
task :refresh => [:build, :test]
desc "Build the default Docker image"
task :build => ["build:generic"]
namespace :build do
desc "Build all versions"
task :all => ["build:generic", "build:base", "build:plus"]
desc "Build the Docker image (generic)"
task :generic do
tmp_file = Tempfile.new("docker")
git_hash = `git rev-parse --short HEAD`
rebuild_or_not = ENV["ISHIGAKI_FORCE_REBUILD"] ? "--pull --force-rm" : ""
if ENV["PUBLISH_MP_MODE"].to_s.downcase == "yes"
command = "docker buildx build"
platforms = "--platform linux/amd64,linux/arm64"
push_or_not = "--push"
else
command = "docker build"
platforms = ""
push_or_not = " "
end
tags = [
"ghcr.io/digital-identity-labs/#{container_name}:#{full_version}",
"ghcr.io/digital-identity-labs/#{container_name}:#{major_version}",
"ghcr.io/digital-identity-labs/#{container_name}:#{minor_version}",
"ghcr.io/digital-identity-labs/#{container_name}:latest",
"digitalidentity/#{container_name}:#{full_version}",
"digitalidentity/#{container_name}:latest",
"#{container_name}:snapshot",
].map { |t| " -t #{t}" }.join(" ")
sh [
command,
"--iidfile #{tmp_file.path}",
platforms,
"--label 'version=#{full_version}'",
"--label 'org.opencontainers.image.revision=#{git_hash}'",
"--progress=plain",
tags,
rebuild_or_not,
push_or_not,
"./"
].join(" ")
image_id = File.read(tmp_file.path).to_s.strip
puts image_id
end
desc "Build the Docker image for use a base image"
task :base do
tmp_file = Tempfile.new("docker")
git_hash = `git rev-parse --short HEAD`
rebuild_or_not = ENV["ISHIGAKI_FORCE_REBUILD"] ? "--pull --force-rm" : ""
if ENV["PUBLISH_MP_MODE"].to_s.downcase == "yes"
command = "docker buildx build"
platforms = "--platform linux/amd64,linux/arm64"
push_or_not = "--push"
else
command = "docker build"
platforms = ""
push_or_not = " "
end
tags = [
"ghcr.io/digital-identity-labs/#{container_name}:#{full_version}-base",
"ghcr.io/digital-identity-labs/#{container_name}:#{major_version}-base",
"ghcr.io/digital-identity-labs/#{container_name}:#{minor_version}-base",
"ghcr.io/digital-identity-labs/#{container_name}:latest-base",
].map { |t| " -t #{t}" }.join(" ")
sh [
command,
"--iidfile #{tmp_file.path}",
platforms,
"--build-arg WRITE_MD=0",
"--build-arg EDWIN_STARR=1",
"--build-arg DELAY_WAR=1",
"--build-arg MODULES=''",
"--build-arg PLUGINS=''",
"--label 'version=#{full_version}'",
"--label 'org.opencontainers.image.revision=#{git_hash}'",
"--progress=plain",
tags,
rebuild_or_not,
push_or_not,
"./"
].join(" ")
image_id = File.read(tmp_file.path).to_s.strip
puts image_id
end
desc "Build the Docker image (including extra plugins)"
task :plus do
tmp_file = Tempfile.new("docker")
git_hash = `git rev-parse --short HEAD`
rebuild_or_not = ENV["ISHIGAKI_FORCE_REBUILD"] ? "--pull --force-rm" : ""
if ENV["PUBLISH_MP_MODE"].to_s.downcase == "yes"
command = "docker buildx build"
platforms = "--platform linux/amd64,linux/arm64"
push_or_not = "--push"
else
command = "docker build"
platforms = ""
push_or_not = " "
end
plugin_ids = [
"net.shibboleth.idp.plugin.metadatagen",
"net.shibboleth.idp.plugin.authn.totp",
"net.shibboleth.oidc.common",
"net.shibboleth.idp.plugin.oidc.config",
"net.shibboleth.idp.plugin.oidc.op",
"net.shibboleth.idp.plugin.oidc.rp",
"net.shibboleth.idp.plugin.authn.duo.sdk",
"net.shibboleth.idp.plugin.nashorn"
].join(" ")
tags = [
"ghcr.io/digital-identity-labs/#{container_name}:#{full_version}-plus",
"ghcr.io/digital-identity-labs/#{container_name}:#{major_version}-plus",
"ghcr.io/digital-identity-labs/#{container_name}:#{minor_version}-plus",
"ghcr.io/digital-identity-labs/#{container_name}:latest-plus",
].map { |t| " -t #{t}" }.join(" ")
sh [
command,
"--iidfile #{tmp_file.path}",
platforms,
"--build-arg WRITE_MD=0",
"--build-arg DELAY_WAR=1",
"--build-arg MODULES=''",
"--build-arg PLUGIN_IDS='#{plugin_ids}'",
"--build-arg PLUGIN_MODULES=''",
"--label 'version=#{full_version}'",
"--label 'org.opencontainers.image.revision=#{git_hash}'",
"--progress=plain",
tags,
rebuild_or_not,
push_or_not,
"./"
].join(" ")
image_id = File.read(tmp_file.path).to_s.strip
puts image_id
end
end
desc "Rebuild the image"
task :rebuild => [:force_reset, :build]
desc "Build the image and test"
task :test => [:build] do
begin
sh "docker run -d -p 8080:8080 #{snapshot_name}"
container_id = `docker ps -q -l`
sleep ENV['CI'] ? 20 : 10
colour = ENV['CI'] ? "--no-color" : "--color"
sh "bundle exec cinc-auditor exec specs/ #{colour} -t docker://#{container_id} "
ensure
sh "docker stop #{container_id}" if container_id
end
end
desc "Build the image, run, and open a shell"
task :shell => [:build] do
sh "docker run -d -p 8080:8080 #{snapshot_name}"
container_id = `docker ps -q -l`.chomp
sh "docker exec -it #{container_id} /bin/bash"
end
desc "Build and run the image and then export configuration files"
task :export => [:build] do
sh "docker run -d -p 8080:8080 #{snapshot_name}"
container_id = `docker ps -q -l`.chomp
sh "mkdir -p exported_optfs/"
sh "docker cp #{container_id}:/opt/shibboleth-idp/ exported_optfs/shibboleth-idp"
sh "docker cp #{container_id}:/opt/jetty-shib/ exported_optfs/jetty-shib"
sh "docker stop #{container_id}"
end
desc "Build and publish all Docker images to Github"
task publish: [:publish_mp_mode, "build:all"] do
puts "Complete!"
end
task :force_reset do
ENV["ISHIGAKI_FORCE_REBUILD"] = "yes"
end
task :publish_mp_mode do
ENV["PUBLISH_MP_MODE"] = "yes"
end