thousands-art-55778
05/24/2021, 10:49 AMdef create_image(args):
...
...
image = docker.Image(
"image",
image_name=ecr_repo.repository_url,
build=docker.DockerBuild(
context="folder",
dockerfile=path.join("folder", "Dockerfile"),
),
registry=app_registry,
)
# Export the base and specific version image name.
pulumi.export('baseImageName', image.base_image_name)
pulumi.export('fullImageName', image.image_name)
return image
main.py
image = create_image(args)
aws.ecs.TaskDefinition("task-definition",
family="task-definition-family",
cpu=512
memory=1024,
network_mode="awsvpc",
requires_compatibilities=["FARGATE"],
execution_role_arn=app_exec_role.arn,
task_role_arn=app_task_role.arn,
container_definitions=json.dumps([{
"name": "test",
"image": image
"memory": 1024,
"essential": True
}])
pulumi stacks
. Is that a good practice?proud-art-41399
05/24/2021, 12:11 PMapply
(https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply) to transform an output (Docker image name) into another value (container definition).
Here's an example:
task_definition = aws.ecs.TaskDefinition('my-task',
family='my-task',
cpu='512',
memory='1024',
network_mode='awsvpc',
requires_compatibilities=['FARGATE'],
execution_role_arn=role.arn,
container_definitions=pulumi.Output.all(
image.image_name, log_group.name
).apply(
lambda args: json.dumps([{
'name': 'my-app',
'image': args[0],
'portMappings': [{
'containerPort': 80,
'hostPort': 80,
'protocol': 'tcp'
}],
'logConfiguration': {
'logDriver': 'awslogs',
'options': {
'awslogs-group': args[1],
'awslogs-stream-prefix': 'my-app'
}
}
}])
)
)
thousands-art-55778
05/24/2021, 3:25 PMimage = create_image(args)
aws.ecs.TaskDefinition("task-definition",
family="task-definition-family",
cpu=512
memory=1024,
network_mode="awsvpc",
requires_compatibilities=["FARGATE"],
execution_role_arn=app_exec_role.arn,
task_role_arn=app_task_role.arn,
container_definitions=json.dumps([{
"name": "test",
"image": image.apply(lambda arg: f"{arg}"),
"memory": 1024,
"essential": True
}])
Naturally , it won't work. Do you have any explanations about the reason? I mean, I know that it is wrong, but how could I better understand the why?