6
6
import pulumi
7
7
import pulumi_aws as aws
8
8
import pulumi_docker as docker
9
+ import pulumi_docker_build as docker_build
9
10
10
11
# Get the password to use for Redis from the pulumi config
11
12
config = pulumi .Config ()
18
19
# Creating a VPC and a public subnet
19
20
app_vpc = aws .ec2 .Vpc ("app-vpc" , cidr_block = "172.31.0.0/16" , enable_dns_hostnames = True )
20
21
21
- app_vpc_subnet = aws .ec2 .Subnet ("app-vpc-subnet" , cidr_block = "172.31.32.0/20" , vpc_id = app_vpc .id )
22
+ app_vpc_subnet = aws .ec2 .Subnet (
23
+ "app-vpc-subnet" , cidr_block = "172.31.32.0/20" , vpc_id = app_vpc .id
24
+ )
22
25
23
26
# Creating a gateway to the web for the VPC
24
27
app_gateway = aws .ec2 .InternetGateway ("app-gateway" , vpc_id = app_vpc .id )
143
146
port = redis_port ,
144
147
protocol = "TCP" ,
145
148
target_type = "ip" ,
146
- stickiness = aws .lb .TargetGroupStickinessArgs (
147
- enabled = False ,
148
- type = "lb_cookie" ,
149
- ),
150
149
vpc_id = app_vpc .id ,
151
150
)
152
151
166
165
port = redis_port ,
167
166
protocol = "TCP" ,
168
167
default_actions = [
169
- aws .lb .ListenerDefaultActionArgs (type = "forward" , target_group_arn = redis_targetgroup .arn )
168
+ aws .lb .ListenerDefaultActionArgs (
169
+ type = "forward" , target_group_arn = redis_targetgroup .arn
170
+ )
170
171
],
171
172
)
172
173
235
236
port = 80 ,
236
237
protocol = "TCP" ,
237
238
target_type = "ip" ,
238
- stickiness = aws .lb .TargetGroupStickinessArgs (
239
- enabled = False ,
240
- type = "lb_cookie" ,
241
- ),
242
239
vpc_id = app_vpc .id ,
243
240
)
244
241
258
255
port = 80 ,
259
256
protocol = "TCP" ,
260
257
default_actions = [
261
- aws .lb .ListenerDefaultActionArgs (type = "forward" , target_group_arn = flask_targetgroup .arn )
258
+ aws .lb .ListenerDefaultActionArgs (
259
+ type = "forward" , target_group_arn = flask_targetgroup .arn
260
+ )
262
261
],
263
262
)
264
263
@@ -271,17 +270,25 @@ def get_registry_info(rid):
271
270
parts = decoded .split (":" )
272
271
if len (parts ) != 2 :
273
272
raise Exception ("Invalid credentials" )
274
- return docker .ImageRegistry (creds .proxy_endpoint , parts [0 ], parts [1 ])
273
+ return docker_build .RegistryArgs (
274
+ address = creds .proxy_endpoint , username = parts [0 ], password = parts [1 ]
275
+ )
275
276
276
277
277
278
app_registry = app_ecr_repo .registry_id .apply (get_registry_info )
278
279
279
- flask_image = docker .Image (
280
+ flask_image_dockerbuild = docker_build .Image (
280
281
"flask-dockerimage" ,
281
- image_name = app_ecr_repo .repository_url ,
282
- build = "./frontend" ,
283
- skip_push = False ,
284
- registry = app_registry ,
282
+ tags = [
283
+ app_ecr_repo .repository_url .apply (
284
+ lambda repository_url : f"{ repository_url } :latest"
285
+ ),
286
+ ],
287
+ context = docker_build .BuildContextArgs (
288
+ location = "./frontend" ,
289
+ ),
290
+ push = True ,
291
+ registries = [app_registry ],
285
292
)
286
293
287
294
# Creating a task definition for the Flask instance.
@@ -298,15 +305,17 @@ def get_registry_info(rid):
298
305
[
299
306
{
300
307
"name" : "flask-container" ,
301
- "image" : flask_image . image_name ,
308
+ "image" : flask_image_dockerbuild . ref ,
302
309
"memory" : 512 ,
303
310
"essential" : True ,
304
- "portMappings" : [{"containerPort" : 80 , "hostPort" : 80 , "protocol" : "tcp" }],
311
+ "portMappings" : [
312
+ {"containerPort" : 80 , "hostPort" : 80 , "protocol" : "tcp" }
313
+ ],
305
314
"environment" : [ # The Redis endpoint we created is given to Flask, allowing it to communicate with the former
306
315
{"name" : "REDIS" , "value" : redis_endpoint ["host" ]},
307
316
{
308
317
"name" : "REDIS_PORT" ,
309
- "value" : redis_endpoint ["port" ]. apply ( lambda x : str ( x )),
318
+ "value" : pulumi . Output . concat ( str ( redis_endpoint ["port" ])),
310
319
},
311
320
{"name" : "REDIS_PWD" , "value" : redis_password },
312
321
],
0 commit comments