# Get the name of the current directory. project_name = "gaelk" #os.path.basename(os.path.realpath(".")) # Version used to tag the generated Docker image, using the UNIX timestamp or the given version. if "VERSION" not in os.environ: version = str(int(time.time())) else: version = os.environ["VERSION"] # Execute "docker-compose build" and abort if it fails. subprocess.check_call( ["docker-compose", "-f", "../docker-compose.yml", "build"]) # Load the services from the input docker-compose.yml file. # TODO: run parallel builds. compose_file = ComposeFile("../docker-compose.yml") # Iterate over all services that have a "build" definition. # Tag them, and initiate a push in the background. push_operations = dict() for service_name, service in compose_file.services.items(): if "build" in service: compose_image = "{}_{}".format(project_name, service_name) registry_image = "{}/{}:{}".format(registry, compose_image, version) # Re-tag the image so that it can be uploaded to the registry. subprocess.check_call(["docker", "tag", compose_image, registry_image]) # Spawn "docker push" to upload the image. push_operations[service_name] = subprocess.Popen( ["docker", "push", registry_image]) # Replace the "build" definition by an "image" definition, # using the name of the image on the registry.
print("export DOCKER_REGISTRY=localhost:5000 # use a local registry") exit(1) # Get the name of the current directory. project_name = os.path.basename(os.path.realpath(".")) # Generate a Docker image tag, using the UNIX timestamp. # (i.e. number of seconds since January 1st, 1970) version = str(int(time.time())) # Execute "docker-compose build" and abort if it fails. subprocess.check_call(["docker-compose", "-f", "docker-compose.yml", "build"]) # Load the services from the input docker-compose.yml file. # TODO: run parallel builds. compose_file = ComposeFile("docker-compose.yml") # Iterate over all services that have a "build" definition. # Tag them, and initiate a push in the background. push_operations = dict() for service_name, service in compose_file.services.items(): if "build" in service: compose_image = "{}_{}".format(project_name, service_name) registry_image = "{}/{}_{}:{}".format(registry, project_name, service_name, version) # Re-tag the image so that it can be uploaded to the registry. subprocess.check_call(["docker", "tag", compose_image, registry_image]) # Spawn "docker push" to upload the image. push_operations[service_name] = subprocess.Popen(["docker", "push", registry_image]) # Replace the "build" definition by an "image" definition, # using the name of the image on the registry. del service["build"]
#!/usr/bin/env python from common import ComposeFile import yaml config = ComposeFile() # The ambassadors need to know the service port to use. # Those ports must be declared here. ports = yaml.load(open("ports.yml")) def generate_local_addr(): last_byte = 2 while last_byte < 255: yield "127.127.0.{}".format(last_byte) last_byte += 1 for service_name, service in config.services.items(): if "links" in service: for link, local_addr in zip(service["links"], generate_local_addr()): if link not in ports: print( "Skipping link {} in service {} " "(no port mapping defined). " "Your code will probably break.".format(link, service_name) ) continue if "extra_hosts" not in service: service["extra_hosts"] = {}
#!/usr/bin/env python from common import ComposeFile, parallel_run import os import subprocess config = ComposeFile() project_name = os.path.basename(os.path.realpath(".")) # Get all services in our compose application. containers_data = subprocess.check_output([ "docker", "ps", "--filter", "label=com.docker.compose.project={}".format(project_name), "--format", '{{ .ID }} {{ .Label "com.docker.compose.service" }}', ]) # Get all existing ambassadors for this application. ambassadors_data = subprocess.check_output([ "docker", "ps", "--filter", "label=ambassador.project={}".format(project_name), "--format", '{{ .ID }} ' '{{ .Label "ambassador.container" }} ' '{{ .Label "ambassador.service" }}', ]) # Build a set of existing ambassadors. ambassadors = dict() for ambassador in ambassadors_data.split('\n'): if not ambassador: continue
#!/usr/bin/env python from common import ComposeFile import yaml config = ComposeFile() # The ambassadors need to know the service port to use. # Those ports must be declared here. ports = yaml.load(open("ports.yml")) def generate_local_addr(): last_byte = 2 while last_byte < 255: yield "127.127.0.{}".format(last_byte) last_byte += 1 for service_name, service in config.services.items(): if "links" in service: for link, local_addr in zip(service["links"], generate_local_addr()): if link not in ports: print("Skipping link {} in service {} " "(no port mapping defined). " "Your code will probably break.".format( link, service_name)) continue if "extra_hosts" not in service: service["extra_hosts"] = {} service["extra_hosts"][link] = local_addr