-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
215 lines (176 loc) · 5.79 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# frozen_string_literal: true
require 'confidante'
require 'ruby_terraform/output'
require 'rake_terraform'
require 'rake_docker'
require 'rake_factory/kernel_extensions'
require 'rubocop/rake_task'
require_relative 'lib/version'
configuration = Confidante.configuration
version = Version.from_file('build/version')
RakeTerraform.define_installation_tasks(
path: File.join(Dir.pwd, 'vendor', 'terraform'),
version: '1.1.7'
)
RuboCop::RakeTask.new
namespace :build do
namespace :code do
desc 'Run all checks on the build code'
task check: [:rubocop]
desc 'Attempt to automatically fix issues with the build code'
task fix: [:'rubocop:autocorrect_all']
end
end
namespace :bootstrap do
RakeTerraform.define_command_tasks(
configuration_name: 'bootstrap',
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: 'bootstrap'))
t.source_directory = 'infra/bootstrap'
t.work_directory = 'build'
t.state_file =
File.join(
Dir.pwd,
"state/bootstrap/#{args.deployment_identifier}.tfstate"
)
t.vars = configuration.vars
end
end
namespace :domain do
RakeTerraform.define_command_tasks(
configuration_name: 'domain',
argument_names: %i[deployment_identifier domain_name]
) do |t, args|
configuration = configuration
.for_overrides(domain_name: args.domain_name)
.for_scope(
{ deployment_identifier: args.deployment_identifier }
.merge(role: 'domain')
)
t.source_directory = 'infra/domain'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end
namespace :certificate do
RakeTerraform.define_command_tasks(
configuration_name: 'certificate',
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: 'certificate'))
t.source_directory = 'infra/certificate'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end
namespace :network do
RakeTerraform.define_command_tasks(
configuration_name: 'network',
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: 'network'))
t.source_directory = 'infra/network'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end
%i[web worker].each do |role|
namespace "#{role}_image_repository" do
RakeTerraform.define_command_tasks(
configuration_name: "#{role} image repository",
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: "#{role}-repository"))
t.source_directory = 'infra/image_repository'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end
namespace "#{role}_image" do
RakeDocker.define_image_tasks(
image_name: "concourse-#{role}",
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: "#{role}-repository"))
t.work_directory = 'build/images'
t.copy_spec = [
"src/concourse-#{role}/Dockerfile"
]
t.create_spec = [
{ content: version.to_s, to: 'VERSION' },
{ content: version.to_docker_tag, to: 'TAG' }
]
t.repository_name = "infrablocks-examples/concourse-#{role}"
t.repository_url = dynamic do
RubyTerraform::Output.for(
name: 'repository_url',
source_directory: 'infra/image_repository',
work_directory: 'build',
backend_config: configuration.backend_config
)
end
t.credentials = dynamic do
RakeDocker::Authentication::ECR.new do |c|
c.region = configuration.region
c.registry_id = RubyTerraform::Output.for(
name: 'registry_id',
source_directory: 'infra/image_repository',
work_directory: 'build',
backend_config: configuration.backend_config
)
end.call
end
t.tags = [version.to_docker_tag, 'latest']
end
end
end
namespace :database do
RakeTerraform.define_command_tasks(
configuration_name: 'database',
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: 'database'))
t.source_directory = 'infra/database'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end
namespace :cluster do
RakeTerraform.define_command_tasks(
configuration_name: 'cluster',
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_scope(args.to_h.merge(role: 'cluster'))
t.source_directory = 'infra/cluster'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end
namespace :services do
RakeTerraform.define_command_tasks(
configuration_name: 'concourse services',
argument_names: [:deployment_identifier]
) do |t, args|
configuration = configuration
.for_overrides(version_number: version.to_docker_tag)
.for_scope(args.to_h.merge(role: 'services'))
t.source_directory = 'infra/services'
t.work_directory = 'build'
t.backend_config = configuration.backend_config
t.vars = configuration.vars
end
end