forked from codeforkanazawa-org/ha4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile.deploy
87 lines (79 loc) · 2.01 KB
/
Rakefile.deploy
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
SUDO = ENV['SUDO'] || ''
NOCACHE = ENV['NOCACHE'] || ''
DOCKER = [SUDO, 'docker'].join(' ')
APP_NAME = 'ha4go'.freeze
ROLE_FRONT = 'front'
ROLE_JOB = 'job'
ROLE_DB = 'db'
ROLE_BASE = 'base'
NAMES = {
ROLE_BASE => "#{APP_NAME}-#{ROLE_BASE}",
ROLE_FRONT => "#{APP_NAME}-#{ROLE_FRONT}",
ROLE_JOB => "#{APP_NAME}-#{ROLE_FRONT}", # FRONTと同じ
ROLE_DB => "#{APP_NAME}-#{ROLE_DB}"
}.freeze
TAGS = {
ROLE_BASE => '1.0',
ROLE_FRONT => '1.0',
ROLE_JOB => '1.0',
ROLE_DB => '1.0'
}.freeze
FILES = {
ROLE_BASE => "Dockerfile.#{ROLE_BASE}",
ROLE_FRONT => "Dockerfile.#{ROLE_FRONT}",
ROLE_JOB => "Dockerfile.#{ROLE_FRONT}", # FRONTと同じ
ROLE_DB => "Dockerfile.#{ROLE_DB}"
}
RELEASE_TAG = "release".freeze
DOCKER_OPTIONS = {
'PRODUCT' => {
ROLE_BASE => '',
ROLE_FRONT => "-d -p 3000:3000 --env-file=.env --log-opt max-size=100m --log-opt max-file=3 -v `pwd`/public/uploads:/myapp/public/uploads",
ROLE_JOB => '-d --env-file=.env',
ROLE_DB => "-d -v `pwd`/mysql:/var/lib/mysql -p 3306:3306"
},
'DEBUG' => {
ROLE_FRONT => '-d -p 3000:3000 --env-file=.env',
ROLE_JOB => '',
ROLE_DB => "-d -v `pwd`/mysql:/var/lib/mysql -p 3306:3306"
}
}
DOCKER_COMMAND = {
'PRODUCT' => {
ROLE_JOB => 'bundle exec rake jobs:work'
},
'DEBUG' => {
ROLE_JOB => 'bundle exec rake jobs:work'
}
}
class Cmd
def self.gen(values)
values.join(' ')
end
end
desc "build[base/db/front/job]"
task :build, [:role] do |_t, a|
r = a[:role]
sh Cmd.gen(
[
DOCKER,
'build',
NOCACHE,
"-t #{NAMES[r]}:#{TAGS[r]}",
"-f #{FILES[r]}",
'./'
]
)
end
desc 'run[<role>,<base>,<`docker-machine ip default`>]'
task :run, [:role, :local, :docker_ip] do |_t, a|
r = a[:role]
e = a[:local] || 'DEBUG'
sh Cmd.gen([
DOCKER,
'run',
"#{DOCKER_OPTIONS[e][r]}",
"#{NAMES[r]}:#{TAGS[r]}",
"#{DOCKER_COMMAND[e][r]}"
])
end