Hello everyone, I’m using an ECS Agent and S3 stor...
# ask-community
g
Hello everyone, I’m using an ECS Agent and S3 storage and I’d like to know how I can specify the docker image in the Run Config (ECSRun) at runtime. I tried to get the image to use from an environment variable but it does not work. I need that because I’d like to use different docker images in staging and production environments. Any suggestion?
j
Here's what I did to use different Docker images in production and staging:
Copy code
from prefect import Flow as PrefectFlow

def base_image():
    if os.environ.get('ENVIRONMENT') == 'STAGING':
        return '<http://gcr.io/pict-app/our-prefect-staging|gcr.io/pict-app/our-prefect-staging>'
    else:
        return '<http://gcr.io/pict-app/our-prefect|gcr.io/pict-app/our-prefect>'

class OurFlow(PrefectFlow):
    def __init__(self, name, **kwargs):
        super().__init__(name, storage=Docker(registry_url='<http://gcr.io/pict-app|gcr.io/pict-app>',
                                              image_name=name,
                                              base_image=base_image(),
                                              path=path_in_docker(inspect.stack()[1].filename),
                                              stored_as_script=True))
        self.run_config = UniversalRun(labels=[label()])
        self.executor=DaskExecutor(address='<tcp://dask-scheduler:8786>', debug=True)
I have separate build processes in production and staging that build the Docker images and then register the flows. None of it happens at runtime. At build time, the Prefect "project" determines which flow is for staging and which is for production. A label is used to separate production from staging at runtime.