-
Notifications
You must be signed in to change notification settings - Fork 58
Merge --base-docker-image and --docker-image flag
#585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
c061114
1321793
b70f1b8
08a7f36
605e7f1
b4d2fba
16e76b1
88f97a9
813afa0
c919384
64527de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import datetime | ||
| import os | ||
| import random | ||
| import re | ||
| import string | ||
|
|
||
| from ..utils.console import xpk_exit, xpk_print | ||
|
|
@@ -26,6 +27,11 @@ | |
| DEFAULT_DOCKER_IMAGE = 'python:3.10' | ||
| DEFAULT_SCRIPT_DIR = os.getcwd() | ||
| PLATFORM = 'linux/amd64' | ||
| CLOUD_PREFIXES = [ | ||
| r'^gcr\.io', | ||
| r'^docker\.pkg\.dev', | ||
| r'^([a-z0-9-]+)-docker\.pkg\.dev', | ||
| ] | ||
|
|
||
|
|
||
| def validate_docker_image(docker_image, args) -> int: | ||
|
|
@@ -161,50 +167,43 @@ def setup_docker_image(args) -> tuple[int, str]: | |
| 0 if successful and 1 otherwise. | ||
| Name of the docker image to use. | ||
| """ | ||
| use_base_docker_image = use_base_docker_image_or_docker_image(args) | ||
|
|
||
| docker_image = args.base_docker_image | ||
| if use_base_docker_image: | ||
| validate_docker_image_code = validate_docker_image(docker_image, args) | ||
| if validate_docker_image_code != 0: | ||
| xpk_exit(validate_docker_image_code) | ||
| build_docker_image_code, docker_image = build_docker_image_from_base_image( | ||
| args | ||
| ) | ||
| if build_docker_image_code != 0: | ||
| xpk_exit(build_docker_image_code) | ||
| else: | ||
| docker_image = args.docker_image | ||
| validate_docker_image_code = validate_docker_image(args.docker_image, args) | ||
| if validate_docker_image_code != 0: | ||
| xpk_exit(validate_docker_image_code) | ||
|
|
||
| return 0, docker_image | ||
| docker_image = args.docker_image | ||
|
|
||
| if not docker_image and args.base_docker_image: | ||
| docker_image = args.base_docker_image # fallback for legacy users | ||
|
|
||
| def use_base_docker_image_or_docker_image(args) -> bool: | ||
| """Checks for correct docker image arguments. | ||
| if not docker_image: | ||
| xpk_print( | ||
| f'No docker image specified, using default: {DEFAULT_DOCKER_IMAGE}' | ||
| ) | ||
| docker_image = DEFAULT_DOCKER_IMAGE | ||
ycchenzheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Args: | ||
| args: user provided arguments for running the command. | ||
| is_cloud_image = any( | ||
|
||
| re.match(prefix, docker_image) for prefix in CLOUD_PREFIXES | ||
| ) | ||
|
|
||
| Returns: | ||
| True if intended to use base docker image, False to use docker image. | ||
| """ | ||
| use_base_docker_image = True | ||
| # Check if (base_docker_image and script_dir) or (docker_image) is set. | ||
| if args.docker_image is not None: | ||
| if is_cloud_image: | ||
| if args.script_dir is not DEFAULT_SCRIPT_DIR: | ||
| xpk_print( | ||
| '`--script-dir` and --docker-image can not be used together. Please' | ||
| ' see `--help` command for more details.' | ||
| 'Error: `--script-dir` cannot be used with a cloud docker' | ||
| ' image.\nHint: If you need to customize the image with local' | ||
| ' scripts, use a local base image (e.g., `ubuntu:20.04`) instead of a' | ||
| ' prebuilt cloud image.' | ||
| ) | ||
| xpk_exit(1) | ||
| if args.base_docker_image is not DEFAULT_DOCKER_IMAGE: | ||
| xpk_print( | ||
| '`--base-docker-image` and --docker-image can not be used together.' | ||
| ' Please see `--help` command for more details.' | ||
| ) | ||
| xpk_exit(1) | ||
| use_base_docker_image = False | ||
| return use_base_docker_image | ||
|
|
||
| validate_code = validate_docker_image(docker_image, args) | ||
| if validate_code != 0: | ||
| xpk_exit(validate_code) | ||
|
|
||
| else: | ||
| validate_code = validate_docker_image(docker_image, args) | ||
| if validate_code != 0: | ||
| xpk_exit(validate_code) | ||
|
|
||
| build_code, docker_image = build_docker_image_from_base_image(args) | ||
| if build_code != 0: | ||
| xpk_exit(build_code) | ||
|
|
||
| return 0, docker_image | ||
Uh oh!
There was an error while loading. Please reload this page.