https://prefect.io logo
Title
d

Daniel

10/27/2022, 2:39 PM
Hello! I'm working on setting up a demo for prefect to programmatically build a deployment and run it in a docker container. I have a single script (see script in thread) that saves a storage block, an infrastructure block, builds a deployment, applies it, and attempts to run it with
run_deployment
. When running the script, I get
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
that comes from
run_deployment
and is thrown at
prefect/client/orion.py", line 1329, in read_deployment_by_name: return schemas.core.Deployment.parse_obj(response.json())
. I edited
orion.py
to add
print(response.json())
at line 1329 and then that line threw the error, but the json response still prints and it looks like a valid json response object. I'm using prefect 2.6.4. I would appreciate any help in getting the deployment working, thanks!
from log_flow import log_flow
from prefect.client import OrionClient
from prefect.deployments import Deployment, run_deployment
from prefect.filesystems import RemoteFileSystem
from prefect.infrastructure import DockerContainer


def main():
    # Storage Block
    storage = RemoteFileSystem(
        basepath='<s3://yaaam>',
        settings={
            'key': 'minioadmin',
            'secret': 'minioadmin',
            'client_kwargs': {'endpoint_url': '<minio_ip>:9000'}
        },
    )
    storage.save('minio', overwrite=True)

    # Infrastructure Block
    infrastructure = DockerContainer(
        name='log-demo',
        image='prefect-demo',
        image_pull_policy='NEVER',
    )
    infrastructure.save('log-demo', overwrite=True)

    # Deployment
    deployment = Deployment.build_from_flow(
        flow=log_flow,
        name='log-simple-docker',
        parameters={'name': 'Marvin'},
        infra_overrides={
            'env': {
                'PREFECT_LOGGING_LEVEL': 'DEBUG',
            }, 
        },
        work_queue_name='test',
        infrastructure=infrastructure,
        storage=storage,
    )
    deployment.apply()
    
    print(run_deployment(
        'log-simple-docker',
        client=OrionClient(api='<http://localhost:4200>'),
    ))

if __name__ == "__main__":
    main()