-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
110 lines (83 loc) · 2.48 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
require 'dotenv/load'
require 'active_support/all'
require 'colorize'
require 'open3'
require_relative 'lib/util'
include Util
apps = %w[taskd znc]
apps.each do |app|
namespace app do
repository = "katsuya94/#{app}"
image = "#{repository}:latest"
namespace :docker do
task :build do
system 'docker', 'build', app, '-t', image
end
task :push do
system 'docker', 'push', image
end
task :pull do
system 'docker', 'pull', image
end
task :shell do
exec 'docker', 'run', '-it', image, '/bin/sh'
end
end
task :deploy do
ansible_playbook "#{app}/deploy.yml"
end
task :bounce do
ansible_playbook "#{app}/bounce.yml"
end
end
end
namespace :ca do
conf = 'files/pki/openssl.conf'
ca_key = 'files/pki/private/cakey.pem'
ca_cert = 'files/pki/cacert.pem'
task :root do
system 'openssl', 'req', '-x509', '-newkey', 'rsa:4096', '-keyout',
ca_key, '-new', '-nodes', '-sha256', '-subj', '/CN=Adrien Katsuya Tateno',
'-out', ca_cert
encrypt ca_key
encrypt ca_cert
end
task :csr, %i[file_root common_name] do |_t, args|
args.with_defaults(common_name: File.basename(args[:file_root]))
csr = "#{args[:file_root]}.csr"
key = "#{args[:file_root]}.key.pem"
system 'openssl', 'req', '-newkey', 'rsa:4096', '-keyout', key, '-new',
'-nodes', '-out', csr, '-subj', "/CN=#{args[:common_name]}"
end
task :sign, [:file_root] do |_t, args|
cert = "#{args[:file_root]}.cert.pem"
csr = "#{args[:file_root]}.csr"
with_decrypted ca_cert, ca_key do
system 'openssl', 'ca', '-config', conf, '-in', csr, '-out', cert,
'-notext', '-batch'
end
serial = File.read('files/pki/serial.old').chomp
serial_cert = "files/pki/newcerts/#{serial}.pem"
encrypt cert
encrypt serial_cert
end
task :revoke, [:serial] do |_t, args|
serial_cert = "files/pki/newcerts/#{args[:serial]}.pem"
crl = 'files/pki/crl.pem'
with_decrypted ca_cert, ca_key, serial_cert do
system 'openssl', 'ca', '-config', conf, '-revoke', serial_cert
system 'openssl', 'ca', '-config', conf, '-gencrl', '-out', crl
end
encrypt crl
end
end
task :facts do
ansible_module 'setup'
end
task :setup do
ansible_playbook 'setup.yml'
end
task :ssh, [:host] do |_t, args|
exec 'ssh', "#{ENV['PB_USER']}@#{args[:host]}", "-i", ENV['PB_PRIVATE_KEY']
end
task default: apps.flat_map { |app| ["#{app}:build", "#{app}:push"] }