From c428c8e02944912b449b058e092bdd9c10f4c449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=BC=E7=A0=BC?= Date: Wed, 8 Sep 2021 20:38:08 +0800 Subject: [PATCH] chore(all): update to 0.7.2 --- README_EN.md | 34 ++++++++++--- docker/Dockerfile | 6 ++- global_config.json | 3 +- redpill_tool_chain.sh | 108 +++++++++++++++++++++++++++------------- user_config.simple.json | 10 ---- 5 files changed, 105 insertions(+), 56 deletions(-) delete mode 100644 user_config.simple.json diff --git a/README_EN.md b/README_EN.md index 3bb2f37..4ab0ffd 100644 --- a/README_EN.md +++ b/README_EN.md @@ -7,14 +7,13 @@ THX @haydibe - Takes care of downloading (and caching) the required sources to compile redpill.ko and the required os packages that the build process depends on. - Caches .pat downloads inside the container on the host. - Configuration is done in the JSON file `global_config.json`; custom entries can be added underneath the `building_configs` block. Make sure the id is unique per block! -- Support a `user_config.json` per -- ALlow to bind a local redpill-load folder into the container (set `"docker.local_rp_load_use": "true"` and set `"docker.local_rp_load_path": "path/to/rp-load"`) +- Supports a `user_config.json` per +- Supports to bind a local redpill-load folder into the container (set `"docker.local_rp_load_use": "true"` and set `"docker.local_rp_load_path": "path/to/rp-load"`) +- Supports to clean old image versions and the build cache per or for `all` of them at once. +- Supports to auto clean old image versions and the build cache for the current build image, set `"docker.auto_clean":`to `"true"`. ## Changes -- removed `user_config.json.template`, as it was orphaned and people started to use it in an unintended way. -- new parameters in `global_config.json`: --- `docker.local_rp_load_use`: wether to mount a local folder with redpill-load into the build container (true/false) --- `docker.local_rp_load_path`: path to the local copy of redpill-load to mount into the build container (absolute or relative path) --- `build_configs[].user_config_json`: allows to defina a user_config.json per . +- `clean` now cleans the build cache as well +- added `auto_clean` to clean old images and build cache after building the image. ## Usage @@ -41,7 +40,7 @@ Examples: ./redpill_tool_chain.sh Usage: ./redpill_tool_chain.sh -Actions: build, auto, run +Actions: build, auto, run, clean - build: Build the toolchain image for the specified platform version. @@ -51,24 +50,43 @@ Actions: build, auto, run - run: Starts the toolchain container using the previously built toolchain image for the specified platform. Interactive Bash terminal. +- clean: Removes old (=dangling) images and the build cache for a platform version. + Use `all` as platform version to remove images and build caches for all platform versions. + Available platform versions: --------------------- bromolow-6.2.4-25556 bromolow-7.0-41222 +bromolow-7.0.1-42214 apollolake-6.2.4-25556 apollolake-7.0-41890 +apollolake-7.0.1-42214 ``` ### Build toolchain image For Bromolow 6.2.4 : `./redpill_tool_chain.sh build bromolow-6.2.4-25556` For Bromolow 7.0 : `./redpill_tool_chain.sh build bromolow-7.0-41222` +For Bromolow 7.0.1 : `./redpill_tool_chain.sh build bromolow-7.0.1-42214` For Apollolake 6.2.4 : `./redpill_tool_chain.sh build apollolake-6.2.4-25556` For Apollolake 7.0 : `./redpill_tool_chain.sh build apollolake-7.0-41890` +For Apollolake 7.0.1 : `./redpill_tool_chain.sh build apollolake-7.0.1-42214` ### Create redpill bootloader image For Bromolow 6.2.4 : `./redpill_tool_chain.sh auto bromolow-6.2.4-25556` For Bromolow 7.0 : `./redpill_tool_chain.sh auto bromolow-7.0-41222` +For Bromolow 7.0.1 : `./redpill_tool_chain.sh auto bromolow-7.0.1-42214` For Apollolake 6.2.4 : `./redpill_tool_chain.sh auto apollolake-6.2.4-25556` For Apollolake 7.0 : `./redpill_tool_chain.sh auto apollolake-7.0-41890` +For Apollolake 7.0.1 : `./redpill_tool_chain.sh auto apollolake-7.0.1-42214` + +### Clean old redpill bootloader images and build cache + +For Bromolow 6.2.4 : `./redpill_tool_chain.sh clean bromolow-6.2.4-25556` +For Bromolow 7.0 : `./redpill_tool_chain.sh clean bromolow-7.0-41222` +For Bromolow 7.0.1 : `./redpill_tool_chain.sh clean bromolow-7.0.1-42214` +For Apollolake 6.2.4 : `./redpill_tool_chain.sh clean apollolake-6.2.4-25556` +For Apollolake 7.0 : `./redpill_tool_chain.sh clean apollolake-7.0-41890` +For Apollolake 7.0.1 : `./redpill_tool_chain.sh clean apollolake-7.0.1-42214` +For all : `./redpill_tool_chain.sh clean all` diff --git a/docker/Dockerfile b/docker/Dockerfile index bfd2605..bb08242 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,11 +8,13 @@ ADD downloads/${KERNEL_SRC_FILENAME} / # tool chain image FROM ${DOCKER_BASE_IMAGE} +LABEL redpill-tool-chain=${TARGET_PLATFORM}-${TARGET_VERSION}-${TARGET_REVISION} + ARG DEBIAN_FRONTEND=noninteractive RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak && \ sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list && \ sed -i "s/security.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list && \ - apt-get update && \ + apt-get update && \ apt-get install --yes --no-install-recommends ca-certificates build-essential git libssl-dev curl cpio bspatch vim gettext bc bison flex dosfstools kmod jq && \ rm -rf /var/lib/apt/lists/* /tmp/* @@ -58,4 +60,4 @@ COPY Makefile /opt/ COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/global_config.json b/global_config.json index db1f62d..019e1ec 100644 --- a/global_config.json +++ b/global_config.json @@ -4,7 +4,8 @@ "image_name": "redpill-tool-chain", "download_folder": "docker/downloads", "local_rp_load_use": "false", - "local_rp_load_path": "./redpill-load" + "local_rp_load_path": "./redpill-load", + "auto_clean": "false" }, "build_configs": [ { diff --git a/redpill_tool_chain.sh b/redpill_tool_chain.sh index bac78f1..4d1f22c 100755 --- a/redpill_tool_chain.sh +++ b/redpill_tool_chain.sh @@ -13,7 +13,7 @@ function getValueByJsonPath(){ function buildImage(){ [ "${USE_BUILDKIT}" == "true" ] && export DOCKER_BUILDKIT=1 - docker build --file docker/Dockerfile --no-cache --force-rm --pull \ + docker build --file docker/Dockerfile --force-rm --pull \ --build-arg DOCKER_BASE_IMAGE="${DOCKER_BASE_IMAGE}" \ --build-arg COMPILE_WITH="${COMPILE_WITH}" \ --build-arg EXTRACTED_KSRC="${EXTRACTED_KSRC}" \ @@ -27,7 +27,29 @@ function buildImage(){ --build-arg DSM_VERSION="${DSM_VERSION}" \ --build-arg TARGET_REVISION="${TARGET_REVISION}" \ --tag ${DOCKER_IMAGE_NAME}:${TARGET_PLATFORM}-${TARGET_VERSION}-${TARGET_REVISION} ./docker - } +} + +function clean(){ + if [ "${AUTO_CLEAN}" != "true" ]; then + echo "---------- before clean --------------------------------------" + docker system df + fi + if [ "${ID}" == "all" ];then + OLD_IMAGES=$(docker image ls --filter label=redpill-tool-chain --filter dangling=true --quiet) + docker builder prune --filter label=redpill-tool-chain --force + else + OLD_IMAGES=$(docker image ls --filter label=redpill-tool-chain=${TARGET_PLATFORM}-${TARGET_VERSION}-${TARGET_REVISION} --filter dangling=true --quiet) + docker builder prune --filter label=redpill-tool-chain=${TARGET_PLATFORM}-${TARGET_VERSION}-${TARGET_REVISION} --force + fi + + if [ ! -z "${OLD_IMAGES}" ]; then + docker image rm ${OLD_IMAGES} + fi + if [ "${AUTO_CLEAN}" != "true" ]; then + echo "---------- after clean ---------------------------------------" + docker system df + fi +} function runContainer(){ local CMD=${1} @@ -69,7 +91,7 @@ function showHelp(){ cat << EOF Usage: ${0} -Actions: build, auto, run +Actions: build, auto, run, clean - build: Build the toolchain image for the specified platform version. @@ -79,6 +101,9 @@ Actions: build, auto, run - run: Starts the toolchain container using the previously built toolchain image for the specified platform. Interactive Bash terminal. +- clean: Removes old (=dangling) images and the build cache for a platform version. + Use `all` as platform version to remove images and build caches for all platform versions. + Available platform versions: --------------------- ${AVAILABLE_IDS} @@ -102,6 +127,7 @@ REDPILL_LOAD_IMAGES=${PWD}/images # parse paramters from config CONFIG=$(readConfig) AVAILABLE_IDS=$(getValueByJsonPath ".build_configs[].id" "${CONFIG}") +AUTO_CLEAN=$(getValueByJsonPath ".docker.auto_clean" "${CONFIG}") if [ $# -lt 2 ]; then showHelp @@ -110,47 +136,60 @@ fi ACTION=${1} ID=${2} -BUILD_CONFIG=$(getValueByJsonPath ".build_configs[] | select(.id==\"${ID}\")" "${CONFIG}") -if [ -z "${BUILD_CONFIG}" ];then - echo "Error: Platform version ${ID} not specified in global_config.json" - echo - showHelp - exit 1 -fi -USE_BUILDKIT=$(getValueByJsonPath ".docker.use_buildkit" "${CONFIG}") -DOCKER_IMAGE_NAME=$(getValueByJsonPath ".docker.image_name" "${CONFIG}") -DOWNLOAD_FOLDER=$(getValueByJsonPath ".docker.download_folder" "${CONFIG}") -LOCAL_RP_LOAD_USE=$(getValueByJsonPath ".docker.local_rp_load_use" "${CONFIG}") -LOCAL_RP_LOAD_PATH=$(getValueByJsonPath ".docker.local_rp_load_path" "${CONFIG}") -TARGET_PLATFORM=$(getValueByJsonPath ".platform_version | split(\"-\")[0]" "${BUILD_CONFIG}") -TARGET_VERSION=$(getValueByJsonPath ".platform_version | split(\"-\")[1]" "${BUILD_CONFIG}") -DSM_VERSION=$(getValueByJsonPath ".platform_version | split(\"-\")[1][0:3]" "${BUILD_CONFIG}") -TARGET_REVISION=$(getValueByJsonPath ".platform_version | split(\"-\")[2]" "${BUILD_CONFIG}") -USER_CONFIG_JSON=$(getValueByJsonPath ".user_config_json" "${BUILD_CONFIG}") -DOCKER_BASE_IMAGE=$(getValueByJsonPath ".docker_base_image" "${BUILD_CONFIG}") -KERNEL_DOWNLOAD_URL=$(getValueByJsonPath ".download_urls.kernel" "${BUILD_CONFIG}") -COMPILE_WITH=$(getValueByJsonPath ".compile_with" "${BUILD_CONFIG}") -KERNEL_FILENAME=$(getValueByJsonPath ".download_urls.kernel | split(\"/\")[] | select ( . | endswith(\".txz\"))" "${BUILD_CONFIG}") -TOOLKIT_DEV_DOWNLOAD_URL=$(getValueByJsonPath ".download_urls.toolkit_dev" "${BUILD_CONFIG}") -TOOLKIT_DEV_FILENAME=$(getValueByJsonPath ".download_urls.toolkit_dev | split(\"/\")[] | select ( . | endswith(\".txz\"))" "${BUILD_CONFIG}") -REDPILL_LKM_REPO=$(getValueByJsonPath ".redpill_lkm.source_url" "${BUILD_CONFIG}") -REDPILL_LKM_BRANCH=$(getValueByJsonPath ".redpill_lkm.branch" "${BUILD_CONFIG}") -REDPILL_LOAD_REPO=$(getValueByJsonPath ".redpill_load.source_url" "${BUILD_CONFIG}") -REDPILL_LOAD_BRANCH=$(getValueByJsonPath ".redpill_load.branch" "${BUILD_CONFIG}") -EXTRACTED_KSRC='/linux*' -if [ "${COMPILE_WITH}" == "toolkit_dev" ]; then - EXTRACTED_KSRC="/usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${DSM_VERSION}/build/" +if [ "${ID}" != "all" ]; then + BUILD_CONFIG=$(getValueByJsonPath ".build_configs[] | select(.id==\"${ID}\")" "${CONFIG}") + if [ -z "${BUILD_CONFIG}" ];then + echo "Error: Platform version ${ID} not specified in global_config.json" + echo + showHelp + exit 1 + fi + USE_BUILDKIT=$(getValueByJsonPath ".docker.use_buildkit" "${CONFIG}") + DOCKER_IMAGE_NAME=$(getValueByJsonPath ".docker.image_name" "${CONFIG}") + DOWNLOAD_FOLDER=$(getValueByJsonPath ".docker.download_folder" "${CONFIG}") + LOCAL_RP_LOAD_USE=$(getValueByJsonPath ".docker.local_rp_load_use" "${CONFIG}") + LOCAL_RP_LOAD_PATH=$(getValueByJsonPath ".docker.local_rp_load_path" "${CONFIG}") + TARGET_PLATFORM=$(getValueByJsonPath ".platform_version | split(\"-\")[0]" "${BUILD_CONFIG}") + TARGET_VERSION=$(getValueByJsonPath ".platform_version | split(\"-\")[1]" "${BUILD_CONFIG}") + DSM_VERSION=$(getValueByJsonPath ".platform_version | split(\"-\")[1][0:3]" "${BUILD_CONFIG}") + TARGET_REVISION=$(getValueByJsonPath ".platform_version | split(\"-\")[2]" "${BUILD_CONFIG}") + USER_CONFIG_JSON=$(getValueByJsonPath ".user_config_json" "${BUILD_CONFIG}") + DOCKER_BASE_IMAGE=$(getValueByJsonPath ".docker_base_image" "${BUILD_CONFIG}") + KERNEL_DOWNLOAD_URL=$(getValueByJsonPath ".download_urls.kernel" "${BUILD_CONFIG}") + COMPILE_WITH=$(getValueByJsonPath ".compile_with" "${BUILD_CONFIG}") + KERNEL_FILENAME=$(getValueByJsonPath ".download_urls.kernel | split(\"/\")[] | select ( . | endswith(\".txz\"))" "${BUILD_CONFIG}") + TOOLKIT_DEV_DOWNLOAD_URL=$(getValueByJsonPath ".download_urls.toolkit_dev" "${BUILD_CONFIG}") + TOOLKIT_DEV_FILENAME=$(getValueByJsonPath ".download_urls.toolkit_dev | split(\"/\")[] | select ( . | endswith(\".txz\"))" "${BUILD_CONFIG}") + REDPILL_LKM_REPO=$(getValueByJsonPath ".redpill_lkm.source_url" "${BUILD_CONFIG}") + REDPILL_LKM_BRANCH=$(getValueByJsonPath ".redpill_lkm.branch" "${BUILD_CONFIG}") + REDPILL_LOAD_REPO=$(getValueByJsonPath ".redpill_load.source_url" "${BUILD_CONFIG}") + REDPILL_LOAD_BRANCH=$(getValueByJsonPath ".redpill_load.branch" "${BUILD_CONFIG}") + + EXTRACTED_KSRC='/linux*' + if [ "${COMPILE_WITH}" == "toolkit_dev" ]; then + EXTRACTED_KSRC="/usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${DSM_VERSION}/build/" + fi +else + if [ "${ACTION}" != "clean" ]; then + echo "All is not supported for action \"${ACTION}\"" + exit 1 + fi fi case "${ACTION}" in build) downloadFromUrlIfNotExists "${KERNEL_DOWNLOAD_URL}" "${DOWNLOAD_FOLDER}/${KERNEL_FILENAME}" "Kernel" downloadFromUrlIfNotExists "${TOOLKIT_DEV_DOWNLOAD_URL}" "${DOWNLOAD_FOLDER}/${TOOLKIT_DEV_FILENAME}" "Toolkit Dev" buildImage + if [ "${AUTO_CLEAN}" == "true" ]; then + clean + fi ;; run) runContainer "run" ;; - auto) runContainer "auto" + auto) runContainer "auto" + ;; + clean) clean ;; *) if [ ! -z ${ACTION} ];then echo "Error: action ${ACTION} does not exist" @@ -160,4 +199,3 @@ case "${ACTION}" in exit 1 ;; esac - diff --git a/user_config.simple.json b/user_config.simple.json deleted file mode 100644 index 2cea412..0000000 --- a/user_config.simple.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extra_cmdline": { - "vid": "0x1908", - "pid": "0x0226", - "sn": "1780PDN123456", - "mac1": "00505623F398" - }, - "synoinfo": {}, - "ramdisk_copy": {} -} \ No newline at end of file