summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rwxr-xr-xbuild/build_nexus_blob.sh41
-rwxr-xr-xbuild/download/clean_docker_images.py71
-rw-r--r--build/download/downloader.py4
3 files changed, 98 insertions, 18 deletions
diff --git a/build/build_nexus_blob.sh b/build/build_nexus_blob.sh
index f3edb482..5f4ed0ff 100755
--- a/build/build_nexus_blob.sh
+++ b/build/build_nexus_blob.sh
@@ -53,31 +53,41 @@ NEXUS_EMAIL=admin@example.org
LOCAL_PATH="$(readlink -f $(dirname ${0}))"
#Defaults
+DOCKER_LOAD="false"
DATA_DIR="$(realpath ${LOCAL_PATH}/../../resources)"
NEXUS_DATA_DIR="${DATA_DIR}/nexus_data"
LISTS_DIR="${LOCAL_PATH}/data_lists"
usage () {
echo " Example usage: build_nexus_blob.sh --input-directory </path/to/downloaded/files/dir> --output-directory
- </path/to/output/dir> --resource-list-directory </path/to/dir/with/resource/list>
+ </path/to/output/dir> --resource-list-directory </path/to/dir/with/resource/list> [--load-docker-images]
- -i | --input-directory directory containing file needed to create nexus blob. The structure of this directory must organized as described in build guide
- -o | --output-directory
- -rl | --resource-list-directory directory with files containing docker, pypi and npm lists
+ -i | --input-directory directory containing file needed to create nexus blob. The structure of this directory must organized as described in build guide
+ -ld | --load-docker-images load docker images from stored files in the input directory
+ -o | --output-directory
+ -rl | --resource-list-directory directory with files containing docker, pypi and npm lists
"
exit 1
}
-while [ "$1" != "" ]; do
- case $1 in
+load_docker_images () {
+ for ARCHIVE in $(sed $'s/\r// ; /^#/d ; s/\:/\_/g ; s/\//\_/g ; s/$/\.tar/g' ${1} | awk '{ print $1 }'); do
+ docker load -i ${NXS_SRC_DOCKER_IMG_DIR}/${ARCHIVE}
+ done
+}
+
+while [ "${1}" != "" ]; do
+ case ${1} in
-i | --input-directory ) shift
- DATA_DIR=$1
+ DATA_DIR="${1}"
+ ;;
+ -ld | --load-docker-images ) DOCKER_LOAD="true"
;;
-o | --output-directory ) shift
- NEXUS_DATA_DIR=$1
+ NEXUS_DATA_DIR="${1}"
;;
-rl | --resource-list-directory ) shift
- LISTS_DIR=$1
+ LISTS_DIR="${1}"
;;
-h | --help ) usage
;;
@@ -179,13 +189,12 @@ fi
# Docker repository preparation #
#################################
-# Load predefined Nexus image
-docker load -i ${NEXUS_IMAGE_TAR}
-
-# Load all necessary images
-for ARCHIVE in $(sed $'s/\r// ; /^#/d ; s/\:/\_/g ; s/\//\_/g ; s/$/\.tar/g' ${NXS_DOCKER_IMG_LIST} | awk '{ print $1 }'); do
- docker load -i ${NXS_SRC_DOCKER_IMG_DIR}/${ARCHIVE}
-done
+if [ "${DOCKER_LOAD}" == "true" ]; then
+ # Load predefined Nexus image
+ docker load -i ${NEXUS_IMAGE_TAR}
+ # Load all necessary images
+ load_docker_images ${NXS_DOCKER_IMG_LIST}
+fi
################################
# Nexus repository preparation #
diff --git a/build/download/clean_docker_images.py b/build/download/clean_docker_images.py
new file mode 100755
index 00000000..186bfd60
--- /dev/null
+++ b/build/download/clean_docker_images.py
@@ -0,0 +1,71 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+# COPYRIGHT NOTICE STARTS HERE
+
+# Copyright 2019 © Samsung Electronics Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# COPYRIGHT NOTICE ENDS HERE
+
+
+import argparse
+import docker
+import logging
+import sys
+
+from downloader import AbstractDownloader
+from docker_downloader import DockerDownloader
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('image_lists', nargs='+', help='Images to keep')
+ parser.add_argument('--debug', '-d', action='store_true', help='Debugging messages')
+ args = parser.parse_args()
+
+ if args.debug:
+ logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
+ else:
+ logging.basicConfig(level=logging.INFO, stream=sys.stdout, format='%(message)s')
+
+ target = set()
+ for lst in args.image_lists:
+ target = target.union(AbstractDownloader.load_list(lst))
+
+ target = set(map(DockerDownloader.image_registry_name, target))
+
+ client = docker.client.DockerClient(version='auto')
+
+ errors = 0
+ for image in client.images.list():
+ for tag in image.tags:
+ logging.debug('Checking {}'.format(tag))
+ if tag not in target:
+ logging.debug('Image \'{}\' not in lists'.format(tag))
+ logging.info('Removing: {}'.format(tag))
+ try:
+ client.images.remove(tag)
+ logging.info('Removed: {}'.format(tag))
+ except docker.errors.APIError as err:
+ errors += 1
+ logging.exception(err)
+ else:
+ logging.debug('Image \'{}\' found in lists.'.format(tag))
+ sys.exit(errors)
+
+
+if __name__ == '__main__':
+ main()
+
diff --git a/build/download/downloader.py b/build/download/downloader.py
index 64403300..7aece0cd 100644
--- a/build/download/downloader.py
+++ b/build/download/downloader.py
@@ -32,7 +32,7 @@ class AbstractDownloader(ABC):
def __init__(self, list_type, *list_args):
self._list_type = list_type
self._data_list = {item: list_arg[1] for list_arg in list_args
- for item in self._load_list(list_arg[0])}
+ for item in self.load_list(list_arg[0])}
self._missing = self.missing()
@property
@@ -43,7 +43,7 @@ class AbstractDownloader(ABC):
return self._list_type
@staticmethod
- def _load_list(path):
+ def load_list(path):
"""
Load list from file.
:param path: path to file