-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
123 lines (103 loc) · 3.11 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
require_relative 'init'
namespace :server do
desc 'Start the server'
task :start do
mkdir_p 'tmp/pids'
mkdir_p 'log'
bundle = 'bundle exec ' unless ENV['DOCKERIZED']
sh "#{bundle}puma -C config/puma.rb"
end
desc 'Restart the server'
task restart: %w[server:stop server:start]
desc 'Shut down the server'
task :stop do
sh 'kill -9 `cat tmp/pids/server.pid`'
end
end
namespace :cache do
desc 'Clean index cache pages (github, gems, featured)'
task :clean_index do
puts '>> Removing index cache pages'
load('scripts/clean_index_cache.rb')
end
desc 'Clean HTML cache of cookbooks'
task :clean_disk_html do
puts '>> Removing HTML cache pages'
system 'find public/cookbooks -atime +7 -exec rm -vrf {} \;'
end
desc 'Clean repository cache of cookbooks'
task :clean_disk_repos do
puts '>> Removing gem repositories'
system 'rm -rf repos/cookbooks/*'
end
end
DOCKER_IMAGE = 'chefdoc/chefdoc.info:latest'.freeze
namespace :docker do
desc 'Build docker image'
task :build do
sh "docker build --rm=true --force-rm -t #{DOCKER_IMAGE} ."
end
desc 'Push docker image'
task :push do
sh "docker push #{DOCKER_IMAGE}"
end
desc 'Start docker image'
task :start do
wd = ENV['WORKDIR'] || File.expand_path('data', File.dirname(__FILE__))
options = ['-d',
"--volume=#{wd}:/data",
'--name chefdoc',
'-p 8080:8080'
]
sh "rm -rf #{wd} && mkdir -p #{wd}"
sh "docker run #{options.join(' ')} #{DOCKER_IMAGE}"
end
desc 'Start docker image with redis'
task start_with_redis: [:start_redis] do
wd = ENV['WORKDIR'] || File.expand_path('data', File.dirname(__FILE__))
options = ['-d',
"--volume=#{wd}:/data",
"--env 'REDIS_HOST=redis.db'",
'--link chefdoc-redis:redis.db',
'--name chefdoc',
'-p 8080:8080'
]
sh "rm -rf #{wd} && mkdir -p #{wd}"
sh "docker run #{options.join(' ')} #{DOCKER_IMAGE}"
end
task :shell do
pid = `docker ps -q`.strip.split(/\r?\n/).first
sh "docker exec -it #{pid} /bin/bash"
end
task :git_pull do
sh 'git pull origin master'
end
desc 'Pull latest image'
task :pull do
sh "docker pull #{DOCKER_IMAGE}"
end
desc 'Stops docker image'
task stop: [:stop_redis] do
sh 'docker rm -f chefdoc' do |ok, _res|
puts 'Redis container not running' unless ok
end
end
desc 'Restart docker image'
task restart: [:stop, :start]
desc 'Pull and update'
task upgrade: [:git_pull, :pull, :restart]
desc 'Start redis docker container'
task :start_redis do
sh 'docker ps -a -q --filter=name=chefdoc-redis | wc -l | grep 1' do |ok, _res|
sh 'docker run --name chefdoc-redis -p 6379:6379 -d redis:3-alpine' unless ok
end
end
desc 'Remove redis container cleaning the database cache'
task :stop_redis do
sh 'docker rm -f chefdoc-redis' do |ok, _res|
puts 'Redis container not running' unless ok
end
end
desc 'Restart redis (remove container and start again)'
task restart_redis: [:stop_redis, :start_redis]
end