diff --git a/samcli/commands/package/package_context.py b/samcli/commands/package/package_context.py index 48b4b777df..aaeb6635b5 100644 --- a/samcli/commands/package/package_context.py +++ b/samcli/commands/package/package_context.py @@ -22,9 +22,9 @@ import boto3 import click import docker -from docker.constants import DEFAULT_DOCKER_API_VERSION from samcli.commands.package.exceptions import PackageFailedError +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable from samcli.lib.package.artifact_exporter import Template from samcli.lib.package.code_signer import CodeSigner @@ -121,7 +121,7 @@ def run(self): ) ecr_client = boto3.client("ecr", config=get_boto_config_with_user_agent(region_name=region_name)) - docker_client = docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + docker_client = docker.from_env(version=DOCKER_MIN_API_VERSION) s3_uploader = S3Uploader( s3_client, self.s3_bucket, self.s3_prefix, self.kms_key_id, self.force_upload, self.no_progressbar diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index 5dbfcab965..50ddbd74e0 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -8,13 +8,13 @@ import pathlib from typing import List, Optional, Dict, cast, NamedTuple import docker -from docker.constants import DEFAULT_DOCKER_API_VERSION import docker.errors from aws_lambda_builders import ( RPC_PROTOCOL_VERSION as lambda_builders_protocol_version, ) from aws_lambda_builders.builder import LambdaBuilder from aws_lambda_builders.exceptions import LambdaBuilderError +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.build.build_graph import FunctionBuildDefinition, LayerBuildDefinition, BuildGraph from samcli.lib.build.build_strategy import ( DefaultBuildStrategy, @@ -157,7 +157,7 @@ def __init__( self._parallel = parallel self._mode = mode self._stream_writer = stream_writer if stream_writer else StreamWriter(stream=osutils.stderr(), auto_flush=True) - self._docker_client = docker_client if docker_client else docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self._docker_client = docker_client if docker_client else docker.from_env(version=DOCKER_MIN_API_VERSION) self._deprecated_runtimes = DEPRECATED_RUNTIMES self._colored = Colored() diff --git a/samcli/lib/constants.py b/samcli/lib/constants.py new file mode 100644 index 0000000000..ec9dd1d3f5 --- /dev/null +++ b/samcli/lib/constants.py @@ -0,0 +1 @@ +DOCKER_MIN_API_VERSION = "1.35" diff --git a/samcli/lib/package/ecr_uploader.py b/samcli/lib/package/ecr_uploader.py index 4c6e714b81..f2d4371407 100644 --- a/samcli/lib/package/ecr_uploader.py +++ b/samcli/lib/package/ecr_uploader.py @@ -9,7 +9,6 @@ import botocore import click import docker -from docker.constants import DEFAULT_DOCKER_API_VERSION from docker.errors import APIError, BuildError from samcli.commands.package.exceptions import ( @@ -18,6 +17,7 @@ DockerPushFailedError, ECRAuthorizationError, ) +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.docker.log_streamer import LogStreamer, LogStreamError from samcli.lib.package.image_utils import tag_translation from samcli.lib.utils.osutils import stderr @@ -36,7 +36,7 @@ class ECRUploader: def __init__( self, docker_client, ecr_client, ecr_repo, ecr_repo_multi, no_progressbar=False, tag="latest", stream=stderr() ): - self.docker_client = docker_client if docker_client else docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self.docker_client = docker_client if docker_client else docker.from_env(version=DOCKER_MIN_API_VERSION) self.ecr_client = ecr_client self.ecr_repo = ecr_repo self.ecr_repo_multi = ecr_repo_multi diff --git a/samcli/lib/package/image_utils.py b/samcli/lib/package/image_utils.py index 5fefbfcd53..b5a0a6bf83 100644 --- a/samcli/lib/package/image_utils.py +++ b/samcli/lib/package/image_utils.py @@ -2,10 +2,10 @@ Image artifacts based utilities """ import docker -from docker.constants import DEFAULT_DOCKER_API_VERSION from docker.errors import APIError, NullResource from samcli.commands.package.exceptions import DockerGetLocalImageFailedError +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.package.utils import is_ecr_url SHA_CHECKSUM_TRUNCATION_LENGTH = 12 @@ -36,7 +36,7 @@ def tag_translation(image, docker_image_id=None, gen_tag="latest"): if not docker_image_id: try: - docker_client = docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + docker_client = docker.from_env(version=DOCKER_MIN_API_VERSION) docker_image_id = docker_client.images.get(image).id except APIError as ex: raise DockerGetLocalImageFailedError(str(ex)) from ex diff --git a/samcli/lib/sync/flows/image_function_sync_flow.py b/samcli/lib/sync/flows/image_function_sync_flow.py index cf9ff34871..f313fa6661 100644 --- a/samcli/lib/sync/flows/image_function_sync_flow.py +++ b/samcli/lib/sync/flows/image_function_sync_flow.py @@ -5,9 +5,9 @@ import docker from docker.client import DockerClient -from docker.constants import DEFAULT_DOCKER_API_VERSION from samcli.lib.build.app_builder import ApplicationBuilder, ApplicationBuildResult +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.package.ecr_uploader import ECRUploader from samcli.lib.providers.provider import Stack from samcli.lib.sync.flows.function_sync_flow import FunctionSyncFlow, wait_for_function_update_complete @@ -70,7 +70,7 @@ def __init__( def _get_docker_client(self) -> DockerClient: """Lazy instantiates and returns the docker client""" if not self._docker_client: - self._docker_client = docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self._docker_client = docker.from_env(version=DOCKER_MIN_API_VERSION) return self._docker_client def _get_ecr_client(self) -> Any: diff --git a/samcli/lib/utils/file_observer.py b/samcli/lib/utils/file_observer.py index 77928007ef..8ccf25cd9a 100644 --- a/samcli/lib/utils/file_observer.py +++ b/samcli/lib/utils/file_observer.py @@ -11,7 +11,6 @@ import docker from docker import DockerClient -from docker.constants import DEFAULT_DOCKER_API_VERSION from docker.errors import ImageNotFound from docker.types import CancellableStream from watchdog.events import FileSystemEvent, FileSystemEventHandler, PatternMatchingEventHandler @@ -19,6 +18,7 @@ from watchdog.observers.api import BaseObserver, ObservedWatch from samcli.cli.global_config import Singleton +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.utils.hash import dir_checksum, file_checksum from samcli.lib.utils.packagetype import IMAGE, ZIP from samcli.local.lambdafn.config import FunctionConfig @@ -258,7 +258,7 @@ def __init__(self, on_change: Callable) -> None: """ self._observed_images: Dict[str, str] = {} self._input_on_change: Callable = on_change - self.docker_client: DockerClient = docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self.docker_client: DockerClient = docker.from_env(version=DOCKER_MIN_API_VERSION) self.events: CancellableStream = self.docker_client.events(filters={"type": "image"}, decode=True) self._images_observer_thread: Optional[Thread] = None self._lock: Lock = threading.Lock() diff --git a/samcli/lib/utils/system_info.py b/samcli/lib/utils/system_info.py index 03c6173b45..4ecd0f56b7 100644 --- a/samcli/lib/utils/system_info.py +++ b/samcli/lib/utils/system_info.py @@ -53,11 +53,11 @@ def _gather_docker_info() -> str: import contextlib import docker - from docker.constants import DEFAULT_DOCKER_API_VERSION + from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.local.docker.utils import is_docker_reachable - with contextlib.closing(docker.from_env(version=DEFAULT_DOCKER_API_VERSION)) as client: + with contextlib.closing(docker.from_env(version=DOCKER_MIN_API_VERSION)) as client: if is_docker_reachable(client): return cast(str, client.version().get("Version", "Not available")) return "Not available" diff --git a/samcli/local/docker/container.py b/samcli/local/docker/container.py index a6205c8e26..e70f7c2a1f 100644 --- a/samcli/local/docker/container.py +++ b/samcli/local/docker/container.py @@ -13,9 +13,9 @@ import docker import requests -from docker.constants import DEFAULT_DOCKER_API_VERSION from docker.errors import NotFound as DockerNetworkNotFound +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.utils.retry import retry from samcli.lib.utils.tar import extract_tarfile from samcli.local.docker.effective_user import ROOT_USER_ID, EffectiveUser @@ -112,7 +112,7 @@ def __init__( self._logs_thread = None # Use the given Docker client or create new one - self.docker_client = docker_client or docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self.docker_client = docker_client or docker.from_env(version=DOCKER_MIN_API_VERSION) # Runtime properties of the container. They won't have value until container is created or started self.id = None diff --git a/samcli/local/docker/lambda_image.py b/samcli/local/docker/lambda_image.py index 14ba00d06a..285e1b81e7 100644 --- a/samcli/local/docker/lambda_image.py +++ b/samcli/local/docker/lambda_image.py @@ -12,13 +12,13 @@ from typing import Optional import docker -from docker.constants import DEFAULT_DOCKER_API_VERSION from samcli.commands.local.cli_common.user_exceptions import ( DockerDistributionAPIError, ImageBuildException, ) from samcli.commands.local.lib.exceptions import InvalidIntermediateImageError +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.utils.architecture import has_runtime_multi_arch_image from samcli.lib.utils.packagetype import IMAGE, ZIP from samcli.lib.utils.stream_writer import StreamWriter @@ -124,7 +124,7 @@ def __init__(self, layer_downloader, skip_pull_image, force_image_build, docker_ self.layer_downloader = layer_downloader self.skip_pull_image = skip_pull_image self.force_image_build = force_image_build - self.docker_client = docker_client or docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self.docker_client = docker_client or docker.from_env(version=DOCKER_MIN_API_VERSION) self.invoke_images = invoke_images def build(self, runtime, packagetype, image, layers, architecture, stream=None, function_name=None): diff --git a/samcli/local/docker/manager.py b/samcli/local/docker/manager.py index 45db09bce7..a035003bb0 100644 --- a/samcli/local/docker/manager.py +++ b/samcli/local/docker/manager.py @@ -7,8 +7,8 @@ import threading import docker -from docker.constants import DEFAULT_DOCKER_API_VERSION +from samcli.lib.constants import DOCKER_MIN_API_VERSION from samcli.lib.utils.stream_writer import StreamWriter from samcli.local.docker import utils from samcli.local.docker.container import Container @@ -36,7 +36,7 @@ def __init__(self, docker_network_id=None, docker_client=None, skip_pull_image=F self.skip_pull_image = skip_pull_image self.docker_network_id = docker_network_id - self.docker_client = docker_client or docker.from_env(version=DEFAULT_DOCKER_API_VERSION) + self.docker_client = docker_client or docker.from_env(version=DOCKER_MIN_API_VERSION) self.do_shutdown_event = do_shutdown_event self._lock = threading.Lock()