prefect.utilities.dockerutils
¶
BuildError
¶
Bases: Exception
Raised when a Docker build fails
Source code in prefect/utilities/dockerutils.py
121 122 |
|
ImageBuilder
¶
An interface for preparing Docker build contexts and building images
Source code in prefect/utilities/dockerutils.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
add_line
¶
Add a line to this image's Dockerfile
Source code in prefect/utilities/dockerutils.py
254 255 256 |
|
add_lines
¶
Add lines to this image's Dockerfile
Source code in prefect/utilities/dockerutils.py
258 259 260 |
|
assert_has_file
¶
Asserts that the given file or directory will be copied into the container at the given path
Source code in prefect/utilities/dockerutils.py
384 385 386 387 388 389 390 |
|
assert_has_line
¶
Asserts that the given line is in the Dockerfile
Source code in prefect/utilities/dockerutils.py
325 326 327 328 329 330 331 332 333 |
|
assert_line_absent
¶
Asserts that the given line is absent from the Dockerfile
Source code in prefect/utilities/dockerutils.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
assert_line_after
¶
Asserts that the second line appears after the first line
Source code in prefect/utilities/dockerutils.py
380 381 382 |
|
assert_line_before
¶
Asserts that the first line appears before the second line
Source code in prefect/utilities/dockerutils.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
build
¶
Build the Docker image from the current state of the ImageBuilder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pull
|
bool
|
True to pull the base image during the build |
False
|
stream_progress_to
|
Optional[TextIO]
|
an optional stream (like sys.stdout, or an io.TextIO) that will collect the build output as it is reported by Docker |
None
|
Returns:
Type | Description |
---|---|
str
|
The image ID |
Source code in prefect/utilities/dockerutils.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
copy
¶
Copy a file to this image
Source code in prefect/utilities/dockerutils.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
PushError
¶
Bases: Exception
Raised when a Docker image push fails
Source code in prefect/utilities/dockerutils.py
393 394 |
|
build_image
¶
Builds a Docker image, returning the image ID
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
Path
|
the root directory for the Docker build context |
required |
dockerfile
|
str
|
the path to the Dockerfile, relative to the context |
'Dockerfile'
|
tag
|
Optional[str]
|
the tag to give this image |
None
|
pull
|
bool
|
True to pull the base image during the build |
False
|
stream_progress_to
|
Optional[TextIO]
|
an optional stream (like sys.stdout, or an io.TextIO) that will collect the build output as it is reported by Docker |
None
|
Returns:
Type | Description |
---|---|
str
|
The image ID |
Source code in prefect/utilities/dockerutils.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
docker_client
¶
Get the environmentally-configured Docker client
Source code in prefect/utilities/dockerutils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
format_outlier_version_name
¶
Formats outlier docker version names to pass packaging.version.parse
validation
- Current cases are simple, but creates stub for more complicated formatting if eventually needed.
- Example outlier versions that throw a parsing exception:
- "20.10.0-ce" (variant of community edition label)
- "20.10.0-ee" (variant of enterprise edition label)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version
|
str
|
raw docker version value |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
value that can pass |
Source code in prefect/utilities/dockerutils.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
generate_default_dockerfile
¶
Generates a default Dockerfile used for deploying flows. The Dockerfile is written to a temporary file and yielded. The temporary file is removed after the context manager exits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
-
|
context
|
The context to use for the Dockerfile. Defaults to the current working directory. |
required |
Source code in prefect/utilities/dockerutils.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
get_prefect_image_name
¶
Get the Prefect image name matching the current Prefect and Python versions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefect_version
|
str
|
An optional override for the Prefect version. |
None
|
python_version
|
str
|
An optional override for the Python version; must be at the minor level e.g. '3.9'. |
None
|
flavor
|
str
|
An optional alternative image flavor to build, like 'conda' |
None
|
Source code in prefect/utilities/dockerutils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
parse_image_tag
¶
Parse Docker Image String
- If a tag exists, this function parses and returns the image registry and tag, separately as a tuple.
- Example 1: 'prefecthq/prefect:latest' -> ('prefecthq/prefect', 'latest')
- Example 2: 'hostname.io:5050/folder/subfolder:latest' -> ('hostname.io:5050/folder/subfolder', 'latest')
- Supports parsing Docker Image strings that follow Docker Image Specification v1.1.0
- Image building tools typically enforce this standard
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of Docker Image |
required |
Return
Source code in prefect/utilities/dockerutils.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
push_image
¶
Pushes a local image to a Docker registry, returning the registry-qualified tag for that image
This assumes that the environment's Docker daemon is already authenticated to the given registry, and currently makes no attempt to authenticate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_id
|
str
|
a Docker image ID |
required |
registry_url
|
str
|
the URL of a Docker registry |
required |
name
|
str
|
the name of this image |
required |
tag
|
str
|
the tag to give this image (defaults to a short representation of the image's ID) |
None
|
stream_progress_to
|
Optional[TextIO]
|
an optional stream (like sys.stdout, or an io.TextIO) that will collect the build output as it is reported by Docker |
None
|
Returns:
Type | Description |
---|---|
str
|
A registry-qualified tag, like my-registry.example.com/my-image:abcdefg |
Source code in prefect/utilities/dockerutils.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
split_repository_path
¶
Splits a Docker repository path into its namespace and repository components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repository_path
|
str
|
The Docker repository path to split. |
required |
Returns:
Type | Description |
---|---|
Tuple[Optional[str], str]
|
Tuple[Optional[str], str]: A tuple containing the namespace and repository components. - namespace (Optional[str]): The Docker namespace, combining the registry and organization. None if not present. - repository (Optionals[str]): The repository name. |
Source code in prefect/utilities/dockerutils.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
to_run_command
¶
Convert a process-style list of command arguments to a single Dockerfile RUN instruction.
Source code in prefect/utilities/dockerutils.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|