Add ability to re-run a dockerfile build

This commit is contained in:
Joseph Schorr 2014-02-14 18:37:06 -05:00
parent 540da00c64
commit 55d846061e
4 changed files with 67 additions and 2 deletions

View file

@ -763,6 +763,16 @@ def get_all_repo_users(namespace_name, repository_name):
Repository.name == repository_name) Repository.name == repository_name)
def get_repository_for_resource(resource_key):
joined = Repository.select().join(RepositoryBuild)
query = joined.where(RepositoryBuild.resource_key == resource_key).limit(1)
result = list(query)
if not result:
return None
return result[0]
def get_repository(namespace_name, repository_name): def get_repository(namespace_name, repository_name):
try: try:
return Repository.get(Repository.name == repository_name, return Repository.get(Repository.name == repository_name,

View file

@ -1157,6 +1157,7 @@ def build_status_view(build_obj):
'started': build_obj.started, 'started': build_obj.started,
'display_name': build_obj.display_name, 'display_name': build_obj.display_name,
'status': status, 'status': status,
'resource_key': build_obj.resource_key
} }
@ -1221,6 +1222,14 @@ def request_repo_build(namespace, repository):
logger.debug('User requested repository initialization.') logger.debug('User requested repository initialization.')
dockerfile_id = request.get_json()['file_id'] dockerfile_id = request.get_json()['file_id']
# Check if the dockerfile resource has already been used. If so, then it can only be reused if the
# user has access to the repository for which it was used.
associated_repository = model.get_repository_for_resource(dockerfile_id)
if associated_repository:
if not ModifyRepositoryPermission(associated_repository.namespace, associated_repository.name):
abort(403)
# Start the build.
repo = model.get_repository(namespace, repository) repo = model.get_repository(namespace, repository)
token = model.create_access_token(repo, 'write') token = model.create_access_token(repo, 'write')
display_name = user_files.get_file_checksum(dockerfile_id) display_name = user_files.get_file_checksum(dockerfile_id)

View file

@ -785,7 +785,28 @@ function RepoBuildCtrl($scope, Restangular, ApiService, $routeParams, $rootScope
$scope.polling = false; $scope.polling = false;
$scope.adjustLogHeight = function() { $scope.adjustLogHeight = function() {
$('.build-logs').height($(window).height() - 365); $('.build-logs').height($(window).height() - 385);
};
$scope.askRestartBuild = function(build) {
$('#confirmRestartBuildModal').modal({});
};
$scope.restartBuild = function(build) {
$('#confirmRestartBuildModal').modal('hide');
var data = {
'file_id': build['resource_key']
};
var params = {
'repository': namespace + '/' + name
};
ApiService.requestRepoBuild(data, params).then(function(newBuild) {
$scope.builds.push(newBuild);
$scope.setCurrentBuild(newBuild['id'], true);
});
}; };
$scope.hasLogs = function(container) { $scope.hasLogs = function(container) {

View file

@ -72,12 +72,37 @@
</div> </div>
</div> </div>
</div> </div>
<div> <div style="margin-top: 10px">
<span class="quay-spinner" ng-show="polling"></span> <span class="quay-spinner" ng-show="polling"></span>
<button class="btn btn-default" ng-show="(build.phase == 'error' || build.phase == 'complete') && build.resource_key"
ng-click="askRestartBuild(build)">
<i class="fa fa-refresh"></i>
Run Build Again
</button>
<span class="build-id">{{ build.id }}</span> <span class="build-id">{{ build.id }}</span>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Modal message dialog -->
<div class="modal fade" id="confirmRestartBuildModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Run Dockerfile Build?</h4>
</div>
<div class="modal-body">
Are you sure you want to run this Dockerfile build again? The results will be immediately pushed to the repository.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" ng-click="restartBuild(currentBuild)">Run Build</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div> </div>