Example #1
0
    def _get_docker_image_version(self, docker_image, verbose_name):
        client = DockerIndex()
        available_versions = client.get_latest_version_tags(docker_image)
        cache_version = ask(
            question='Which {} version do you want to use?'.format(
                verbose_name),
            choices=list(available_versions.keys()) + ['custom'])

        if cache_version == 'custom':
            cache_version = ask(
                question='Specify {} version'.format(verbose_name),
                validator=DockerImageVersionValidator(docker_image),
            )

        cache_image_flavor = False
        if len(available_versions.get(cache_version, [])) != 0:
            default_choices = 'alpine' if 'alpine' in available_versions[
                cache_version] else 'No'
            flavor_response = ask(
                question='Do you want to use a separate flavor?'.format(
                    verbose_name),
                choices=available_versions[cache_version] + ['No'],
                default=default_choices,
            )
            cache_image_flavor = flavor_response if flavor_response != 'No' else False

        versioned_docker_image = "{}:{}".format(docker_image, cache_version)
        if cache_image_flavor:
            versioned_docker_image = "{}-{}".format(versioned_docker_image,
                                                    cache_image_flavor)
        print('Using docker image: {}'.format(
            color(versioned_docker_image, Colors.HEADER)))

        return versioned_docker_image
Example #2
0
    def _get_cache_image(self):
        cache_type = get_cache_type(self.django_settings)
        verbose_cache_type = verbose_name_cache_mapping.get(cache_type)

        use_settings_cache = False
        if cache_type:
            use_settings_db_response = ask(
                question='Do you want to use {} as your database?'.format(
                    verbose_cache_type),
                default='Yes',
                choices=['Yes', 'No'])
            use_settings_cache = use_settings_db_response == 'Yes'

        if not cache_type or not use_settings_cache:
            cache_choices = verbose_name_cache_mapping
            cache_choices[None] = 'None'  # TODO: Don't do this
            cache_type = ask(
                question='What cache are you using in production?',
                default='None',
                choices=cache_choices,
                newline=True)
            if cache_type is None:
                return None, None
            verbose_cache_type = verbose_name_cache_mapping.get(cache_type)

        cache_docker_image = self._get_docker_image_version(
            cache_type, verbose_cache_type)

        return cache_docker_image, cache_type
Example #3
0
    def _get_database_image(self):
        database_type = get_database_type(self.django_settings)
        verbose_db_type = verbose_name_db_mapping.get(database_type)

        use_settings_db = False
        if database_type:
            use_settings_db_response = ask(
                question='Do you want to use {} as your database?'.format(
                    verbose_db_type),
                default='Yes',
                choices=['Yes', 'No'])
            use_settings_db = use_settings_db_response == 'Yes'

        if not database_type or not use_settings_db:
            database_type = ask(
                question='What database are you using in production?',
                default='PostgreSQL',
                choices=verbose_name_db_mapping,
                newline=True)
            verbose_db_type = verbose_name_db_mapping.get(database_type)

        database_docker_image = self._get_docker_image_version(
            database_type, verbose_db_type)

        return database_docker_image, database_type
Example #4
0
    def _get_python_version(self, supported_python_versions):
        if not supported_python_versions:
            print(
                color(
                    "Python is currently not supported by the docker image handler",
                    Colors.WARNING))
            return None
        supported_python_versions = sorted(supported_python_versions)

        version_info = sys.version_info
        running_python_version = "{}.{}".format(version_info[0],
                                                version_info[1])
        default_choice = running_python_version

        if running_python_version not in supported_python_versions:
            print(
                color(
                    "Note that the version ({}) you are currently running is not supported by the Dockerize right now"
                    .format(running_python_version), Colors.WARNING))

            default_choice = supported_python_versions[-1]

        return ask(
            question='Which version of Python is the project using?',
            default=default_choice,
            choices=supported_python_versions,
        )
Example #5
0
    def _get_application_server(self):
        application_server_mapping = {'uwsgi': 'uWSGI', 'gunicorn': 'Gunicorn'}

        return ask(
            question='Which application server is used in production?',
            default='uWSGI',
            choices=application_server_mapping,
        )
Example #6
0
    def _get_base_image(self):
        docker_image = ask(question='What docker image be based on?',
                           default='ubuntu:16.04',
                           validator=DockerImageValidator(),
                           newline=False)
        print('Using docker image: {}'.format(
            color(docker_image, Colors.HEADER)))
        operating_system = docker_image.split(':')[0]

        return docker_image, operating_system
Example #7
0
    def _get_wsgi_file(self, base_dir):
        search_dir = base_dir

        # Try to guess in which folder the WSGI file is in if Django is enabled
        if self.django_settings and self.django_settings_path:
            search_dir += '/{}'.format(self.django_settings_path.split('.')[0])

        # Find all wsgi files
        wsgi_settings = find_filename('wsgi.py', search_dir)

        if not wsgi_settings:
            return wsgi_settings

        if len(wsgi_settings) > 1:
            # Handle multiple files
            return ask(
                question=
                'More then one WSGI settings file detected, which should be used?',
                choices=wsgi_settings,
            )
        else:
            # Do not ask if we only found one file
            return wsgi_settings[0]