Skip to content

Commit

Permalink
Fix: Force docker version to match 4.2's default version (aws#5305)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Fuss <[email protected]>
  • Loading branch information
2 people authored and moelasmar committed Jun 13, 2023
1 parent 677d8dd commit bc445e2
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions samcli/commands/package/package_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOCKER_MIN_API_VERSION = "1.35"
4 changes: 2 additions & 2 deletions samcli/lib/package/ecr_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/package/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/sync/flows/image_function_sync_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/utils/file_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

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
from watchdog.observers import Observer
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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/utils/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions samcli/local/docker/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samcli/local/docker/lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions samcli/local/docker/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bc445e2

Please sign in to comment.