Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 1 addition & 83 deletions ebcli/containers/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,100 +35,18 @@
DOCKER_TLS_VERIFY = 'DOCKER_TLS_VERIFY'


def supported_docker_installed():
"""
Return whether proper Docker version is installed.
:return: bool
"""

try:
clean_version = remove_leading_zeros_from_version(commands.version())
return Version(clean_version) >= Version(SUPPORTED_DOCKER_V)
except (OSError, CommandError):
return False


def validate_docker_installed():
_validate_docker_installed(supported_docker_installed())


def _validate_docker_installed(supported_docker_installed):
versions = {'boot2docker-version': SUPPORTED_BOOT2DOCKER_V,
'docker-version': SUPPORTED_DOCKER_V}
err = strings['local.dockernotpresent'].format(**versions)

if not supported_docker_installed:
raise CommandError(err)


def container_ip():
"""
Return the ip address that local containers are or will be running on.
:return str
"""
try:
return _boot2docker_ip()
except OSError:
return LOCALHOST


def _boot2docker_ip():
args = ['boot2docker', 'ip']
return utils.exec_cmd_quiet(args).strip()


def setup(env=os.environ):
validate_docker_installed()
boot2docker_setup(env)


def boot2docker_setup(env=os.environ):
if not heuristics.is_boot2docker_installed():
return
LOG.debug('Ensuring boot2docker VM has initialized, started and the client is set up...')

_init_boot2docker()
if not _is_boot2docker_running():
_start_boot2docker()

boot2docker_certs_path = os.path.sep.join(['.boot2docker', 'certs',
'boot2docker-vm'])

if DOCKER_HOST not in env:
env[DOCKER_HOST] = 'tcp://{}:2376'.format(_boot2docker_ip())

if DOCKER_CERT_PATH not in env:
env[DOCKER_CERT_PATH] = os.path.join(fileoperations.get_home(),
boot2docker_certs_path)
if DOCKER_TLS_VERIFY not in env:
env[DOCKER_TLS_VERIFY] = '1'

LOG.debug('DOCKER_HOST is set to ' + env[DOCKER_HOST])
LOG.debug('DOCKER_CERT_PATH is set to ' + env[DOCKER_CERT_PATH])
LOG.debug('DOCKER_TLS_VERIFY is set to ' + env[DOCKER_TLS_VERIFY])
LOG.debug('PATH is set to ' + env.get('PATH', ''))
return LOCALHOST


def is_windows():
return 'win32' in str(sys.platform).lower()


def _is_boot2docker_running():
return _get_boot2docker_status() == BOOT2DOCKER_RUNNING


def _get_boot2docker_status():
return utils.exec_cmd_quiet(['boot2docker', 'status']).strip()


def _start_boot2docker():
utils.exec_cmd_quiet(['boot2docker', 'start'])


def _init_boot2docker():
utils.exec_cmd_quiet(['boot2docker', 'init'])


def remove_leading_zeros_from_version(version_string):
# regex explaination: remove zeroes if both:
# 1. the start of string (major version) or following a '.'
Expand Down
51 changes: 5 additions & 46 deletions ebcli/controllers/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import argparse
import os
import time
import yaml

from ebcli.core import io, fileoperations, hooks
from ebcli.core.abstractcontroller import AbstractBaseController
from ebcli.lib import elasticbeanstalk, utils, iam
Expand Down Expand Up @@ -239,7 +239,7 @@ def do_command(self):
cname = cname or get_environment_cname(env_name, provided_env_name, tier)
key_name = key_name or commonops.get_default_keyname()
vpc = self.form_vpc_object(tier, single)
elb_type = elb_type or get_elb_type_from_customer(interactive, single, tier,cfg_flag_used=cfg)
elb_type = elb_type or get_elb_type_from_customer(interactive, single, tier)
shared_lb = get_shared_load_balancer(interactive, elb_type, platform, shared_lb, vpc)
shared_lb_port = shared_lb_port or shared_lb_ops.get_shared_lb_port_from_customer(interactive, shared_lb)
enable_spot = enable_spot or spotops.get_spot_request_from_customer(interactive)
Expand Down Expand Up @@ -533,48 +533,8 @@ def get_cname_from_customer(env_name):
break
return cname

def check_elb_type_from_configs(use_saved_config=False):
"""
Checks if the ELB type is present from either the .ebextensions or saved_configs directories.
:param use_saved_config: Boolean indicating if --cfg flag was used.
:return: True, else False.
"""

