aboutsummaryrefslogtreecommitdiff
blob: e6ab09c2d001703d1722f7e16c0ef5282fee4cc1 (plain)
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
require_relative 'app'

task default: 'test'

desc 'Run the test suite'
task :test do
	puts "RUBOCOP:\n"
	sh 'bundle exec rubocop'
	puts "\nSHELLCHECK:\n"
	sh "shellcheck --exclude=SC2016 #{Dir.glob('../**/*.sh').join(' ')}"
	puts "\nPYLINT:\n"
	sh "pylint --rcfile=.pylintrc #{Dir.glob('../**/*.py').join(' ')}"
	puts "\nMINITEST:"
	Dir.glob('./test/test_*.rb') { |f| require f }
end

namespace :db do
	task :migrate do
		Sequel.extension :migration
		Sequel::Migrator.run(DB, 'db/migrations')
	end

	desc 'Clear the packages database'
	task :clear_packages do
		clear_packages
	end

	desc 'Update the build database with logfiles from ci-logs/'
	task :update_build do
		update_build
	end

	desc 'Clear the build database'
	task :clear_build do
		clear_build
	end

	desc 'Update the repoman database with logfiles from repo-logs/'
	task :update_repoman do
		update_repoman
	end

	desc 'Clear the repoman database'
	task :clear_repoman do
		clear_repoman
	end
end

namespace :docker do
	num_of_packages = ENV['NUM_OF_PACKAGES']
	begin
		num_of_packages = Integer(num_of_packages)
	rescue
		'Do not suppress exceptions'
	end

	desc 'Build a docker image to use with subsequent tasks'
	task :setup do
		Docker.options[:read_timeout] = 36_000
		Docker.options[:write_timeout] = 36_000

		@volume_image = Docker::Image.build('FROM busybox')
		@volume_container = Docker::Container.create(
			Image: @volume_image.id,
			Volumes: {
				'/usr/portage/packages' => {
					'/usr/portage/packages' => 'rw'
				}
			}
		)
		@volume_container.start
		@volume_container.wait(36_000)

		if ENV['CI_IMAGE'].nil?
			docker_path = File.dirname(File.expand_path(File.dirname(__FILE__)))
			@ci_image = Docker::Image.build_from_dir(docker_path)
		else
			@ci_image = Docker::Image.get(ENV['CI_IMAGE'])
		end
	end

	desc 'Remove a previously built docker image'
	task :teardown do
		@ci_image.delete if ENV['CI_IMAGE'].nil?
		@volume_container.delete(v: 1)
		@volume_image.delete
	end

	desc 'Update the packages database with new versions and targets'
	task :update_packages do
		update_packages(@ci_image)
	end

	desc 'Build test packages ( NUM_OF_PACKAGES={5,all,untested} )'
	task :run_build do
		run_ci(@volume_container, @ci_image, 'build', num_of_packages)
	end

	desc 'QA test packages ( NUM_OF_PACKAGES={5,all} )'
	task :run_repoman do
		run_ci(@volume_container, @ci_image, 'repoman', num_of_packages)
	end
end