def delete_container_collection(cid, uid): '''Delete artifacts for a container build, if they exist, and then the entire collection. This is called as a django-rq task for a worker to do from views.py Parameters ========== cid: the collection id to delete. uid: the user id requesting permission ''' from shub.apps.main.views import get_collection from .github import delete_webhook collection = get_collection(cid) # Delete files before containers containers = Container.objects.filter(collection=collection) # Create a client to share context = get_build_context() client = get_client(debug=True, **context) # Delete container build objects first for container in containers: delete_build(cid=container.id, client=client) # Now handle the webhook (a separate task) if "github" in collection.metadata: django_rq.enqueue(delete_webhook, user=uid, repo=collection.metadata['github']['repo_name'], hook_id=collection.metadata['github']['webhook']['id']) # Finally, delete the collection print("%s deleting." % collection) collection.delete()
def parse_hook(cid, branch="master", commits=None): """parse hook will take a request and an associated user collection, and finish parsing. This means generating the new container, and submitting a job to run on Google Cloud Build. """ from shub.apps.main.views import get_collection print("RUNNING PARSE HOOK") collection = get_collection(cid) # Determine changed Singularity file(s) if commits is None: return build_previous_commits(collection, branch) return build_commits(collection, commits, branch)
def prepare_build_task(cid, recipes, branch): """wrapper to prepare build, to run as a task Parameters ========== cid: the collection id to retrieve the collection recipes: a dictionary of modified recipe files to build branch: the repository branch (kept as metadata) """ print("RUNNING PREPARE BUILD TASK WITH RECIPES %s" % recipes) from .actions import receive_build from shub.apps.main.views import get_collection collection = get_collection(cid) receive_build(collection=collection, recipes=recipes, branch=branch)
def _delete_collection(request, cid): '''the underlying function to delete a collection, returns True/False if done to the calling view. Parameters ========== cid: the collection id to delete ''' collection = get_collection(cid) # Only an owner can delete if not collection.has_edit_permission(request): return False # Queue the job to delete the collection django_rq.enqueue(delete_container_collection, cid=collection.id, uid=request.user.id) return True
def delete_collection(request, cid): '''delete a container collection that has Google Builds Parameters ========== cid: the collection id to delete ''' collection = get_collection(cid) # Only an owner can delete if not collection.has_edit_permission(request): messages.info(request, "This action is not permitted.") return redirect('collections') # Queue the job to delete the collection django_rq.enqueue(delete_container_collection, cid=collection.id, uid=request.user.id) messages.info(request, 'Collection requested for deletion.') return redirect('collections')