Ken Farr
06/28/2021, 10:17 PM...
cft_container = CreateContainer(image_name="twodub:v0.4")
cft_start = StartContainer()
cft_logs = GetContainerLogs()
cft_status_code = WaitOnContainer()
@task
def set_cft_container_command(cft_name: str, account_id: str):
logger = prefect.context.get("logger")
ret = f"python -m twodub cft install --cft-name {cft_name} --account-id {account_id}"
new_container.command = ret # <--- Referencing new_container before declared
<http://logger.info|logger.info>(f"command is: '{ret}'")
return ret
with Flow("install-cft-flow") as flow:
cft_name = Parameter("CFT Name")
account_id = Parameter("Account ID")
scc = set_cft_container_command(cft_name, account_id)
# I'm creating a new version of this Task here with bind
# I suspect there is a cleaner way than this, but it wasn't
# apparent to me in the documentation
#
# If I did not do this, then the container would be created
# before the set_cft_container_command was called and the
# correct command argument would not be set
new_container = cft_container().bind(upstream_tasks=[scc])
start_container = cft_start(container_id=new_container)
...
Kevin Kho
06/28/2021, 10:21 PMnew_container = CreateContainer(scc)
instead. You can initialize tasks inside the Flow context.new_container = cft_container(scc)
new_container = CreateContainer(image_name="twodub:v0.4")(scc)
Ken Farr
06/28/2021, 10:25 PMcommand
based on the two Parameters being passed in. If you take a peek at set_cft_container_command
the only purpose of this task is to build the container command and set it. BUT since the run() on CreateContainer doesn't take a command
I have to do it on the Task instead.
It's creating a weird circular logic that I think can be fixed by expanding the CreateImage API to accept the command
at execution instead of at creationKevin Kho
06/28/2021, 10:28 PMcommand
in the run methodKen Farr
06/28/2021, 10:29 PMcommand
when the flow executes, not when the flow is created. Such is my understanding.Kevin Kho
06/28/2021, 10:33 PMwith Flow("install-cft-flow") as flow:
cft_name = Parameter("CFT Name")
account_id = Parameter("Account ID")
scc = set_cft_container_command(cft_name, account_id)
CreateContainer()(image_name="twodub:v0.4", command=scc)
Ken Farr
06/28/2021, 10:36 PMKevin Kho
06/28/2021, 10:37 PM