forked from Digital-Identity-Labs/eduldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
76 lines (58 loc) · 2.39 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
require 'tempfile'
container_name = ENV['EDULDAP_CONTAINER_NAME'] || "eduldap"
snapshot_name = "#{container_name}:snapshot"
full_version = File.read("VERSION").to_s.strip
token = ENV["GITHUB_TOKEN"] || File.read("#{Dir.home}/.tokens/.gh_token").to_s.strip
user = ENV["GITHUB_USER"] || File.read("#{Dir.home}/.tokens/.gh_user").to_s.strip
task :default => :refresh
task :refresh => [:build, :test]
desc "Build the Docker image"
task :build do
tmp_file = Tempfile.new("docker")
git_hash = `git rev-parse --short HEAD`
rebuild_or_not = ENV["EDULDAP_FORCE_REBUILD"] ? "--pull --force-rm" : ""
sh [
"docker build --iidfile #{tmp_file.path}",
"--label 'version=#{full_version}'",
"--label 'org.opencontainers.image.revision=#{git_hash}'",
"--build-arg GITHUB_TOKEN=#{token}",
"--build-arg GH_USER=#{user}",
rebuild_or_not,
"./"
].join(" ")
image_id = File.read(tmp_file.path).to_s.strip
sh "docker tag #{image_id} ghcr.io/digital-identity-labs/#{container_name}:#{full_version}"
sh "docker tag #{image_id} ghcr.io/digital-identity-labs/#{container_name}:latest"
sh "docker tag #{image_id} #{container_name}:#{full_version}"
sh "docker tag #{image_id} #{container_name}:latest"
sh "docker tag #{image_id} #{snapshot_name}"
end
desc "Rebuild the image"
task :rebuild => [:force_reset, :build]
desc "Build the image and test"
task :test => [:build] do
begin
sh "docker run --rm -d -p 389:389 #{snapshot_name}"
container_id = `docker ps -q -l`
sleep ENV['CI'] ? 20 : 10
colour = ENV['CI'] ? "--no-color" : "--color"
# sh "bundle exec inspec exec specs/ishigaki-internal/ #{colour} --chef-license accept -t docker://#{container_id} "
ensure
sh "docker stop #{container_id}" if container_id
end
end
task :shell => [:build] do
sh "docker run --rm -d -p 389:389 #{snapshot_name}"
container_id = `docker ps -q -l`.chomp
sh "docker exec -it #{container_id} /bin/sh"
end
desc "Build and publish a Docker image to Github and Dockerhub"
task publish: [:build] do
sh "docker image push ghcr.io/digital-identity-labs/#{container_name}:#{full_version}"
sh "docker image push ghcr.io/digital-identity-labs/#{container_name}:latest"
sh "docker image push digitalidentity/#{container_name}:#{full_version}"
sh "docker image push digitalidentity/#{container_name}:latest"
end
task :force_reset do
ENV["EDULDAP_FORCE_REBUILD"] = "yes"
end