Ejemplo n.º 1
0
    def update_app_images(self, db, app):
        """
        Update images for app from docker registry. If we know
        about existing containers that reference a newly fetched
        image, we attach the containers to the image 
        """
        logging.info("Fetching images for {} from {} ...".format(
            app.name, self._registry_url))
        images = DockerWrapper.list_images(self._registry_url, app.name,
                                           self._registry_user,
                                           self._registry_password)
        for image_info in images:
            image = Image.get(db, image_info['layer'])
            if image:
                logging.info(
                    "Found existing image {}, updating tag to {}".format(
                        image_info['layer'], image_info['name']))
                image.tag = image_info['name']
            else:
                logging.info("Found new image {}, setting tag to {}".format(
                    image_info['layer'], image_info['name']))
                image = Image(id=image_info['layer'], tag=image_info['name'])

            for container in self.containers_for_app_image(
                    db, app.name, image.tag):
                logging.info(
                    "Found container {} with state: [{}], associated with image: {}, linking"
                    .format(container.id, container.state, image.id))
                image.containers.append(container)

            app.images.append(image)
            db.add(image)
            db.add(app)
        db.commit()
Ejemplo n.º 2
0
    def update_app_images(self, db, app):
        """
        Update images for app from docker registry. If we know
        about existing containers that reference a newly fetched
        image, we attach the containers to the image 
        """
        logging.info("Fetching images for {} from {} ...".format(app.name, self._registry_url))
        images = DockerWrapper.list_images(
            self._registry_url, app.name, self._registry_user, self._registry_password)
        for image_info in images:
            image = Image.get(db, image_info['layer'])
            if image:
                logging.info("Found existing image {}, updating tag to {}".format(image_info['layer'], image_info['name']))
                image.tag = image_info['name']
            else:
                logging.info("Found new image {}, setting tag to {}".format(image_info['layer'], image_info['name']))
                image = Image(id=image_info['layer'], tag=image_info['name'])

            for container in self.containers_for_app_image(db, app.name, image.tag):
                logging.info("Found container {} with state: [{}], associated with image: {}, linking".format(
                    container.id, container.state, image.id
                ))
                image.containers.append(container)
            
            app.images.append(image)
            db.add(image)
            db.add(app)
        db.commit()