| 353 | |
| 354 | |
| 355 | def process_dockerfile(dockerfile, path): |
| 356 | if not dockerfile: |
| 357 | return (None, None) |
| 358 | |
| 359 | abs_dockerfile = dockerfile |
| 360 | if not os.path.isabs(dockerfile): |
| 361 | abs_dockerfile = os.path.join(path, dockerfile) |
| 362 | if constants.IS_WINDOWS_PLATFORM and path.startswith( |
| 363 | constants.WINDOWS_LONGPATH_PREFIX): |
| 364 | normpath = os.path.normpath( |
| 365 | abs_dockerfile[len(constants.WINDOWS_LONGPATH_PREFIX):]) |
| 366 | abs_dockerfile = f'{constants.WINDOWS_LONGPATH_PREFIX}{normpath}' |
| 367 | if (os.path.splitdrive(path)[0] != os.path.splitdrive(abs_dockerfile)[0] or |
| 368 | os.path.relpath(abs_dockerfile, path).startswith('..')): |
| 369 | # Dockerfile not in context - read data to insert into tar later |
| 370 | with open(abs_dockerfile) as df: |
| 371 | return ( |
| 372 | f'.dockerfile.{random.getrandbits(160):x}', |
| 373 | df.read() |
| 374 | ) |
| 375 | |
| 376 | # Dockerfile is inside the context - return path relative to context root |
| 377 | if dockerfile == abs_dockerfile: |
| 378 | # Only calculate relpath if necessary to avoid errors |
| 379 | # on Windows client -> Linux Docker |
| 380 | # see https://github.com/docker/compose/issues/5969 |
| 381 | dockerfile = os.path.relpath(abs_dockerfile, path) |
| 382 | return (dockerfile, None) |