• Notifications
  • Fork

    Where should we fork this repository?

    If this dialog fails to load, you can visit the fork page directly.

/lookit-api

[feature] docker image cleanup #113

Open
wants to merge 1 commit into from Jul 9, 2018
Commits
Jump to file or symbol
Failed to load files and symbols.
+49 −0
Diff settings

Always

Just for now

Finish your review
Select a reply ctrl .

Attach files by dragging & dropping, selecting them, or pasting from the clipboard. Uploading your files… We don’t support that file type. with a GIF, JPEG, JPG, PNG, DOCX, GZ, LOG, PDF, PPTX, TXT, XLSX or ZIP. Attaching documents requires write permission to this repository. with a GIF, JPEG, JPG, PNG, DOCX, GZ, LOG, PDF, PPTX, TXT, XLSX or ZIP. We don’t support that file type. with a GIF, JPEG, JPG, PNG, DOCX, GZ, LOG, PDF, PPTX, TXT, XLSX or ZIP. Yowza, that’s a big file with a file smaller than 10MB. This file is empty. with a file that’s not empty. This file is hidden. with another file. Something went really wrong, and we can’t process that file.

Nothing to preview

@@ -50,6 +50,10 @@ This task downloads videos from MIT's Amazon S3 bucket, zips them up, uploads th
This finds build directories older than a day and deletes them. It's scheduled to run every morning at 2am.
+## `cleanup_docker_images`
+
+This finds unused docker images from previous builds and deletes them. It's scheduled to run every morning at 3am.
+
## `cleanup_checkouts`
This finds checkout (extracted archives of github repos) directories older than a day and deletes them. It's scheduled to run every morning at 4am.
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.2 on 2018-07-06 19:33
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+three_am_crontab_schedule_dict = dict(
+ minute='0',
+ hour='3',
+ day_of_week='*',
+ day_of_month='*',
+ month_of_year='*'
+)
+cleanup_docker_images_periodic_task_dict = dict(
+ name='Nightly docker image cleanup',
+ task='studies.tasks.cleanup_docker_images'
+)
+
+
+def create_scheduled_jobs(apps, schema_editor):
+ CrontabSchedule = apps.get_model('django_celery_beat', 'CrontabSchedule')
+ PeriodicTask = apps.get_model('django_celery_beat', 'PeriodicTask')
+
+ three_am_crontab_schedule, created = CrontabSchedule.objects.get_or_create(**three_am_crontab_schedule_dict)
+ cleanup_docker_images_periodic_task_dict.update(dict(crontab=three_am_crontab_schedule))
+ cleanup_docker_images_periodic_task, created = PeriodicTask.objects.get_or_create(**cleanup_docker_images_periodic_task_dict)
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('studies', '0039_auto_20180219_1259'),
+ ]
+
+ operations = [
+ migrations.RunPython(create_scheduled_jobs)
+ ]
View
@@ -283,6 +283,14 @@ def cleanup_checkouts(older_than=None):
cleanup_old_directories(checkouts, older_than)
+@app.task
+def cleanup_docker_images():
+ logger.debug('Cleaning up docker images...')
+ images = subprocess.run(['docker', 'images', '--quiet', '--filter', 'dangling=true'], stdout=subprocess.PIPE)
+ for image in images.stdout.splitlines():
+ return subprocess.run(['docker', 'rmi', '--force', image])
+
+
@app.task(bind=True, max_retries=10, retry_backoff=10)
def build_zipfile_of_videos(self, filename, study_uuid, orderby, match, requesting_user_uuid, consent=False):
from studies.models import Study