From c3f72d948e875cc5085c6ac682bbf225096e7517 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Jan 03 2017 23:36:58 +0000 Subject: work in progress, need to add the cli component also Signed-off-by: Adam Miller --- diff --git a/flr/docker.py b/flr/docker.py new file mode 100644 index 0000000..b35ac06 --- /dev/null +++ b/flr/docker.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +""" docker module of flr """ + +import docker + +class DockerClient(object): + """ + docker module for flr + + The aim of this object is to provide a library common solution to use-cases + for Fedora Release Engineering utilities + """ + + def __init__(self, docker_daemon=None, registry=None): + self.dc = docker.Client(base_url=docker_daemon) + + if registry: + # Note: This will require the login credentials to pre-exist in + # the default path of ~/.dockercfg for the user this is running as + # + # FIXME - not sure if this is the best idea, maybe allow other auth + # configs? + self.dc.login() + + + def split_repo(self, repo_name): + """ + Split a docker repo uri into it's reponame and tag + + :param repo_name: str, docker repo uri + + :return: tuple, (image_repo, image_tag) + """ + + try: + image_repo, image_tag = repo_name.split(':') + except ValueError: + image_repo = repo_name + image_tag = None + + return (image_repo, image_tag) + + def copy(self, src_image, dest_image): + """ + + :param src_image: str, source docker image repo uri + :param dest_image: str, source docker image repo uri + """ + + + src_repo, src_tag = self.split_repo(src_image) + dest_repo, dest_tag = self.split_repo(dest_image) + + self.dc.pull(src_repo, tag=src_tag) + + # We set 'force' here just as we would with 'docker tag' because often + # times RelEng is updating an image in-place and we need to actively + # overwrite the pre-existing base image for things like fedora:rawhide + self.dc.tag(src_image, dest_repo, tag=dest_tag, force=True) + + self.dc.push(dest_image) + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4