2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> packer-build.sh"
12 # The script builds an image using packer
13 # $CLOUDENV : Provides the cloud credential file.
14 # $PACKER_PLATFORM : Provides the packer platform.
15 # $PACKER_TEMPLATE : Provides the packer temnplate.
17 # Ensure we fail the job if any steps fail.
20 PACKER_LOGS_DIR="$WORKSPACE/archives/packer"
21 PACKER_BUILD_LOG="$PACKER_LOGS_DIR/packer-build.log"
22 mkdir -p "$PACKER_LOGS_DIR"
23 export PATH="${WORKSPACE}/bin:$PATH"
25 # Prioritize the project's own version of vars if available
26 platform_file="common-packer/vars/$PACKER_PLATFORM.json"
27 if [ -f "$PACKER_PLATFORM" ]; then
28 platform_file="vars/$PACKER_PLATFORM.json"
32 export PACKER_LOG="yes"
33 export PACKER_LOG_PATH="$PACKER_BUILD_LOG"
34 packer.io build -color=false \
35 -var-file="$CLOUDENV" \
36 -var-file="$platform_file" \
37 "templates/$PACKER_TEMPLATE.json"
39 # Retrive the list of cloud providers
40 mapfile -t clouds < <(jq -r '.builders[].name' "templates/$PACKER_TEMPLATE.json")
42 # Split public/private clouds logs
43 for cloud in "${clouds[@]}"; do
44 grep -e "$cloud" "$PACKER_BUILD_LOG" > "$PACKER_LOGS_DIR/packer-build_$cloud.log" 2>&1