Don't set tracing in environment files

Because environment files are sourced into the current environment,
they shouldn't be setting global settings like tracing else they
affect every preceeding import.  This is quite confusing when only
half your imports are traced in the logs, because it was either turned
on, or off, by a preceeding environment import.

There is a corresponding dib-run-parts change in
I29f7df1514aeb988222d1094e8269eddb485c2a0 that will greatly increase
debugability for environment files by deliberately logging what files
are sourced and consistently turning on tracing around their import.

This isn't strictly necessary (since dib-run-parts with the prior
change will just turn tracing off after import anyway) but it's a
decent cleanup for consistency.  A bare-minimum dib-lint check is
added.  Documentation is updated.

Change-Id: I10f68be0642835a04af7e5a2bc101502f61e5357
This commit is contained in:
Ian Wienand 2016-10-20 13:51:16 +11:00
parent 85354e5cd8
commit 9e392f56b0
4 changed files with 12 additions and 21 deletions

View File

@ -151,6 +151,12 @@ for i in $(find elements -type f \
fi
fi
# check that environment files don't "set -x"
if [[ "$i" =~ (environment.d) ]]; then
if grep -q "set -x" $i; then
error "Environment file $i should not set tracing"
fi
fi
# check that sudo calls in phases run outside the chroot look
# "safe"; meaning that they seem to operate within the chroot

View File

@ -172,11 +172,12 @@ the image as executable files.
Environment Variables
^^^^^^^^^^^^^^^^^^^^^
To set environment variables for other hooks, add a file to your element
``environment.d``.
This directory contains bash script snippets that are sourced before running
scripts in each phase.
To set environment variables for other hooks, add a file to your
element ``environment.d``. This directory contains bash script
snippets that are sourced before running scripts in each phase. Note
that because environment includes are sourced together, they should
not set global flags like ``set -x`` because they will affect all
preceeding imports.
DIB exposes an internal ``$IMAGE_ELEMENT`` variable which provides elements
access to the full set of elements that are included in the image build. This

View File

@ -1,9 +1 @@
#!/bin/bash
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
export DIB_EXTLINUX=1

View File

@ -1,5 +1,3 @@
#!/bin/bash
#
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -15,11 +13,5 @@
# under the License.
#
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
export DIB_MANIFEST_IMAGE_DIR=${DIB_MANIFEST_IMAGE_DIR:-/etc/dib-manifests}
export DIB_MANIFEST_SAVE_DIR=${DIB_MANIFEST_SAVE_DIR:-${IMAGE_NAME}.d/}