فهرست منبع

Added ability to specify in which subdirectory brew should look for the Dockerfile

shin- 12 سال پیش
والد
کامیت
2ff82a5d91
2فایلهای تغییر یافته به همراه23 افزوده شده و 11 حذف شده
  1. 6 1
      README.md
  2. 17 10
      stackbrew/brew/brew.py

+ 6 - 1
README.md

@@ -1,7 +1,7 @@
 # Stackbrew
 # Stackbrew
 
 
 Stackbrew is a web-application that performs continuous building of the docker
 Stackbrew is a web-application that performs continuous building of the docker
-standard library. See `README.md` in the stackbrew subfolder for more 
+standard library. See `README.md` in the stackbrew subfolder for more
 information.
 information.
 
 
 ## Library definition files
 ## Library definition files
@@ -25,6 +25,8 @@ of our effort to create strict, unambiguous references to build images upon.
 	2.4.0: 	git://github.com/dotcloud/[email protected]
 	2.4.0: 	git://github.com/dotcloud/[email protected]
 	<docker-tag>:	<git-url>@<git-commit-id>
 	<docker-tag>:	<git-url>@<git-commit-id>
 	2.2.0: 	git://github.com/dotcloud/docker-redis@a4bf8923ee4ec566d3ddc212
 	2.2.0: 	git://github.com/dotcloud/docker-redis@a4bf8923ee4ec566d3ddc212
+    <docker-tag>: <git-url>@<git-tag-or-commit-id>  <dockerfile-dir>
+    2.5.1: git://github.com/dotcloud/[email protected]     tools/dockerfiles/2.5.1
 
 
 Stackbrew will fetch data from the provided git repository from the
 Stackbrew will fetch data from the provided git repository from the
 provided reference. Generated image will be tagged as `<docker-tag>`.
 provided reference. Generated image will be tagged as `<docker-tag>`.
@@ -32,6 +34,9 @@ If a git tag is removed and added to another commit,
 **you should not expect the image to be rebuilt.** Create a new tag and submit
 **you should not expect the image to be rebuilt.** Create a new tag and submit
 a pull request instead.
 a pull request instead.
 
 
+Optionally, if `<dockerfile-dir>`, stackbrew will look for the `Dockerfile`
+inside the specified subdirectory instead of at the root.
+
 ## Contributing to the standard library
 ## Contributing to the standard library
 
 
 Thank you for your interest in the stackbrew project! We strive to make these instructions as simple and straightforward as possible, but if you find yourself lost, don't hesitate to seek us out on IRC freenode, channel `#docker` or by creating a github issue.
 Thank you for your interest in the stackbrew project! We strive to make these instructions as simple and straightforward as possible, but if you find yourself lost, don't hesitate to seek us out on IRC freenode, channel `#docker` or by creating a github issue.

+ 17 - 10
stackbrew/brew/brew.py

