diff --git a/.vscode/tasks.json b/.vscode/tasks.json index eee9aa7..a038ef4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -170,6 +170,17 @@ "id": "terminal", "color": "terminal.ansiMagenta" } + }, + { + "label": "util: clear images", + "command": "python3", + "args": [ + "tools${pathSeparator}clear-images.py" + ], + "icon": { + "id": "terminal", + "color": "terminal.ansiMagenta" + } } ], "inputs": [ diff --git a/README.md b/README.md index bc9705b..d372458 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Microsoft Azure CLI Extension for creating (or _"baking"_) custom virtual machin To install the Azure CLI Custom Image Helper extension, simply run the following command: ```sh -az extension add --source https://github.com/colbylwilliams/az-bake/releases/latest/download/bake-0.3.9-py3-none-any.whl -y +az extension add --source https://github.com/colbylwilliams/az-bake/releases/latest/download/bake-0.3.10-py3-none-any.whl -y ``` ### Update diff --git a/bake/HISTORY.rst b/bake/HISTORY.rst index 3d7a6ed..de162b9 100644 --- a/bake/HISTORY.rst +++ b/bake/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +0.3.10 +++++++ +* Revert bug that could create log file + 0.3.9 ++++++ * Save all image config files to builder storage diff --git a/bake/azext_bake/_utils.py b/bake/azext_bake/_utils.py index 1cc6d62..becc73b 100644 --- a/bake/azext_bake/_utils.py +++ b/bake/azext_bake/_utils.py @@ -18,7 +18,7 @@ from azure.cli.core.azclierror import FileOperationError, ValidationError from knack.log import get_logger as knack_get_logger -from ._constants import OUTPUT_DIR, STORAGE_DIR +from ._constants import IN_BUILDER, OUTPUT_DIR, STORAGE_DIR from ._data import ChocoPackage, Image, PowershellScript, get_dict @@ -26,8 +26,9 @@ def get_logger(name): '''Get the logger for the extension''' _logger = knack_get_logger(name) - # if IN_BUILDER and STORAGE_DIR.is_dir(): - if STORAGE_DIR.is_dir(): + # this must only happen in the builder, otherwise + # the log file could be created on users machines + if IN_BUILDER and STORAGE_DIR.is_dir(): import logging log_file = OUTPUT_DIR / 'builder.log' formatter = logging.Formatter('{asctime} [{name:^28}] {levelname:<8}: {message}', diff --git a/bake/setup.py b/bake/setup.py index a42dc19..90b7d06 100644 --- a/bake/setup.py +++ b/bake/setup.py @@ -17,7 +17,7 @@ logger.warn("Wheel is not available, disabling bdist_wheel hook") # Must match a HISTORY.rst entry. -VERSION = '0.3.9' +VERSION = '0.3.10' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers diff --git a/builder/Dockerfile b/builder/Dockerfile index fad8fce..412a3f2 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -38,7 +38,7 @@ LABEL maintainer="Microsoft" \ RUN apk add --no-cache packer --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community # install az-bake -RUN az extension add --source https://github.com/colbylwilliams/az-bake/releases/latest/download/bake-0.3.9-py3-none-any.whl -y +RUN az extension add --source https://github.com/colbylwilliams/az-bake/releases/latest/download/bake-0.3.10-py3-none-any.whl -y # Terminate container on stop STOPSIGNAL SIGTERM diff --git a/tools/clear-images.py b/tools/clear-images.py new file mode 100644 index 0000000..a94bd0b --- /dev/null +++ b/tools/clear-images.py @@ -0,0 +1,22 @@ +from os import walk +from pathlib import Path +from shutil import rmtree + +REPO_DIR = Path(__file__).resolve().parent.parent +IMAGES_DIR = REPO_DIR / 'images' + +files_del = [] +dirs_del = [] + +# walk the images directory and find all the child directories +for dirpath, dirnames, files in walk(IMAGES_DIR): + # os.walk includes the root directory (i.e. repo/images) so we need to skip it + if not IMAGES_DIR.samefile(dirpath) and Path(dirpath).parent.samefile(IMAGES_DIR): + files_del.extend([Path(dirpath) / f for f in files if not f.lower() == 'image.yaml' and not f.lower() == 'image.yml']) + dirs_del.extend([Path(dirpath) / d for d in dirnames]) + +for f in files_del: + f.unlink() + +for d in dirs_del: + rmtree(d)