From 870374c8dab318e13d1c544e84bb6f0d14c01008 Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Sat, 14 Jan 2017 12:17:08 +0000 Subject: [PATCH] Move generation of dib_[environment|args] to manifest element dib_[environment|args] manifest files are currently generated by the base element and then moved by the manifest element. This creates too many corner cases -- if you don't include the base element (we are trying to empty it ATM) you don't get the env/args saved at all; if you include base but don't include the manifest element they're saved to /etc, but if you do have the manifest element they're moved to the manifest dir. Move generation of these into the manifest element directly and update the documentation to reflect this. In practice this doesn't change things, because the "manifests" element gets pulled in via deps for most builds. Change-Id: I3f23037058137d166b29f0b70fd1a02c22c07fc8 Signed-off-by: Andreas Florath --- doc/source/developer/developing_elements.rst | 10 ++++--- .../base/extra-data.d/50-store-build-settings | 13 --------- .../base/install.d/50-store-build-settings | 16 ----------- elements/manifests/README.rst | 28 +++++++++++++------ .../manifests/cleanup.d/01-copy-manifests-dir | 25 +++++++++-------- 5 files changed, 39 insertions(+), 53 deletions(-) delete mode 100755 elements/base/extra-data.d/50-store-build-settings delete mode 100755 elements/base/install.d/50-store-build-settings diff --git a/doc/source/developer/developing_elements.rst b/doc/source/developer/developing_elements.rst index fa6c24b6..b3e9704c 100644 --- a/doc/source/developer/developing_elements.rst +++ b/doc/source/developer/developing_elements.rst @@ -323,10 +323,6 @@ then one branch of a git repository or to get source for a local cache. See Debugging elements ------------------ -The build-time environment and command line arguments are captured by the -:doc:`../elements/base/README` element and written to ``/etc/dib_environment`` -and ``/etc/dib_arguments`` inside the image. - Export ``break`` to drop to a shell during the image build. Break points can be set either before or after any of the hook points by exporting "break=[before|after]-hook-name". Multiple break points can be specified as a @@ -339,6 +335,12 @@ comma-delimited string. Some examples: * ``break=after-error`` will break after an error during an in target hookpoint. +The :doc:`../elements/manifests/README` element will make a range of +manifest information generated by other elements available for +inspection inside and outside the built image. Environment and +command line arguments are captured as described in the documentation +and can be useful for debugging. + Images are built such that the Linux kernel is instructed not to switch into graphical consoles (i.e. it will not activate KMS). This maximises compatibility with remote console interception hardware, such as HP's iLO. diff --git a/elements/base/extra-data.d/50-store-build-settings b/elements/base/extra-data.d/50-store-build-settings deleted file mode 100755 index 0ba87371..00000000 --- a/elements/base/extra-data.d/50-store-build-settings +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# Store the build-time environment and command line arguments - -if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -[ -n "$TMP_HOOKS_PATH" ] || die "Temp hook path not set" - -echo "$DIB_ENV" > $TMP_HOOKS_PATH/dib_environment -echo "$DIB_ARGS" > $TMP_HOOKS_PATH/dib_arguments diff --git a/elements/base/install.d/50-store-build-settings b/elements/base/install.d/50-store-build-settings deleted file mode 100755 index 8a25b53f..00000000 --- a/elements/base/install.d/50-store-build-settings +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# Store build-time environment and command line arguments - -if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -if [ -e "/tmp/in_target.d/dib_environment" ]; then - cp /tmp/in_target.d/dib_environment /etc/ -fi - -if [ -e "/tmp/in_target.d/dib_arguments" ]; then - cp /tmp/in_target.d/dib_arguments /etc/ -fi diff --git a/elements/manifests/README.rst b/elements/manifests/README.rst index d707c1b0..14065f14 100644 --- a/elements/manifests/README.rst +++ b/elements/manifests/README.rst @@ -1,13 +1,25 @@ ========= manifests ========= -Copy any manifests generated into the build area post-image creation -This element should be a dependency of any element that writes a manifest -into the `DIB_MANIFEST_IMAGE_DIR`, which defaults to `/etc/dib-manifests`. -This is created in extra-data.d rather than pre-install.d to allow the -source-repositories element to make use of it +An framework for saving manifest information generated during the +build for later inspection. Manifests are kept in the final image and +also copied to the build area post-image creation. -The manifests are copied to `DIB_MANIFEST_SAVE_DIR`, which defaults to -`${IMAGE_NAME}.d/`, resulting in the manifests being available as -`${IMAGE_NAME}.d/dib-manifests` by default +Elements that wish to save any form of manifest should depend on this +element and can save their data to into the ``DIB_MANIFEST_IMAGE_DIR`` ( +which defaults to ``/etc/dib-manifests``). Note this is created in +``extra-data.d`` rather than ``pre-install.d`` to allow the +``source-repositories`` element to make use of it + +The manifests are copied to ``DIB_MANIFEST_SAVE_DIR``, which defaults +to ``${IMAGE_NAME}.d/``, resulting in the manifests being available as +``${IMAGE_NAME}.d/dib-manifests`` by default after the build. + +Extra status +------------ + +This element will also add the files ``dib_environment`` and +``dib_arguments`` to the manifest recording the ``diskimage-builder`` +specific environment (``DIB_*`` variables) and command-line arguments +respectively. diff --git a/elements/manifests/cleanup.d/01-copy-manifests-dir b/elements/manifests/cleanup.d/01-copy-manifests-dir index 6248e829..27d86121 100755 --- a/elements/manifests/cleanup.d/01-copy-manifests-dir +++ b/elements/manifests/cleanup.d/01-copy-manifests-dir @@ -1,6 +1,7 @@ #!/bin/bash # # Copyright 2014 Hewlett-Packard Development Company, L.P. +# Copyright 2017 Andreas Florath (andreas@florath.net) # # 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 @@ -21,15 +22,15 @@ fi set -eu set -o pipefail -if [ -d $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} ]; then - # Move the dib_environment and dib_arguments files into the manifests dir - if [ -e $TMP_MOUNT_PATH/etc/dib_arguments ]; then - sudo mv $TMP_MOUNT_PATH/etc/dib_arguments $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} - fi - if [ -e $TMP_MOUNT_PATH/etc/dib_environment ]; then - sudo mv $TMP_MOUNT_PATH/etc/dib_environment $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} - fi - mkdir -p ${DIB_MANIFEST_SAVE_DIR} - cp --no-preserve=ownership -rv $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} \ - ${DIB_MANIFEST_SAVE_DIR} -fi +MANIFEST_IMAGE_PATH=${TMP_MOUNT_PATH}/${DIB_MANIFEST_IMAGE_DIR} + +# Double check: directory must be created in extra-data.d/20-manifest-dir +[ -d ${MANIFEST_IMAGE_PATH} ] || { + echo "Error: MANIFEST_IMAGE_PATH [${MANIFEST_IMAGE_PATH}] does not exist"; + exit 1; } + +echo "$DIB_ENV" | sudo dd of=${MANIFEST_IMAGE_PATH}/dib_environment # dib-lint: safe_sudo +echo "$DIB_ARGS" | sudo dd of=${MANIFEST_IMAGE_PATH}/dib_arguments # dib-lint: safe_sudo + +mkdir -p ${DIB_MANIFEST_SAVE_DIR} +cp --no-preserve=ownership -rv ${MANIFEST_IMAGE_PATH} ${DIB_MANIFEST_SAVE_DIR}