Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to override default boxes cache location #75

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/source/commands/system_boxbuild.rst
Original file line number Diff line number Diff line change
@@ -174,6 +174,15 @@ OPTIONS
the virtual machine. See the Example below how to provide
options to the build command correctly.

ENVIRONMENT
-----------

KIWI_BOXED_CACHE_DIR
By default, VM disk images used as build environment are
stored in $HOME/.kiwi_boxes directory. To override this
location, KIWI_BOXED_CACHE_DIR environment variable should
be set to a different absolute path.

EXAMPLE
-------

9 changes: 8 additions & 1 deletion kiwi_boxed_plugin/defaults.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,9 @@
#
import os
import pathlib
from typing import List
from typing import (
List, Optional
)
from kiwi.path import Path
from pkg_resources import resource_filename
import subprocess
@@ -79,6 +81,11 @@ def get_plugin_config_file() -> str:

@staticmethod
def get_local_box_cache_dir() -> str:
local_box_cache_dir_env: Optional[str] = os.environ.get(
'KIWI_BOXED_CACHE_DIR'
)
if local_box_cache_dir_env and os.path.isdir(local_box_cache_dir_env):
return local_box_cache_dir_env
return f'{os.environ.get("HOME")}/.kiwi_boxes'

@staticmethod
19 changes: 19 additions & 0 deletions test/unit/box_download_test.py
Original file line number Diff line number Diff line change
@@ -42,6 +42,25 @@ def setup_method(
):
self.setup()

@patch('kiwi_boxed_plugin.defaults.Defaults.get_plugin_config_file')
@patch('kiwi_boxed_plugin.box_download.Path')
@patch('kiwi_boxed_plugin.box_download.DirFiles')
@patch('os.path.isdir')
def test_custom_box_cache_dir(
self, mock_os_path_isdir, mock_DirFiles, mock_Path,
mock_get_plugin_config_file
):
mock_os_path_isdir.return_value = True
mock_DirFiles.return_value = \
Mock().register.return_value = 'register_file'
mock_get_plugin_config_file.return_value = \
'../data/kiwi_boxed_plugin.yml'
with patch.dict('os.environ', {'KIWI_BOXED_CACHE_DIR': '/some/custom/dir'}):
BoxDownload('suse', 'x86_64')
mock_Path.create.assert_called_once_with(
'/some/custom/dir/suse'
)

@patch('kiwi_boxed_plugin.box_download.Command.run')
@patch('kiwi_boxed_plugin.box_download.Uri')
@patch('kiwi_boxed_plugin.box_download.SolverRepository.new')