# If --cfg flag is used, prioritize checking saved_configs first
if use_saved_config:
saved_configs_dir = './.elasticbeanstalk/saved_configs'
if os.path.exists(saved_configs_dir):
for config_file in os.listdir(saved_configs_dir):
with open(os.path.join(saved_configs_dir, config_file), 'r') as f:
try:
config = yaml.safe_load(f)
option_settings = config.get('OptionSettings', {})
for namespace, setting in option_settings.items():
if namespace == 'aws:elasticbeanstalk:environment' and setting.get('LoadBalancerType'):
return True
except yaml.YAMLError:
raise ValueError(f"Malformed YAML in file {config_file} in saved_configs.")

else:
# Then check in .ebextensions
ebextensions_dir = './.ebextensions'
if os.path.exists(ebextensions_dir):
for config_file in os.listdir(ebextensions_dir):
with open(os.path.join(ebextensions_dir, config_file), 'r') as f:
try:
config = yaml.safe_load(f)
option_settings = config.get('option_settings', [])
for setting in option_settings:
if setting.get('namespace') == 'aws:elasticbeanstalk:environment' and setting.get('option_name') == 'LoadBalancerType':
if setting.get('value'):
return True
except yaml.YAMLError:
raise ValueError(f"Malformed YAML in file {config_file} in .ebextensions.")


return False

def get_elb_type_from_customer(interactive, single, tier, cfg_flag_used=False):
def get_elb_type_from_customer(interactive, single, tier):
"""
Prompt customer to specify the ELB type if operating in the interactive mode and
on a load-balanced environment.
Expand All @@ -586,9 +546,8 @@ def get_elb_type_from_customer(interactive, single, tier, cfg_flag_used=False):
:param tier: the tier type of the environment
:return: selected ELB type which is one among ['application', 'classic', 'network']
"""
elb_type_is_configured = check_elb_type_from_configs(use_saved_config=cfg_flag_used)
if single or (tier and not tier.is_webserver()) or elb_type_is_configured:
return
if single or (tier and not tier.is_webserver()):
return
elif not interactive:
return elb_names.APPLICATION_VERSION

Expand Down
3 changes: 0 additions & 3 deletions ebcli/controllers/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Meta:
dict(action='store_true', help=flag_text['local.run.insecuressl']))]

def do_command(self):
compat.setup()
cnt = factory.make_container(self.app.pargs.envvars,
self.app.pargs.port,
self.app.pargs.allow_insecure_ssl)
Expand Down Expand Up @@ -93,7 +92,6 @@ class Meta:
arguments = []

def do_command(self):
compat.setup()
cnt = factory.make_container()
cnt_viewmodel = ContainerViewModel.from_container(cnt)
localops.open_webpage(cnt_viewmodel)
Expand All @@ -111,7 +109,6 @@ class Meta:
arguments = []

def do_command(self):
compat.setup()
cnt = factory.make_container()
cnt_viewmodel = ContainerViewModel.from_container(cnt)
localops.print_container_details(cnt_viewmodel)
Expand Down
21 changes: 10 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
botocore>1.23.41,<1.35.0
cement==2.8.2
colorama>=0.2.5,<0.4.4 # use the same range that 'docker-compose' uses
botocore>=1.35.0,<1.36.0
cement==2.10.14
colorama>=0.4.6,<0.5
pathspec==0.10.1
python-dateutil>=2.1,<3.0.0 # use the same range that 'botocore' uses
requests>=2.31
setuptools >= 20.0
semantic_version == 2.8.5
six>=1.11.0,<1.17.0
termcolor == 1.1.0
wcwidth>=0.1.7,<0.2.0
PyYAML>=5.3.1,<6.1 # use the same range that 'aws-cli' uses. This is also compatible with 'docker-compose'
urllib3>=1.26.5,<2 #1.26.5 fix CVE-2021-33503
requests>=2.31,<3
setuptools>=20.0
semantic_version>=2.10.0,<2.11
termcolor>=2.4.0,<3
wcwidth>=0.2.13,<0.3
PyYAML>=5.3.1,<6.1 # use the same range that 'aws-cli' uses
urllib3>=1.26.5,<2
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

}
if not sys.platform.startswith('win'):
requires.append('blessed>=1.9.5')
requires.append('blessed>=1.20.0')


setup_options = dict(
Expand Down Expand Up @@ -66,10 +66,12 @@
'Natural Language :: English',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
),
entry_points={
'console_scripts': [
Expand Down
5 changes: 1 addition & 4 deletions tests/test_dependencies_mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from pkg_resources import get_distribution, parse_version


if pip_version != '21.1':
raise RuntimeError('You need pip==21.1 to check for dependency incompatibilities.')

try:
from pip._internal.operations.check import (
check_package_set,
Expand All @@ -41,7 +38,7 @@ def color_green(message):
def collect_package_requirements_by_requirement_name(req_name, package_set):
required_by = dict()
for pkg_name, package in package_set.items():
for req in package.requires:
for req in package.dependencies:
if req.name.lower() == req_name.lower():
required_by[pkg_name] = req.specifier

Expand Down
Loading
Loading