Add dockerfiles validation
The validation takes 2 steps: a) render Dockerfile.j2's; b) verify that all images have parents except ones that are listed in base_images config parameter. This validation ignores list of components because we have repos without services (debian-base, openstack-base). Change-Id: I0fd9fb0382b860f04e12993e350c7c23fbcdfda7
This commit is contained in:
parent
cdad0ef4ac
commit
35a9378c6c
|
@ -4,6 +4,7 @@ DEFAULTS = {
|
|||
'tag': 'latest',
|
||||
'base_distro': 'debian',
|
||||
'base_tag': 'jessie',
|
||||
'base_images': ['base'],
|
||||
'maintainer': 'MOS Microservices <mos-microservices@mirantis.com>',
|
||||
'image_specs': {},
|
||||
},
|
||||
|
@ -18,6 +19,7 @@ SCHEMA = {
|
|||
'tag': {'type': 'string'},
|
||||
'base_distro': {'type': 'string'},
|
||||
'base_tag': {'type': 'string'},
|
||||
'base_images': {'type': 'array', 'items': {'type': 'string'}},
|
||||
'maintainer': {'type': 'string'},
|
||||
'image_specs': {
|
||||
'type': 'object',
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
from fuel_ccp.common import utils
|
||||
|
||||
from fuel_ccp.validation import dockerfiles
|
||||
from fuel_ccp.validation import service as service_validation
|
||||
|
||||
|
||||
def validate(components, types):
|
||||
if not types:
|
||||
types = ["service-def"]
|
||||
types = ["service-def", "dockerfiles"]
|
||||
|
||||
for validation_type in set(types):
|
||||
if validation_type == "service-def":
|
||||
component_map = utils.get_deploy_components_info()
|
||||
service_validation.validate_service_definitions(component_map,
|
||||
components)
|
||||
elif validation_type == "dockerfiles":
|
||||
dockerfiles.validate()
|
||||
else:
|
||||
raise RuntimeError(
|
||||
"Unexpected validation type: '{}'".format(validation_type)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import logging
|
||||
|
||||
from fuel_ccp import build
|
||||
from fuel_ccp import config
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def validate():
|
||||
# We ensure that all images' parents are in our repos here
|
||||
dockerfiles = build.get_dockerfiles_tree()
|
||||
LOG.info("Dockerfile tree has been built successfully, no template issues"
|
||||
" or bad image_spec's")
|
||||
# Now we ensure that no unexpected orphat (base) images are found
|
||||
# (i.e. images with malformed FROM line)
|
||||
base_images = config.CONF.images.base_images
|
||||
for dockerfile in dockerfiles.values():
|
||||
name = dockerfile['name']
|
||||
parent = dockerfile['parent']
|
||||
should_have_parent = name not in base_images
|
||||
has_parent = parent is not None
|
||||
if has_parent and not should_have_parent:
|
||||
raise RuntimeError(
|
||||
'Image {} is listed as base image but has a parent {}'.format(
|
||||
name, parent))
|
||||
if not has_parent and should_have_parent:
|
||||
raise RuntimeError(
|
||||
'Image {} doesn\'t have a parent and is not listed as base'
|
||||
' image. Malformed FROM line?'.format(name, parent))
|
||||
LOG.info("All Dockerfiles have been verified successfully")
|
Loading…
Reference in New Issue