-
Notifications
You must be signed in to change notification settings - Fork 23
/
Rakefile
85 lines (70 loc) · 2.13 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
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path('./lib', __dir__)
# 初始化一些文件和目录,否则无法 docker 构建,构建的内容不会引入 docker
FileUtils.cp('config/hpr.example.yml', 'config/hpr.yml') unless File.file?('config/hpr.yml')
FileUtils.mkdir('logs') unless Dir.exist?('logs')
require 'fileutils'
require 'hpr'
namespace :db do
desc 'Load table to db file'
task :setup do
Hpr.connect_database
ActiveRecord::Schema.define do
create_table :repositories, if_not_exists: true do |t|
t.string :name, null: false
t.string :url, null: false
t.string :mirror_url
t.integer :gitlab_project_id
t.integer :status, default: 0
t.datetime :scheduled_at
t.timestamps
end
end
end
desc 'Drop db file'
task :drop do
File.delete Hpr.db_file
end
desc 'Drop db file and load it agin'
task :reset do
Rake::Task['db:reset'].invoke
Rake::Task['db:setup'].invoke
end
end
# development tasks
unless Hpr.producton?
require 'rubocop/rake_task'
require 'awesome_print'
namespace :test do
task :release_version do
puts Hpr.release_info
end
task :create do
puts "create test repo"
Hpr::Repository.create name: 'icyleaf-halite', url: '[email protected]:icyleaf/halite.git'
end
end
RuboCop::RakeTask.new
IMAGE_NAME = 'icyleafcn/hpr'
IMAGE_WITH_VERSION = "#{IMAGE_NAME}:#{Hpr::VERSION}"
namespace :docker do
desc 'Create docker image'
task :build do
system %(docker build -t #{IMAGE_WITH_VERSION} .)
end
desc 'Push hpr to docker hub'
task :publish do
system %(docker tag #{IMAGE_WITH_VERSION} #{IMAGE_NAME}:latest)
system %(docker push #{IMAGE_WITH_VERSION})
system %(docker push #{IMAGE_NAME}:latest)
end
desc 'Run a new hpr container'
task :run do
system %(docker run --rm -v `pwd`/config/hpr.example.yml:/app/config/hpr.yml -p 18848:8848 -p 16379:6379 #{IMAGE_WITH_VERSION})
end
desc 'Run a new hpr console'
task :console do
system %(docker run --rm -it #{IMAGE_WITH_VERSION} bash)
end
end
end