diff --git a/portainer/app/build.py b/portainer/app/build.py index 53b9026..81e9779 100644 --- a/portainer/app/build.py +++ b/portainer/app/build.py @@ -37,6 +37,8 @@ def args(parser): help="Multiple tags to apply to the image once built") group.add_argument("--container-image", default="jpetazzo/dind", help="Docker image to run the portainer executor in") + group.add_argument("--insecure", default=False, action="store_true", + help="Enable pulling/pushing of images with insecure registries") # Arguments for the staging filesystem group = parser.add_argument_group("fs") @@ -75,7 +77,8 @@ def main(args): container_image=args.container_image, stream=args.stream, docker_host=args.docker_host, - verbose=args.verbose + verbose=args.verbose, + insecure_registries=args.insecure ) driver = pesos.scheduler.PesosSchedulerDriver( diff --git a/portainer/app/executor.py b/portainer/app/executor.py index 35c0c70..55d4ac9 100644 --- a/portainer/app/executor.py +++ b/portainer/app/executor.py @@ -70,10 +70,13 @@ def launch_docker_daemon(): logger.info("Launching docker daemon subprocess") env = dict(os.environ) - env["DOCKER_DAEMON_ARGS"] = "-g %s" % ( + env["DOCKER_DAEMON_ARGS"] = " -g %s" % ( os.path.join(env["MESOS_DIRECTORY"], "docker") ) + for reg in build_task.daemon.insecure_registries: + env["DOCKER_DAEMON_ARGS"] += " --insecure-registry %s" % reg + # Use the `wrapdocker` script included in our docker image proc = subprocess.Popen(["/usr/local/bin/wrapdocker"], env=env) @@ -90,7 +93,7 @@ def launch_docker_daemon(): proc.wait() - if not build_task.HasField("docker_host"): + if not build_task.daemon.HasField("docker_host"): daemon_thread = threading.Thread(target=launch_docker_daemon) daemon_thread.setDaemon(True) daemon_thread.start() diff --git a/portainer/app/scheduler.py b/portainer/app/scheduler.py index e2d3163..6da2489 100644 --- a/portainer/app/scheduler.py +++ b/portainer/app/scheduler.py @@ -38,7 +38,8 @@ class Scheduler(mesos.interface.Scheduler): def __init__(self, tasks, executor_uri, cpu_limit, mem_limit, push_registry, staging_uri, stream=False, verbose=False, repository=None, - pull_registry=None, docker_host=None, container_image=None): + pull_registry=None, docker_host=None, container_image=None, + insecure_registries=False): self.executor_uri = executor_uri self.cpu = float(cpu_limit) @@ -51,6 +52,7 @@ def __init__(self, tasks, executor_uri, cpu_limit, mem_limit, push_registry, self.repository = repository self.docker_host = docker_host self.container_image = container_image + self.insecure_registries = insecure_registries self.queued_tasks = [] for path, tags in tasks: @@ -308,8 +310,13 @@ def handle_exception(e): else: build_task.dockerfile = dockerfile.build() + # Configure properties on the docker daemon if self.docker_host: - build_task.docker_host = self.docker_host + build_task.daemon.docker_host = self.docker_host + if self.insecure_registries: + for registry in [self.pull_registry, self.push_registry]: + if registry: + build_task.daemon.insecure_registries.append(registry) # Pull out the repository from the dockerfile try: diff --git a/portainer/proto/portainer_pb2.py b/portainer/proto/portainer_pb2.py index 40ad523..48ed617 100644 --- a/portainer/proto/portainer_pb2.py +++ b/portainer/proto/portainer_pb2.py @@ -13,7 +13,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( name='proto/portainer.proto', package='portainer', - serialized_pb='\n\x15proto/portainer.proto\x12\tportainer\"\x91\x01\n\tBuildTask\x12%\n\x05image\x18\x01 \x02(\x0b\x32\x16.portainer.DockerImage\x12\x0f\n\x07\x63ontext\x18\x02 \x01(\t\x12\x12\n\ndockerfile\x18\x06 \x01(\t\x12\x0e\n\x06stream\x18\x05 \x01(\x08\x12\x13\n\x0b\x64ocker_host\x18\x03 \x01(\t\x12\x13\n\x0b\x64ocker_args\x18\x04 \x01(\t\"[\n\x0b\x44ockerImage\x12+\n\x08registry\x18\x02 \x01(\x0b\x32\x19.portainer.DockerRegistry\x12\x12\n\nrepository\x18\x01 \x02(\t\x12\x0b\n\x03tag\x18\x03 \x03(\t\"4\n\x0e\x44ockerRegistry\x12\x10\n\x08hostname\x18\x01 \x02(\t\x12\x10\n\x04port\x18\x02 \x01(\r:\x02\x38\x30') + serialized_pb='\n\x15proto/portainer.proto\x12\tportainer\"\x90\x01\n\tBuildTask\x12%\n\x05image\x18\x01 \x02(\x0b\x32\x16.portainer.DockerImage\x12\'\n\x06\x64\x61\x65mon\x18\x07 \x02(\x0b\x32\x17.portainer.DockerDaemon\x12\x0f\n\x07\x63ontext\x18\x02 \x01(\t\x12\x12\n\ndockerfile\x18\x06 \x01(\t\x12\x0e\n\x06stream\x18\x05 \x01(\x08\"[\n\x0b\x44ockerImage\x12+\n\x08registry\x18\x02 \x01(\x0b\x32\x19.portainer.DockerRegistry\x12\x12\n\nrepository\x18\x01 \x02(\t\x12\x0b\n\x03tag\x18\x03 \x03(\t\"4\n\x0e\x44ockerRegistry\x12\x10\n\x08hostname\x18\x01 \x02(\t\x12\x10\n\x04port\x18\x02 \x01(\r:\x02\x38\x30\"U\n\x0c\x44ockerDaemon\x12\x13\n\x0b\x64ocker_host\x18\x01 \x01(\t\x12\x13\n\x0b\x64ocker_args\x18\x02 \x01(\t\x12\x1b\n\x13insecure_registries\x18\x03 \x03(\t') @@ -33,37 +33,30 @@ is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='context', full_name='portainer.BuildTask.context', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=unicode("", "utf-8"), + name='daemon', full_name='portainer.BuildTask.daemon', index=1, + number=7, type=11, cpp_type=10, label=2, + has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='dockerfile', full_name='portainer.BuildTask.dockerfile', index=2, - number=6, type=9, cpp_type=9, label=1, + name='context', full_name='portainer.BuildTask.context', index=2, + number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=unicode("", "utf-8"), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='stream', full_name='portainer.BuildTask.stream', index=3, - number=5, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='docker_host', full_name='portainer.BuildTask.docker_host', index=4, - number=3, type=9, cpp_type=9, label=1, + name='dockerfile', full_name='portainer.BuildTask.dockerfile', index=3, + number=6, type=9, cpp_type=9, label=1, has_default_value=False, default_value=unicode("", "utf-8"), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='docker_args', full_name='portainer.BuildTask.docker_args', index=5, - number=4, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=unicode("", "utf-8"), + name='stream', full_name='portainer.BuildTask.stream', index=4, + number=5, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), @@ -77,7 +70,7 @@ is_extendable=False, extension_ranges=[], serialized_start=37, - serialized_end=182, + serialized_end=181, ) @@ -118,8 +111,8 @@ options=None, is_extendable=False, extension_ranges=[], - serialized_start=184, - serialized_end=275, + serialized_start=183, + serialized_end=274, ) @@ -153,15 +146,59 @@ options=None, is_extendable=False, extension_ranges=[], - serialized_start=277, - serialized_end=329, + serialized_start=276, + serialized_end=328, +) + + +_DOCKERDAEMON = _descriptor.Descriptor( + name='DockerDaemon', + full_name='portainer.DockerDaemon', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='docker_host', full_name='portainer.DockerDaemon.docker_host', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=unicode("", "utf-8"), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='docker_args', full_name='portainer.DockerDaemon.docker_args', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=unicode("", "utf-8"), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='insecure_registries', full_name='portainer.DockerDaemon.insecure_registries', index=2, + number=3, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + extension_ranges=[], + serialized_start=330, + serialized_end=415, ) _BUILDTASK.fields_by_name['image'].message_type = _DOCKERIMAGE +_BUILDTASK.fields_by_name['daemon'].message_type = _DOCKERDAEMON _DOCKERIMAGE.fields_by_name['registry'].message_type = _DOCKERREGISTRY DESCRIPTOR.message_types_by_name['BuildTask'] = _BUILDTASK DESCRIPTOR.message_types_by_name['DockerImage'] = _DOCKERIMAGE DESCRIPTOR.message_types_by_name['DockerRegistry'] = _DOCKERREGISTRY +DESCRIPTOR.message_types_by_name['DockerDaemon'] = _DOCKERDAEMON class BuildTask(_message.Message): __metaclass__ = _reflection.GeneratedProtocolMessageType @@ -181,5 +218,11 @@ class DockerRegistry(_message.Message): # @@protoc_insertion_point(class_scope:portainer.DockerRegistry) +class DockerDaemon(_message.Message): + __metaclass__ = _reflection.GeneratedProtocolMessageType + DESCRIPTOR = _DOCKERDAEMON + + # @@protoc_insertion_point(class_scope:portainer.DockerDaemon) + # @@protoc_insertion_point(module_scope) diff --git a/proto/portainer.proto b/proto/portainer.proto index 014c6e1..8dd7980 100644 --- a/proto/portainer.proto +++ b/proto/portainer.proto @@ -8,13 +8,11 @@ package portainer; */ message BuildTask { required DockerImage image = 1; + required DockerDaemon daemon = 7; + optional string context = 2; optional string dockerfile = 6; // Optional string representation of the Dockerfile to build optional bool stream = 5; // Should we stream the build output? - - // These are used when launching/connecting to the docker daemon - optional string docker_host = 3; - optional string docker_args = 4; } /** @@ -33,3 +31,15 @@ message DockerRegistry { required string hostname = 1; optional uint32 port = 2 [default = 80]; } + +/** + * Configuration for the docker daemon + */ +message DockerDaemon { + // These are used when launching/connecting to the docker daemon + optional string docker_host = 1; + optional string docker_args = 2; + + // List of docker registries that can be used without SSL + repeated string insecure_registries = 3; +}