Browse Source

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

shin- 12 years ago
parent
commit
2ff82a5d91
2 changed files with 23 additions and 11 deletions
  1. 6 1
      README.md
  2. 17 10
      stackbrew/brew/brew.py

+ 6 - 1
README.md

@@ -1,7 +1,7 @@
 # Stackbrew
 
 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.
 
 ## 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]
 	<docker-tag>:	<git-url>@<git-commit-id>
 	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
 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
 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
 
 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
             logger.debug('{0} ---> {1}'.format(buildfile, line))
             try:
-                tag, url, ref = parse_line(line, logger)
+                tag, url, ref, dfile = parse_line(line, logger)
                 if prefill:
                     logger.debug('Pulling {0} from official repository (cache '
                                  'fill)'.format(buildfile))
                     try:
-                        client.pull('stackbrew/' + buildfile)
+                        client.pull(buildfile)
                     except:
                         # Image is not on official repository, ignore prefill
                         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)
                 processed['{0}@{1}'.format(url, ref)] = img
             except Exception as e:
@@ -127,14 +128,18 @@ def build_library(repository=None, branch=None, namespace=None, push=False,
 
 
 def parse_line(line, logger):
+    df_folder = '.'
     args = line.split(':', 1)
     if len(args) != 2:
         logger.debug("Invalid line: {0}".format(line))
         raise RuntimeError('Incorrect line format, please refer to the docs')
 
     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:
         logger.debug("Invalid line: {0}".format(line))
         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.
         repository:     URL of the git repository 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
                         end up.
+        dockerfile_location: Folder containing the Dockerfile
         docker_tag:     Tag for the image in the docker repository.
         namespace:      Namespace for the docker repository.
         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:
                     ref = 'refs/tags/' + 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')
         commit_id = rep.head()
         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:
             logger.error('Image ID not found. Printing build logs...')
             logger.debug(logs)