From 85ce3c6bb2506b27e4b262d2379bc7b0c389b628 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 16 Jul 2014 16:47:59 -0400 Subject: [PATCH 01/14] Remove the HTML escaping in the dockerfile-view directive; the text escaping is handled by the nested controls and Angular itself --- static/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/app.js b/static/js/app.js index fe1719449..e2f3394ce 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -4343,7 +4343,7 @@ quayApp.directive('dockerfileView', function () { } var lineInfo = { - 'text': UtilService.textToSafeHtml(line), + 'text': line, 'kind': kind }; $scope.lines.push(lineInfo); From cceb09d4f6fe435494c58e0fa351c6e26d42983b Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 17 Jul 2014 12:05:37 -0400 Subject: [PATCH 02/14] Remove some unused dependencies and update the rest. --- requirements-nover.txt | 4 +-- requirements.txt | 50 ++++++++++++++++++-------------------- workers/dockerfilebuild.py | 1 - 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/requirements-nover.txt b/requirements-nover.txt index d2f543772..c4396d882 100644 --- a/requirements-nover.txt +++ b/requirements-nover.txt @@ -14,13 +14,11 @@ mixpanel-py beautifulsoup4 marisa-trie apscheduler -python-daemon paramiko -python-digitalocean xhtml2pdf redis hiredis -git+https://github.com/DevTable/docker-py.git +docker-py loremipsum pygithub flask-restful diff --git a/requirements.txt b/requirements.txt index 13be2148f..e6f2cb804 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,56 +1,54 @@ APScheduler==2.1.2 Flask==0.10.1 -Flask-Login==0.2.10 +Flask-Login==0.2.11 Flask-Mail==0.9.0 Flask-Principal==0.4.0 Flask-RESTful==0.2.12 -Jinja2==2.7.2 +Jinja2==2.7.3 LogentriesLogger==0.2.1 -Mako==0.9.1 -MarkupSafe==0.21 -Pillow==2.4.0 -PyGithub==1.24.1 +Mako==1.0.0 +MarkupSafe==0.23 +Pillow==2.5.1 +PyGithub==1.25.0 PyMySQL==0.6.2 -PyPDF2==1.21 -SQLAlchemy==0.9.4 +PyPDF2==1.22 +SQLAlchemy==0.9.6 Unidecode==0.04.16 -Werkzeug==0.9.4 -alembic==0.6.4 +Werkzeug==0.9.6 +alembic==0.6.5 aniso8601==0.82 argparse==1.2.1 beautifulsoup4==4.3.2 blinker==1.3 -boto==2.27.0 -git+https://github.com/DevTable/docker-py.git +boto==2.31.1 +docker-py==0.3.2 ecdsa==0.11 gevent==1.0.1 greenlet==0.4.2 -gunicorn==18.0 -hiredis==0.1.3 +gunicorn==19.0.0 +hiredis==0.1.4 html5lib==0.999 itsdangerous==0.24 jsonschema==2.3.0 -lockfile==0.9.1 loremipsum==1.0.2 marisa-trie==0.6 -mixpanel-py==3.1.2 +mixpanel-py==3.1.3 +mock==1.0.1 git+https://github.com/NateFerrero/oauth2lib.git -paramiko==1.13.0 -peewee==2.2.3 +paramiko==1.14.0 +peewee==2.2.5 py-bcrypt==0.4 pycrypto==2.6.1 -python-daemon==1.6 python-dateutil==2.2 -python-digitalocean==0.7 python-ldap==2.4.15 python-magic==0.4.6 -pytz==2014.2 -raven==4.2.1 -redis==2.9.1 +pytz==2014.4 +raven==5.0.0 +redis==2.10.1 reportlab==2.7 -requests==2.2.1 -six==1.6.1 -stripe==1.14.0 +requests==2.3.0 +six==1.7.3 +stripe==1.18.0 websocket-client==0.11.0 wsgiref==0.1.2 xhtml2pdf==0.0.6 diff --git a/workers/dockerfilebuild.py b/workers/dockerfilebuild.py index dbb8d0aa0..6e0c53694 100644 --- a/workers/dockerfilebuild.py +++ b/workers/dockerfilebuild.py @@ -3,7 +3,6 @@ import logging.config logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False) import logging -import daemon import argparse import os import requests From db953cdc79f21d8bb858b2650917f19b15993759 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 17 Jul 2014 14:04:51 -0400 Subject: [PATCH 03/14] Temporarily downgrade the gunicorn version until the fix for this bug is available: https://github.com/benoitc/gunicorn/issues/790 --- requirements-nover.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-nover.txt b/requirements-nover.txt index c4396d882..f9352aa02 100644 --- a/requirements-nover.txt +++ b/requirements-nover.txt @@ -8,7 +8,7 @@ python-dateutil boto pymysql stripe -gunicorn +gunicorn<19.0 gevent mixpanel-py beautifulsoup4 diff --git a/requirements.txt b/requirements.txt index e6f2cb804..e82f94c7b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ docker-py==0.3.2 ecdsa==0.11 gevent==1.0.1 greenlet==0.4.2 -gunicorn==19.0.0 +gunicorn==18.0 hiredis==0.1.4 html5lib==0.999 itsdangerous==0.24 From 126371f8a1df2c44409ae2f78f97dd6ecc3f01cc Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 17 Jul 2014 14:36:06 -0400 Subject: [PATCH 04/14] Fix non-library Dockerhub links --- static/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/app.js b/static/js/app.js index e2f3394ce..35577621e 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -4271,7 +4271,7 @@ quayApp.directive('dockerfileCommand', function () { }, '': function(pieces) { - var rnamespace = pieces.length == 1 ? '_' : pieces[0]; + var rnamespace = pieces.length == 1 ? '_' : 'u/' + pieces[0]; var rname = pieces[pieces.length - 1].split(':')[0]; return 'https://registry.hub.docker.com/' + rnamespace + '/' + rname + '/'; } From a45054bf2ed84c0eb63a074956fb96d80b44f2d9 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 17 Jul 2014 15:16:22 -0400 Subject: [PATCH 05/14] Change tag_view to avoid a DB lookup and only return the tag's image ID. We map the ID in the frontend based on the image data returned --- endpoints/api/repository.py | 22 +---------- static/js/controllers.js | 69 +++++++++++++++++++--------------- static/partials/view-repo.html | 15 ++++++-- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/endpoints/api/repository.py b/endpoints/api/repository.py index 215caa1b5..17a35fea1 100644 --- a/endpoints/api/repository.py +++ b/endpoints/api/repository.py @@ -138,21 +138,6 @@ class RepositoryList(ApiResource): return response -def image_view(image): - extended_props = image - if image.storage and image.storage.id: - extended_props = image.storage - - command = extended_props.command - return { - 'id': image.docker_image_id, - 'created': format_date(extended_props.created), - 'comment': extended_props.comment, - 'command': json.loads(command) if command else None, - 'ancestors': image.ancestors, - 'dbid': image.id, - 'size': extended_props.image_size - } @resource('/v1/repository/') class Repository(RepositoryParamResource): @@ -181,13 +166,10 @@ class Repository(RepositoryParamResource): logger.debug('Get repo: %s/%s' % (namespace, repository)) def tag_view(tag): - image = model.get_tag_image(namespace, repository, tag.name) - if not image: - return {} - return { 'name': tag.name, - 'image': image_view(image), + 'image_id': tag.image.docker_image_id, + 'dbid': tag.image.id } organization = None diff --git a/static/js/controllers.js b/static/js/controllers.js index 0b19eba2e..985a6c361 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -466,31 +466,6 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi addedDisplayed - removedDisplayed - changedDisplayed; }; - $scope.setImage = function(imageId, opt_updateURL) { - var image = null; - for (var i = 0; i < $scope.images.length; ++i) { - var currentImage = $scope.images[i]; - if (currentImage.id == imageId || currentImage.id.substr(0, 12) == imageId) { - image = currentImage; - break; - } - } - - if (!image) { return; } - - $scope.currentTag = null; - $scope.currentImage = image; - $scope.loadImageChanges(image); - if ($scope.tree) { - $scope.tree.setImage(image.id); - } - - if (opt_updateURL) { - $location.search('tag', null); - $location.search('image', imageId.substr(0, 12)); - } - }; - $scope.showAddTag = function(image) { $scope.toTagImage = image; $('#addTagModal').modal('show'); @@ -513,6 +488,10 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi $('#confirmdeleteTagModal').modal('show'); }; + $scope.findImageForTag = function(tag) { + return tag && $scope.imageByDBID && $scope.imageByDBID[tag.dbid]; + }; + $scope.createOrMoveTag = function(image, tagName, opt_invalid) { if (opt_invalid) { return; } @@ -592,13 +571,38 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi return size; }; + $scope.setImage = function(imageId, opt_updateURL) { + var image = null; + for (var i = 0; i < $scope.images.length; ++i) { + var currentImage = $scope.images[i]; + if (currentImage.id == imageId || currentImage.id.substr(0, 12) == imageId) { + image = currentImage; + break; + } + } + + if (!image) { return; } + + $scope.currentTag = null; + $scope.currentImage = image; + $scope.loadImageChanges(image); + if ($scope.tree) { + $scope.tree.setImage(image.id); + } + + if (opt_updateURL) { + $location.search('tag', null); + $location.search('image', imageId.substr(0, 12)); + } + }; + $scope.setTag = function(tagName, opt_updateURL) { var repo = $scope.repo; if (!repo) { return; } var proposedTag = repo.tags[tagName]; if (!proposedTag) { - // We must find a good default + // We must find a good default. for (tagName in repo.tags) { if (!proposedTag || tagName == 'latest') { proposedTag = repo.tags[tagName]; @@ -608,8 +612,8 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi if (proposedTag) { $scope.currentTag = proposedTag; - $scope.currentImage = proposedTag.image; - $scope.loadImageChanges($scope.currentImage); + $scope.currentImage = null; + if ($scope.tree) { $scope.tree.setTag(proposedTag.name); } @@ -686,9 +690,14 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi var forAllTagImages = function(tag, callback) { if (!tag || !$scope.imageByDBID) { return; } - callback(tag.image); + var tag_image = $scope.imageByDBID[tag.dbid]; + if (!tag_image) { return; } - var ancestors = tag.image.ancestors.split('/'); + // Callback the tag's image itself. + callback(tag_image); + + // Callback any parent images. + var ancestors = tag_image.ancestors.split('/'); for (var i = 0; i < ancestors.length; ++i) { var image = $scope.imageByDBID[ancestors[i]]; if (image) { diff --git a/static/partials/view-repo.html b/static/partials/view-repo.html index 915bc52ec..7d683cd2b 100644 --- a/static/partials/view-repo.html +++ b/static/partials/view-repo.html @@ -77,7 +77,7 @@ content-changed="updateForDescription" field-title="'repository description'"> -
+
This repository is empty
@@ -100,14 +100,14 @@
-
+
A build is currently processing. If this takes longer than an hour, please contact us
-
+
@@ -163,7 +163,14 @@
Last Modified
-
+
+ +
+ +
+
+
Total Compressed Size
Date: Thu, 17 Jul 2014 22:59:17 -0400 Subject: [PATCH 06/14] Fix missing change to code handling tags and images --- static/js/app.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/static/js/app.js b/static/js/app.js index 35577621e..1c4554e7a 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -4896,7 +4896,7 @@ quayApp.directive('tagSpecificImagesView', function () { } var currentTag = $scope.repository.tags[$scope.tag]; - if (image.dbid == currentTag.image.dbid) { + if (image.dbid == currentTag.dbid) { classes += 'tag-image '; } @@ -4906,8 +4906,6 @@ quayApp.directive('tagSpecificImagesView', function () { var forAllTagImages = function(tag, callback) { if (!tag) { return; } - callback(tag.image); - if (!$scope.imageByDBID) { $scope.imageByDBID = []; for (var i = 0; i < $scope.images.length; ++i) { @@ -4916,7 +4914,14 @@ quayApp.directive('tagSpecificImagesView', function () { } } - var ancestors = tag.image.ancestors.split('/'); + var tag_image = $scope.imageByDBID[tag.dbid]; + if (!tag_image) { + return; + } + + callback(tag_image); + + var ancestors = tag_image.ancestors.split('/'); for (var i = 0; i < ancestors.length; ++i) { var image = $scope.imageByDBID[ancestors[i]]; if (image) { From 566fda93510bff6445579130cd6890ce2175f935 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 17 Jul 2014 23:00:25 -0400 Subject: [PATCH 07/14] Add an NPE check to loadImageChanges --- static/js/controllers.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/js/controllers.js b/static/js/controllers.js index 985a6c361..a94ed8c1e 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -450,6 +450,8 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi }; $scope.loadImageChanges = function(image) { + if (!image) { return; } + var params = {'repository': namespace + '/' + name, 'image_id': image.id}; $scope.currentImageChangeResource = ApiService.getImageChangesAsResource(params).get(function(ci) { $scope.currentImageChanges = ci; From afebb7780d858019b1274a087d4cd3a8b7732fe5 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 17 Jul 2014 23:02:18 -0400 Subject: [PATCH 08/14] Add an NPE check to lookup up a tag's image's ancestors --- static/js/controllers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/js/controllers.js b/static/js/controllers.js index a94ed8c1e..822c5a751 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -699,6 +699,7 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi callback(tag_image); // Callback any parent images. + if (!tag_image.ancestors) { return; } var ancestors = tag_image.ancestors.split('/'); for (var i = 0; i < ancestors.length; ++i) { var image = $scope.imageByDBID[ancestors[i]]; From 397af2ffc908942b2646c812c0946fe44298c702 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 17 Jul 2014 23:03:22 -0400 Subject: [PATCH 09/14] Fix tooltip in tag-specific-images-view to properly bind --- static/directives/tag-specific-images-view.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/directives/tag-specific-images-view.html b/static/directives/tag-specific-images-view.html index c4e9424d2..a1513384c 100644 --- a/static/directives/tag-specific-images-view.html +++ b/static/directives/tag-specific-images-view.html @@ -5,7 +5,7 @@ ng-class="getImageListingClasses(image)"> - {{ image.id.substr(0, 12) }} From 78a259063171e99f24700d080bf9fedaa65884fb Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 17 Jul 2014 23:17:43 -0400 Subject: [PATCH 10/14] Simplify the dockerfiles using a dockerignore. --- .dockerignore | 11 +++++++ Dockerfile.buildworker | 41 ++++++++--------------- Dockerfile.web | 74 +++++++++++------------------------------- 3 files changed, 43 insertions(+), 83 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..fcc890f76 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +conf/stack +screenshots +test/data/registry +venv +.git +.gitignore +Bobfile +README.md +license.py +requirements-nover.txt +run-local.sh diff --git a/Dockerfile.buildworker b/Dockerfile.buildworker index 8f3232870..f3ea2a4d5 100644 --- a/Dockerfile.buildworker +++ b/Dockerfile.buildworker @@ -1,45 +1,30 @@ -FROM phusion/baseimage:0.9.10 +FROM phusion/baseimage:0.9.11 ENV DEBIAN_FRONTEND noninteractive ENV HOME /root +WORKDIR / -RUN apt-get update # 20JUN2014 -RUN apt-get install -y git python-virtualenv python-dev libjpeg8 libjpeg62-dev libevent-dev gdebi-core g++ libmagic1 +# Install the dependencies. +RUN apt-get update # 15JUL2014 + +# New ubuntu packages should be added as their own apt-get install lines below the existing install commands +RUN apt-get install -y git python-virtualenv python-dev libjpeg8 libjpeg62-dev libevent-dev gdebi-core g++ libmagic1 phantomjs nodejs npm libldap2-dev libsasl2-dev + +# Build the python dependencies +ADD requirements.txt requirements.txt +RUN virtualenv --distribute venv +RUN venv/bin/pip install -r requirements.txt ### End common section ### -RUN apt-get install -y libldap2-dev libsasl2-dev - RUN apt-get install -y lxc aufs-tools RUN usermod -v 100000-200000 -w 100000-200000 root ADD binary_dependencies/builder binary_dependencies/builder - RUN gdebi --n binary_dependencies/builder/*.deb -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -ADD requirements.txt requirements.txt -RUN virtualenv --distribute venv -RUN venv/bin/pip install -r requirements.txt - -ADD buildstatus buildstatus -ADD data data -ADD features features -ADD storage storage -ADD util util -ADD workers workers - -ADD app.py app.py -ADD config.py config.py -ADD license.pyc license.pyc - -# Remove this if we ever stop depending on test data for the default config -ADD test test - -ADD conf conf -RUN rm -rf /conf/stack +ADD . . ADD conf/init/svlogd_config /svlogd_config ADD conf/init/preplogsdir.sh /etc/my_init.d/ diff --git a/Dockerfile.web b/Dockerfile.web index dd0975bb4..4d1cda7af 100644 --- a/Dockerfile.web +++ b/Dockerfile.web @@ -1,67 +1,35 @@ -FROM phusion/baseimage:0.9.10 +FROM phusion/baseimage:0.9.11 ENV DEBIAN_FRONTEND noninteractive ENV HOME /root +WORKDIR / # Install the dependencies. -RUN apt-get update # 20JUN2014 +RUN apt-get update # 15JUL2014 # New ubuntu packages should be added as their own apt-get install lines below the existing install commands -RUN apt-get install -y git python-virtualenv python-dev libjpeg8 libjpeg62-dev libevent-dev gdebi-core g++ libmagic1 - -# PhantomJS -RUN apt-get install -y phantomjs - -# Grunt -RUN apt-get install -y nodejs npm -RUN ln -s /usr/bin/nodejs /usr/bin/node -RUN npm install -g grunt-cli - -# LDAP -RUN apt-get install -y libldap2-dev libsasl2-dev - -ADD binary_dependencies binary_dependencies -RUN gdebi --n binary_dependencies/*.deb - -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +RUN apt-get install -y git python-virtualenv python-dev libjpeg8 libjpeg62-dev libevent-dev gdebi-core g++ libmagic1 phantomjs nodejs npm libldap2-dev libsasl2-dev +# Build the python dependencies ADD requirements.txt requirements.txt RUN virtualenv --distribute venv RUN venv/bin/pip install -r requirements.txt -# Add the static assets and run grunt -ADD grunt grunt -ADD static static +# Install the binary dependencies +ADD binary_dependencies binary_dependencies +RUN gdebi --n binary_dependencies/*.deb + +# Grunt +RUN ln -s /usr/bin/nodejs /usr/bin/node +RUN npm install -g grunt-cli + +# Add all of the files! +ADD . . + +# Run grunt RUN cd grunt && npm install RUN cd grunt && grunt -# Add the backend assets -ADD auth auth -ADD buildstatus buildstatus -ADD data data -ADD endpoints endpoints -ADD features features -ADD screenshots screenshots -ADD storage storage -ADD templates templates -ADD util util -ADD workers workers - -ADD license.pyc license.pyc -ADD app.py app.py -ADD application.py application.py -ADD config.py config.py -ADD initdb.py initdb.py -ADD external_libraries.py external_libraries.py -ADD alembic.ini alembic.ini - -# Add the config -ADD conf conf - -# This command must be rm -f (not -rf) to fail in case stack is ever a dir, -# which may contain secrets -RUN rm -f /conf/stack - ADD conf/init/svlogd_config /svlogd_config ADD conf/init/preplogsdir.sh /etc/my_init.d/ ADD conf/init/runmigration.sh /etc/my_init.d/ @@ -72,16 +40,12 @@ ADD conf/init/diffsworker /etc/service/diffsworker ADD conf/init/webhookworker /etc/service/webhookworker # Download any external libs. -RUN mkdir static/fonts -RUN mkdir static/ldn - +RUN mkdir static/fonts static/ldn RUN venv/bin/python -m external_libraries -# Add the tests last because they're prone to accidental changes, then run them -ADD test test +# Run the tests RUN TEST=true venv/bin/python -m unittest discover -RUN rm -rf /conf/stack VOLUME ["/conf/stack", "/var/log", "/datastorage"] EXPOSE 443 80 From 3d852aa9d3d9801cce08a8312a3ea5d8165e6483 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 18 Jul 2014 14:55:55 -0400 Subject: [PATCH 11/14] tiny style fixes --- endpoints/api/repotoken.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/endpoints/api/repotoken.py b/endpoints/api/repotoken.py index 1d9f6bf3b..b430d2b4e 100644 --- a/endpoints/api/repotoken.py +++ b/endpoints/api/repotoken.py @@ -60,7 +60,7 @@ class RepositoryTokenList(RepositoryParamResource): log_action('add_repo_accesstoken', namespace, {'repo': repository, 'token': token_params['friendlyName']}, - repo = model.get_repository(namespace, repository)) + repo=model.get_repository(namespace, repository)) return token_view(token), 201 @@ -116,7 +116,7 @@ class RepositoryToken(RepositoryParamResource): log_action('change_repo_permission', namespace, {'repo': repository, 'token': token.friendly_name, 'code': code, 'role': new_permission['role']}, - repo = model.get_repository(namespace, repository)) + repo=model.get_repository(namespace, repository)) return token_view(token) @@ -129,6 +129,6 @@ class RepositoryToken(RepositoryParamResource): log_action('delete_repo_accesstoken', namespace, {'repo': repository, 'token': token.friendly_name, 'code': code}, - repo = model.get_repository(namespace, repository)) + repo=model.get_repository(namespace, repository)) return 'Deleted', 204 From 8a2c88488aae17a5455d9270b20fff2378bf8dbc Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 18 Jul 2014 14:56:26 -0400 Subject: [PATCH 12/14] Filter tokens with an associated build trigger from the list API. Delete associated tokens when deleting a trigger. --- data/model/legacy.py | 16 +++++++++------- endpoints/api/trigger.py | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/data/model/legacy.py b/data/model/legacy.py index e59cae6b9..811979981 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -1402,12 +1402,14 @@ def create_delegate_token(namespace_name, repository_name, friendly_name, def get_repository_delegate_tokens(namespace_name, repository_name): - selected = AccessToken.select(AccessToken, Role) - with_repo = selected.join(Repository) - with_role = with_repo.switch(AccessToken).join(Role) - return with_role.where(Repository.name == repository_name, - Repository.namespace == namespace_name, - AccessToken.temporary == False) + return (AccessToken.select(AccessToken, Role) + .join(Repository) + .switch(AccessToken) + .join(Role) + .switch(AccessToken) + .join(RepositoryBuildTrigger, JOIN_LEFT_OUTER) + .where(Repository.name == repository_name, Repository.namespace == namespace_name, + AccessToken.temporary == False, RepositoryBuildTrigger.uuid >> None)) def get_repo_delegate_token(namespace_name, repository_name, code): @@ -1435,7 +1437,7 @@ def set_repo_delegate_token_role(namespace_name, repository_name, code, role): def delete_delegate_token(namespace_name, repository_name, code): token = get_repo_delegate_token(namespace_name, repository_name, code) - token.delete_instance() + token.delete_instance(recursive=True) return token diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index 20ab04330..47d36a547 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -81,6 +81,7 @@ class BuildTrigger(RepositoryParamResource): 'service': trigger.service.name, 'config': config_dict}, repo=model.get_repository(namespace, repository)) + trigger.write_token.delete_instance() trigger.delete_instance(recursive=True) return 'No Content', 204 From 74d1c4e6b079bd38eb8d67093b35d0740b8c7aa7 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 18 Jul 2014 15:04:20 -0400 Subject: [PATCH 13/14] Update the worker status endpoint to be ELB friendly. --- workers/worker.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workers/worker.py b/workers/worker.py index 094f2154f..5e04c1d5e 100644 --- a/workers/worker.py +++ b/workers/worker.py @@ -40,6 +40,9 @@ class WorkerStatusHandler(BaseHTTPRequestHandler): # Return the worker status code = 200 if self.server.worker.is_healthy() else 503 self.send_response(code) + self.send_header('Content-Type', 'text/plain') + self.end_headers() + self.wfile.write('OK') elif self.path == '/terminate': # Return whether it is safe to terminate the worker process code = 200 if self.server.worker.is_terminated() else 503 From 70a35ab421a83139f012ec469ee54164ef1efc89 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 18 Jul 2014 15:05:39 -0400 Subject: [PATCH 14/14] Some uninitialized build triggers may not yet have a write token. --- endpoints/api/trigger.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index 47d36a547..484601ee7 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -81,7 +81,9 @@ class BuildTrigger(RepositoryParamResource): 'service': trigger.service.name, 'config': config_dict}, repo=model.get_repository(namespace, repository)) - trigger.write_token.delete_instance() + if trigger.write_token is not None: + trigger.write_token.delete_instance() + trigger.delete_instance(recursive=True) return 'No Content', 204