浏览代码

Adapted script to work with docker-py 0.1.0, added command line tool

shin- 12 年之前
父节点
当前提交
e47b7f4461
共有 5 个文件被更改,包括 34 次插入8 次删除
  1. 1 0
      brew/__init__.py
  2. 4 5
      brew/brew.py
  3. 25 0
      docker-brew
  4. 2 1
      requirements.txt
  5. 2 2
      setup.py

+ 1 - 0
brew/__init__.py

@@ -0,0 +1 @@
+from brew import build_library

+ 4 - 5
brew/brew.py

@@ -15,7 +15,7 @@ client = docker.Client()
 processed = {}
 
 
-def fetch_buildlist(repository=None, branch=None):
+def build_library(repository=None, branch=None, namespace=None, push=False):
     if repository is None:
         repository = DEFAULT_REPOSITORY
     if branch is None:
@@ -58,15 +58,14 @@ def fetch_buildlist(repository=None, branch=None):
                     else:
                         raise RuntimeError('Incorrect line format, '
                             'please refer to the docs')
-                img = start_build(url, ref, buildfile, tag)
+                img = build_repo(url, ref, buildfile, tag, namespace, push)
                 processed['{0}@{1}'.format(url, ref)] = img
             except Exception as e:
                 logger.exception(e)
         f.close()
 
 
-def start_build(repository, ref, docker_repo, docker_tag=None, namespace=None,
-                push=False):
+def build_repo(repository, ref, docker_repo, docker_tag, namespace, push):
     docker_repo = '{0}/{1}'.format(namespace or 'library', docker_repo)
     img_id = None
     if '{0}@{1}'.format(repository, ref) not in processed.keys():
@@ -75,7 +74,7 @@ def start_build(repository, ref, docker_repo, docker_tag=None, namespace=None,
         if not 'Dockerfile' in os.listdir(dst_folder):
             raise RuntimeError('Dockerfile not found in cloned repository')
         logger.info('Building using dockerfile...')
-        img_id, logs = client.build_context(dst_folder)
+        img_id, logs = client.build(path=dst_folder)
 
     if not img_id:
         img_id = processed['{0}@{1}'.format(repository, ref)]

+ 25 - 0
docker-brew

@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import argparse
+
+import brew
+
+
+DEFAULT_REPOSITORY = 'git://github.com/dotcloud/docker'
+DEFAULT_BRANCH = 'library'
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser('Build the docker standard library')
+    parser.add_argument('--push', action='store_true', default=False,
+        help='push generated repositories to the official registry')
+    parser.add_argument('-n', metavar='NAMESPACE', default='library',
+        help='namespace used for generated repositories.'
+        ' Default is library')
+    parser.add_argument('-b', metavar='BRANCH', default=DEFAULT_BRANCH,
+        help='branch in the repository where the library definition'
+        ' files will be fetched. Default is ' + DEFAULT_BRANCH)
+    parser.add_argument('repository', default=DEFAULT_REPOSITORY, nargs='?',
+        help='git repository containing the library definition files.'
+        ' Default is ' + DEFAULT_REPOSITORY)
+    args = parser.parse_args()
+    brew.build_library(args.repository, args.b, args.n, args.push)

+ 2 - 1
requirements.txt

@@ -1 +1,2 @@
-dulwich
+dulwich==0.9.0
+docker==0.1.0

+ 2 - 2
setup.py

@@ -1,4 +1,4 @@
-#/usr/bin/env python
+#!/usr/bin/env python
 import os
 from setuptools import setup
 
@@ -11,7 +11,7 @@ setup(
     version='0.0.1',
     description="-",
     packages=['dockerbrew'],
-    install_requires=['requests'] + test_requirements,
+    install_requires=['dulwich', 'docker'] + test_requirements,
     zip_safe=False,
     classifiers=['Development Status :: 3 - Alpha',
                  'Environment :: Other Environment',