Deploy and run a flow in a Docker container with runtime package installation using uv. Demonstrates using EXTRA_PIP_PACKAGES to install dependencies at runtime.
()
| 28 | |
| 29 | |
| 30 | def test_docker_deploy(): |
| 31 | """ |
| 32 | Deploy and run a flow in a Docker container with runtime package installation using uv. |
| 33 | Demonstrates using EXTRA_PIP_PACKAGES to install dependencies at runtime. |
| 34 | """ |
| 35 | try: |
| 36 | subprocess.check_call( |
| 37 | [ |
| 38 | "uv", |
| 39 | "run", |
| 40 | "--isolated", |
| 41 | "prefect", |
| 42 | "work-pool", |
| 43 | "create", |
| 44 | "test-docker-pool", |
| 45 | "-t", |
| 46 | "docker", |
| 47 | ], |
| 48 | stdout=sys.stdout, |
| 49 | stderr=sys.stderr, |
| 50 | ) |
| 51 | |
| 52 | dockerfile = Path("docker-deploy.Dockerfile") |
| 53 | |
| 54 | dockerfile.write_text( |
| 55 | dedent( |
| 56 | """ |
| 57 | FROM prefecthq/prefect:3-latest |
| 58 | COPY integration-tests/test_docker_deploy.py /opt/prefect/integration-tests/test_docker_deploy.py |
| 59 | """ |
| 60 | ) |
| 61 | ) |
| 62 | |
| 63 | flow_that_needs_pandas.deploy( |
| 64 | name="docker-demo-deployment", |
| 65 | work_pool_name="test-docker-pool", |
| 66 | job_variables={ |
| 67 | "env": {"EXTRA_PIP_PACKAGES": "pandas"}, |
| 68 | "image": "prefect-integration-test-docker-deploy", |
| 69 | }, |
| 70 | image=DockerImage( |
| 71 | name="prefect-integration-test-docker-deploy", |
| 72 | dockerfile=str(dockerfile), |
| 73 | ), |
| 74 | build=True, |
| 75 | push=False, |
| 76 | ) |
| 77 | |
| 78 | dockerfile.unlink() |
| 79 | |
| 80 | flow_run = run_deployment( |
| 81 | "flow-that-needs-pandas/docker-demo-deployment", |
| 82 | timeout=0, |
| 83 | ) |
| 84 | |
| 85 | # Execute the flow run |
| 86 | subprocess.check_call( |
| 87 | [ |
nothing calls this directly
no test coverage detected
searching dependent graphs…