From 4c467964f5deeaf01dd11700a9e9117fb13a36ea Mon Sep 17 00:00:00 2001 From: Jon-Paul Sullivan Date: Fri, 28 Mar 2014 18:02:36 +0000 Subject: [PATCH] Standardise manifest creation and retrieval * Create a standard element to copy manifests out of the image and into the build area. * Ensure all current manifests are copied into a standard manifests directory Change-Id: I37eff5a13a14564e1adc33eb4f0144d571267617 --- elements/dpkg/element-deps | 1 + .../post-install.d/99-write-dpkg-manifest | 8 +++--- elements/manifests/README.md | 10 +++++++ .../manifests/cleanup.d/01-copy-manifests-dir | 27 +++++++++++++++++++ elements/manifests/environment.d/15-manifests | 21 +++++++++++++++ .../extra-data.d/20-manifest-dir} | 9 +------ elements/source-repositories/element-deps | 1 + .../extra-data.d/98-source-repositories | 5 ++-- 8 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 elements/dpkg/element-deps create mode 100644 elements/manifests/README.md create mode 100755 elements/manifests/cleanup.d/01-copy-manifests-dir create mode 100755 elements/manifests/environment.d/15-manifests rename elements/{dpkg/cleanup.d/01-copy-dpkg-manifest => manifests/extra-data.d/20-manifest-dir} (66%) diff --git a/elements/dpkg/element-deps b/elements/dpkg/element-deps new file mode 100644 index 00000000..c890ea15 --- /dev/null +++ b/elements/dpkg/element-deps @@ -0,0 +1 @@ +manifests diff --git a/elements/dpkg/post-install.d/99-write-dpkg-manifest b/elements/dpkg/post-install.d/99-write-dpkg-manifest index 802657ce..044240a8 100755 --- a/elements/dpkg/post-install.d/99-write-dpkg-manifest +++ b/elements/dpkg/post-install.d/99-write-dpkg-manifest @@ -17,17 +17,15 @@ # set -eux -MANIFEST_DIR=/etc/dib-manifests -mkdir -p ${MANIFEST_DIR} DPKG_MANIFEST_NAME=dib-manifest-dpkg-$(basename ${IMAGE_NAME}) # Write the json preamble -echo '{"packages": [' > ${MANIFEST_DIR}/${DPKG_MANIFEST_NAME} +echo '{"packages": [' > ${DIB_MANIFEST_IMAGE_DIR}/${DPKG_MANIFEST_NAME} # Write a json-format output for the packages installed format='{"package": "${binary:Package}","arch": "${Architecture}","version": "${Version}","status": "${db:Status-Abbrev}"},' # Use the configurable dpkg --show output as a manifest -dpkg-query --show --showformat="${format}" | tee -a ${MANIFEST_DIR}/${DPKG_MANIFEST_NAME} +dpkg-query --show --showformat="${format}" | tee -a ${DIB_MANIFEST_IMAGE_DIR}/${DPKG_MANIFEST_NAME} # Finish off the json structure and make it easier for human inspection -sed -i -e 's/,$/\n]}/g' -e 's/\(},\)/ \1\n/g' ${MANIFEST_DIR}/${DPKG_MANIFEST_NAME} +sed -i -e 's/,$/\n]}/g' -e 's/\(},\)/ \1\n/g' ${DIB_MANIFEST_IMAGE_DIR}/${DPKG_MANIFEST_NAME} diff --git a/elements/manifests/README.md b/elements/manifests/README.md new file mode 100644 index 00000000..6ada9376 --- /dev/null +++ b/elements/manifests/README.md @@ -0,0 +1,10 @@ +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 + +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 diff --git a/elements/manifests/cleanup.d/01-copy-manifests-dir b/elements/manifests/cleanup.d/01-copy-manifests-dir new file mode 100755 index 00000000..50d99957 --- /dev/null +++ b/elements/manifests/cleanup.d/01-copy-manifests-dir @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# All Rights Reserved. +# +# 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. +# +set -eux + +if [ -d $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} ]; then + # Move the dib_environment and dib_arguments files into the manifests dir + sudo mv $TMP_MOUNT_PATH/etc/dib_arguments $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} + sudo mv $TMP_MOUNT_PATH/etc/dib_environment $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} + mkdir -p ${DIB_MANIFEST_SAVE_DIR} + cp --no-preserve=ownership -rv $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} \ + ${DIB_MANIFEST_SAVE_DIR} +fi diff --git a/elements/manifests/environment.d/15-manifests b/elements/manifests/environment.d/15-manifests new file mode 100755 index 00000000..0a151d72 --- /dev/null +++ b/elements/manifests/environment.d/15-manifests @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# All Rights Reserved. +# +# 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. +# +set -eu + +export DIB_MANIFEST_IMAGE_DIR=${DIB_MANIFEST_IMAGE_DIR:-/etc/dib-manifests} +export DIB_MANIFEST_SAVE_DIR=${DIB_MANIFEST_SAVE_DIR:-${IMAGE_NAME}.d/} diff --git a/elements/dpkg/cleanup.d/01-copy-dpkg-manifest b/elements/manifests/extra-data.d/20-manifest-dir similarity index 66% rename from elements/dpkg/cleanup.d/01-copy-dpkg-manifest rename to elements/manifests/extra-data.d/20-manifest-dir index 124436a6..48e605bb 100755 --- a/elements/dpkg/cleanup.d/01-copy-dpkg-manifest +++ b/elements/manifests/extra-data.d/20-manifest-dir @@ -17,11 +17,4 @@ # set -eux -MANIFEST_DIR=/etc/dib-manifests -DPKG_MANIFEST_NAME=dib-manifest-dpkg-$(basename ${IMAGE_NAME}) - -if [ -f $TMP_MOUNT_PATH/${MANIFEST_DIR}/${DPKG_MANIFEST_NAME} ]; then - mkdir -p ${IMAGE_NAME}-manifests - cp --no-preserve=ownership -v $TMP_MOUNT_PATH/${MANIFEST_DIR}/${DPKG_MANIFEST_NAME} \ - ${IMAGE_NAME}-manifests/ -fi +sudo mkdir -p $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR} diff --git a/elements/source-repositories/element-deps b/elements/source-repositories/element-deps index 5562b27b..a8ec56bb 100644 --- a/elements/source-repositories/element-deps +++ b/elements/source-repositories/element-deps @@ -1 +1,2 @@ cache-url +manifests diff --git a/elements/source-repositories/extra-data.d/98-source-repositories b/elements/source-repositories/extra-data.d/98-source-repositories index 6f417fc7..87dfc345 100755 --- a/elements/source-repositories/extra-data.d/98-source-repositories +++ b/elements/source-repositories/extra-data.d/98-source-repositories @@ -166,7 +166,7 @@ OLD_CACHE_BASE=~/.cache/image-create/repository-sources make_new_cache $OLD_CACHE_BASE $CACHE_BASE mkdir -p $CACHE_BASE # Use the IMAGE_NAME from the calling script, and make it unique with the temporary path -GIT_MANIFEST_NAME=dib-git-manifest-$(basename ${IMAGE_NAME}) +GIT_MANIFEST_NAME=dib-manifest-git-$(basename ${IMAGE_NAME}) GIT_MANIFEST_CACHE_NAME=${GIT_MANIFEST_NAME}_$(dirname ${TMP_MOUNT_PATH##*.}) GIT_MANIFEST=$CACHE_BASE/${GIT_MANIFEST_CACHE_NAME} rm -f $GIT_MANIFEST @@ -178,6 +178,5 @@ done # Copy the manifest into the image if it exists (there may be no git repositories used) if [ -e "$GIT_MANIFEST" ] ; then - sudo cp $GIT_MANIFEST $TMP_MOUNT_PATH/etc/$GIT_MANIFEST_NAME - sudo mv $GIT_MANIFEST $(dirname ${IMAGE_NAME})/$GIT_MANIFEST_NAME + sudo cp $GIT_MANIFEST $TMP_MOUNT_PATH/${DIB_MANIFEST_IMAGE_DIR}/$GIT_MANIFEST_NAME fi