I am able to build docker image using python sdk. if the dockerfile is available on my local machine.
client = docker.from_env()
image, build_log = client.images.build(path = "./", tag=image_name,rm=True)
Now, My docker files will be maintained in github repository, I should pull them and build the images. python sdk doc says build method accepts path or file objects.
I was able to read the content of the docker file from github using pyGithub (API3) repository
g = Github(base_url=url, login_or_token=accessToken, verify=False)
dmc = g.get_organization(org_name)
repo = dmc.get_repo(repoName)
contents = repo.get_contents(dockerfile_name, "master")
I am not sure how to convert above contents object(ContentFile.ContentFile) to a python file object so that I can use it to build the image as below
client = docker.from_env()
image, build_log = client.images.build(fileobj = contents_file_obj, tag=image_name,rm=True)