@@ -102,18 +102,19 @@ def build_library(repository=None, branch=None, namespace=None, push=False,
                 continue
                 continue
             logger.debug('{0} ---> {1}'.format(buildfile, line))
             logger.debug('{0} ---> {1}'.format(buildfile, line))
             try:
             try:
-                tag, url, ref = parse_line(line, logger)
+                tag, url, ref, dfile = parse_line(line, logger)
                 if prefill:
                 if prefill:
                     logger.debug('Pulling {0} from official repository (cache '
                     logger.debug('Pulling {0} from official repository (cache '
                                  'fill)'.format(buildfile))
                                  'fill)'.format(buildfile))
                     try:
                     try:
-                        client.pull('stackbrew/' + buildfile)
+                        client.pull(buildfile)
                     except:
                     except:
                         # Image is not on official repository, ignore prefill
                         # Image is not on official repository, ignore prefill
                         pass
                         pass
 
 
-                img, commit = build_repo(url, ref, buildfile, tag, namespace,
-                                         push, registry, repos_folder, logger)
+                img, commit = build_repo(url, ref, buildfile, dfile, tag,
+                                         namespace, push, registry,
+                                         repos_folder, logger)
                 summary.add_success(buildfile, (linecnt, line), img, commit)
                 summary.add_success(buildfile, (linecnt, line), img, commit)
                 processed['{0}@{1}'.format(url, ref)] = img
                 processed['{0}@{1}'.format(url, ref)] = img
             except Exception as e:
             except Exception as e:
@@ -127,14 +128,18 @@ def build_library(repository=None, branch=None, namespace=None, push=False,
 
 
 
 
 def parse_line(line, logger):
 def parse_line(line, logger):
+    df_folder = '.'
     args = line.split(':', 1)
     args = line.split(':', 1)
     if len(args) != 2:
     if len(args) != 2:
         logger.debug("Invalid line: {0}".format(line))
         logger.debug("Invalid line: {0}".format(line))
         raise RuntimeError('Incorrect line format, please refer to the docs')
         raise RuntimeError('Incorrect line format, please refer to the docs')
 
 
     try:
     try:
-        url, ref = args[1].strip().rsplit('@', 1)
-        return (args[0].strip(), url, ref)
+        repo = args[1].strip().split()
+        if len(repo) == 2:
+            df_folder = repo[1].strip()
+        url, ref = repo[0].strip().rsplit('@', 1)
+        return (args[0].strip(), url, ref, df_folder)
     except ValueError:
     except ValueError:
         logger.debug("Invalid line: {0}".format(line))
         logger.debug("Invalid line: {0}".format(line))
         raise RuntimeError('Incorrect line format, please refer to the docs')
         raise RuntimeError('Incorrect line format, please refer to the docs')
@@ -165,13 +170,14 @@ def _random_suffix():
     ])
     ])
 
 
 
 
-def build_repo(repository, ref, docker_repo, docker_tag, namespace, push,
-               registry, repos_folder, logger):
+def build_repo(repository, ref, docker_repo, dockerfile_location,
+               docker_tag, namespace, push, registry, repos_folder, logger):
     ''' Builds one line of a library file.
     ''' Builds one line of a library file.
         repository:     URL of the git repository that needs to be built
         repository:     URL of the git repository that needs to be built
         ref:            Git reference (or commit ID) that needs to be built
         ref:            Git reference (or commit ID) that needs to be built
         docker_repo:    Name of the docker repository where the image will
         docker_repo:    Name of the docker repository where the image will
                         end up.
                         end up.
+        dockerfile_location: Folder containing the Dockerfile
         docker_tag:     Tag for the image in the docker repository.
         docker_tag:     Tag for the image in the docker repository.
         namespace:      Namespace for the docker repository.
         namespace:      Namespace for the docker repository.
         push:           If the image should be pushed at the end of the build
         push:           If the image should be pushed at the end of the build
@@ -225,11 +231,12 @@ def build_repo(repository, ref, docker_repo, docker_tag, namespace, push,
                 except Exception:
                 except Exception:
                     ref = 'refs/tags/' + ref
                     ref = 'refs/tags/' + ref
                     rep, dst_folder = git.pull(repository, rep, ref)
                     rep, dst_folder = git.pull(repository, rep, ref)
-        if not 'Dockerfile' in os.listdir(dst_folder):
+        dockerfile_location = os.path.join(dst_folder, dockerfile_location)
+        if not 'Dockerfile' in os.listdir(dockerfile_location):
             raise RuntimeError('Dockerfile not found in cloned repository')
             raise RuntimeError('Dockerfile not found in cloned repository')
         commit_id = rep.head()
         commit_id = rep.head()
         logger.info('Building using dockerfile...')
         logger.info('Building using dockerfile...')
-        img_id, logs = client.build(path=dst_folder, quiet=True)
+        img_id, logs = client.build(path=dockerfile_location, quiet=True)
         if img_id is None:
         if img_id is None:
             logger.error('Image ID not found. Printing build logs...')
             logger.error('Image ID not found. Printing build logs...')
             logger.debug(logs)
             logger.debug(logs)