Exemplo n.º 1
0
# 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.
Exemplo n.º 2
0
#!/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