Skip to content

Commit

Permalink
Allow to override default boxes cache location
Browse files Browse the repository at this point in the history
If KIWI_BOXED_CACHE_DIR environment variable is set,
it will be used to store kiwi boxes used for build.
-------
Co-authored-by: Marcus Schäfer <[email protected]>
  • Loading branch information
fcrozat authored Jan 7, 2025
1 parent efdd0cf commit 99a4b1b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/source/commands/system_boxbuild.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
9 changes: 8 additions & 1 deletion kiwi_boxed_plugin/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/unit/box_download_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 99a4b1b

Please sign in to comment.