Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
Deploy bug fixes and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Houseknecht committed May 24, 2017
1 parent 857b847 commit ae419b4
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
before_install:
- sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports universe'
- sudo apt-get update -qq
- sudo apt-get install -y shellcheck
# - sudo apt-get install -y shellcheck
- pip install --upgrade setuptools

script:
Expand Down
4 changes: 2 additions & 2 deletions conductor-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#https://github.com/ansible/ansible/archive/devel.tar.gz
ansible>=2.3.0
https://github.com/ansible/ansible/archive/devel.tar.gz
# ansible>=2.3.0
https://github.com/openshift/openshift-restclient-python/archive/master.tar.gz#egg=openshift-1.0.0
PyYAML>=3.12
docker-compose>=1.7
Expand Down
29 changes: 16 additions & 13 deletions container/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from container.config import AnsibleContainerConductorConfig
from container.utils import list_to_ordereddict

from collections import OrderedDict
from logging import config
LOGGING = {
'version': 1,
Expand Down Expand Up @@ -63,6 +62,8 @@ class HostCommand(object):
'deploy': 'Deploy your built images into production'
}

project_path = os.getcwd()

def subcmd_common_parsers(self, parser, subparser, cmd):
if cmd in ('build', 'run', 'deploy', 'push', 'restart', 'stop', 'destroy'):
subparser.add_argument('--with-volumes', '-v', action='store', nargs='+',
Expand Down Expand Up @@ -91,29 +92,26 @@ def subcmd_common_parsers(self, parser, subparser, cmd):
help=u'If authentication with the registry is required, provide a valid password.',
dest='password', default=None)
subparser.add_argument('--push-to', action='store',
help=(u'Name of a registry defined in container.yml or the actual URL of the registry, '
u'including the namespace. If passing a URL, an example would be: '
u'"https://registry.example.com:5000/myproject"'),
help=(u'Name of a registry defined in container.yml, or a registry URL. When '
u'providing a URL, include the repository or project namespace.'),
dest='push_to', default=None)
subparser.add_argument('--tag', action='store',
help=u'Tag the images before pushing.',
dest='tag', default=None)


def subcmd_init_parser(self, parser, subparser):
subparser.add_argument('--server', '-s', action='store',
default='https://galaxy.ansible.com/',
help=u'Use a different Galaxy server URL')
subparser.add_argument('project', nargs='?', action='store',
help=u'Use a project template instead of making a '
u'blank project from an Ansible Container project '
u'from Ansible Galaxy.')
help=(u'Rather than starting with a blank project, use a project template '
u'from an Ansible Container project downloaded from the Ansible Galaxy '
u'web site.'))
subparser.add_argument('--force', '-f', action='store_true',
help=u'Overrides the requirement that init be run'
u'in an empty directory, for example'
u'if a virtualenv exists in the directory.')


def subcmd_build_parser(self, parser, subparser):
subparser.add_argument('--flatten', action='store_true',
help=u'By default, Ansible Container will add a single '
Expand Down Expand Up @@ -236,7 +234,7 @@ def __call__(self):
default='docker')
parser.add_argument('--project-path', '-p', action='store', dest='base_path',
help=u'Specify a path to your project. Defaults to '
u'current working directory.', default=os.getcwd())
u'current working directory.', default=self.project_path)
parser.add_argument('--project-name', '-n', action='store', dest='project_name',
help=u'Specify an alternate name for your project. Defaults '
u'to the directory it lives in.', default=None)
Expand Down Expand Up @@ -264,14 +262,19 @@ def __call__(self):
LOGGING['loggers']['container']['level'] = 'DEBUG'
config.dictConfig(LOGGING)

vargs = vars(args)
if not vargs['project_name']:
# Set the default project_name
vargs['project_name'] = os.path.basename(vargs['base_path'])

try:
getattr(core, u'hostcmd_{}'.format(args.subcommand))(**vars(args))
getattr(core, u'hostcmd_{}'.format(args.subcommand))(**vargs)
except exceptions.AnsibleContainerAlreadyInitializedException as e:
logger.error('{0}'.format(e), exc_info=False)
logger.error("Project already initialized. Use the --force option.")
sys.exit(1)
except exceptions.AnsibleContainerNotInitializedException:
logger.error('No Ansible Container project data found - do you need to '
'run "ansible-container init"?', exc_info=False)
'run "ansible-container init"?', exc_info=False)
sys.exit(1)
except exceptions.AnsibleContainerNoAuthenticationProvidedException:
logger.error('No authentication provided, unable to continue', exc_info=False)
Expand Down
16 changes: 13 additions & 3 deletions container/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,28 @@ class AnsibleContainerConfig(Mapping):
base_path = None

@container.host_only
def __init__(self, base_path, var_file=None, engine_name=None):
def __init__(self, base_path, var_file=None, engine_name=None, project_name=None):
self.base_path = base_path
self.var_file = var_file
self.engine_name = engine_name
self.config_path = path.join(self.base_path, 'container.yml')
self.project_name = project_name
self.set_env('prod')

@property
def deployment_path(self):
dep_path = self.get('settings', yaml.compat.ordereddict()).get('deployment_output_path',
path.join(self.base_path, 'ansible-deployment/'))
return path.normpath(path.abspath(path.expanduser(dep_path)))
return path.normpath(path.abspath(path.expanduser(path.expandvars(dep_path))))

@property
def image_namespace(self):
# When pushing images or deploying, we need to know the registry namespace
namespace = self.project_name
if self.engine_name in ('k8s', 'openshift'):
if self._config.get('settings', {}).get('k8s_namespace', {}).get('name'):
namespace = self._config['settings']['k8s_namespace']['name']
return namespace

def set_env(self, env):
"""
Expand Down Expand Up @@ -273,7 +283,7 @@ def _process_top_level_sections(self):
self._config['settings'] = self._config.get('settings', yaml.compat.ordereddict())
for section in ['volumes', 'registries']:
logger.debug('Processing section...', section=section)
setattr(self, section, self._process_section(self._config.get(section, yaml.compat.ordereddict())))
setattr(self, section, dict(self._process_section(self._config.get(section, yaml.compat.ordereddict()))))

def _process_services(self):
services = yaml.compat.ordereddict()
Expand Down
Loading

0 comments on commit ae419b4

Please sign in to comment.