Coder Social home page Coder Social logo

Comments (5)

mitant avatar mitant commented on August 29, 2024 1

here's some updated snippets to help you. Good luck! I'm just trying this repo out right now but it looks promising in terms of what I want to do.

def __init__(self, parser):
    self.args = parser.parse_args()
    self.loud = self.args.loud
    self.log = self.configure_and_get_logger()
    self.cli = docker.from_env()
    self.api = docker.APIClient()
def build_task(self, directory_name):
    self.log.info(f"Handling {directory_name}")
    try:
        self.copy_libraries(directory_name)
        self.log.info("Building image. (run script with -l to see docker logs)")
        build_logs = self.api.build(path=f'./docker/{directory_name}', tag=directory_name, rm=True)

        while True:
            try:
                output = self.parse_output(next(build_logs))
                if self.loud:
                    self.log.info(output)
            except StopIteration:
                self.log.info("Image built.")
                break
    finally:
        self.remove_libraries(directory_name)

def parse_output(self, raw) -> str:
    output = json.loads(raw)
    try:
        return output['stream'].strip('\n')
    except KeyError:
        return raw

from airflow_project.

mitant avatar mitant commented on August 29, 2024

The interface for docker-py has changed.
self.cli.images.build only returns an Image now
Update build_task to ignore the output of self.cli.images.build and this will let you build using this script
This means you won't get the build output anymore

If you want the build output looks like you need to get the APIClient from docker-py and call the low level build there. The low level build returns a stream of output but no Image object. The image object isn't used anyways..

from airflow_project.

pedrovgp avatar pedrovgp commented on August 29, 2024

from airflow_project.

is2co avatar is2co commented on August 29, 2024

You can be done using the low-level APIs given in docker-py as follows:
`

def build_task(self, directory_name):
    self.log.info(f'Handling {directory_name}')
    try:
        self.copy_libraries(directory_name)
        self.log.info('Building image. (run script with -l to see docker logs)')

        docker_client = docker.Client(base_url='unix://var/run/docker.sock', timeout=10)
        build_logs = docker_client.build(path=f'./docker/{directory_name}', tag=directory_name, rm=True)
        for output in build_logs:
            json_output = json.loads(output)
            if self.loud and 'stream' in json_output:
                self.log.info(json_output['stream'].strip('\n'))
        self.log.info('Docker image built.')

        # build_logs = self.api.build(path=f'./docker/{directory_name}', tag=directory_name, rm=True)

        # while True:
        #     try:
        #         output = self.parse_output(next(build_logs))
        #         if self.loud:
        #             self.log.info(output)
        #     except StopIteration:
        #         self.log.info('Image built.')
        #         break
    finally:
        self.remove_libraries(directory_name)

`

from airflow_project.

tomaszdudek7 avatar tomaszdudek7 commented on August 29, 2024

Is this still an issue? Could any of you make a tiny pull request fixing this? :)

from airflow_project.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.