Created
September 21, 2016 20:26
-
-
Save ahsan518/30f658f82032bc2e758d4d3372364ec6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import docker | |
import os | |
import json | |
import ipdb | |
docker_client=docker.Client(base_url='unix://var/run/docker.sock') | |
class StreamLineBuildGenerator(object): | |
def __init__(self, json_data): | |
self.__dict__ = json.loads(json_data) | |
generator = docker_client.build(nocache=False, rm=True, stream=True, tag="craton-inventory:latest", | |
path='/home/vagrant/craton') | |
for line in generator: | |
try: | |
stream_line=StreamLineBuildGenerator(line) | |
if hasattr(stream_line, "error"): | |
print(stream_line.error) | |
if hasattr(stream_line, "errorDetail"): | |
if not stream_line.error == stream_line.errorDetail["message"]: | |
if hasattr(stream_line.errorDetail, "code"): | |
print("[" + stream_line.errorDetail["code"] + "] ", False) | |
print(stream_line.errorDetail["message"]) | |
except ValueError: | |
# If we are not able to deserialize the received line as JSON object, just print it out | |
print (line) | |
continue | |
# docker_client.pull('craton-inventory:latest') | |
# Build a new craton-inventory:latest image | |
container = docker_client.create_container( | |
image='craton-inventory:latest', | |
detach=True | |
) | |
docker_client.start(container) | |
# Show the list of all the containers // Similar to docker ps -a | |
docker_client.containers(all) | |
# Load the fixture data to complete initial setup | |
os.system("/home/vagrant/craton/tools/generate_fake_data.py --url http://127.0.0.1:32775/v1 --user demo --project 1 --key demo") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment