mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
New plugin: minimize_size
It binds folders from the host machine to temporary and cache folders in the image. This way dynamic volumes will not grow in size when running `apt-get update` etc.
This commit is contained in:
parent
4ef77f1b69
commit
83e1339145
2 changed files with 57 additions and 0 deletions
16
plugins/minimize_size/__init__.py
Normal file
16
plugins/minimize_size/__init__.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import tasks
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_tasks(tasklist, manifest):
|
||||||
|
tasklist.add(tasks.AddFolderMounts,
|
||||||
|
tasks.RemoveFolderMounts)
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_rollback_tasks(tasklist, tasks_completed, manifest):
|
||||||
|
completed = [type(task) for task in tasks_completed]
|
||||||
|
|
||||||
|
def counter_task(task, counter):
|
||||||
|
if task in completed and counter not in completed:
|
||||||
|
tasklist.add(counter)
|
||||||
|
|
||||||
|
counter_task(tasks.AddFolderMounts, tasks.RemoveFolderMounts)
|
41
plugins/minimize_size/tasks.py
Normal file
41
plugins/minimize_size/tasks.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
from base import Task
|
||||||
|
from common import phases
|
||||||
|
from common.tasks import bootstrap
|
||||||
|
from common.tasks import apt
|
||||||
|
import os
|
||||||
|
|
||||||
|
folders = ['tmp', 'var/lib/apt/lists']
|
||||||
|
|
||||||
|
|
||||||
|
class AddFolderMounts(Task):
|
||||||
|
description = 'Mounting folders for writing temporary and cache data'
|
||||||
|
phase = phases.os_installation
|
||||||
|
predecessors = [bootstrap.Bootstrap]
|
||||||
|
|
||||||
|
def run(self, info):
|
||||||
|
info.minimize_size_folder = os.path.join(info.workspace, 'minimize_size')
|
||||||
|
os.mkdir(info.minimize_size_folder)
|
||||||
|
for folder in folders:
|
||||||
|
temp_path = os.path.join(info.minimize_size_folder, folder.replace('/', '_'))
|
||||||
|
os.mkdir(temp_path)
|
||||||
|
|
||||||
|
full_path = os.path.join(info.root, folder)
|
||||||
|
info.volume.partition_map.root.add_mount(temp_path, full_path, ['--bind'])
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveFolderMounts(Task):
|
||||||
|
description = 'Removing folder mounts for temporary and cache data'
|
||||||
|
phase = phases.system_cleaning
|
||||||
|
successors = [apt.AptClean]
|
||||||
|
|
||||||
|
def run(self, info):
|
||||||
|
import shutil
|
||||||
|
for folder in folders:
|
||||||
|
temp_path = os.path.join(info.minimize_size_folder, folder.replace('/', '_'))
|
||||||
|
full_path = os.path.join(info.root, folder)
|
||||||
|
|
||||||
|
info.volume.partition_map.root.remove_mount(full_path)
|
||||||
|
shutil.rmtree(temp_path)
|
||||||
|
|
||||||
|
os.rmdir(info.minimize_size_folder)
|
||||||
|
del info.minimize_size_folder
|
Loading…
Add table
Reference in a new issue