This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-image.sh
executable file
·93 lines (77 loc) · 3.14 KB
/
create-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e
set -o xtrace
set -o errexit
set -o nounset
DIR="$(dirname $0)" # http://stackoverflow.com/a/59916/194586
export DIB_RELEASE="$UBUNTU_ADJECTIVE"
export DIB_PYTHON_VERSION=3
#Clone the required repositories for Heat contextualization elements
git config --global http.sslverify false
if [ ! -d tripleo-image-elements ]; then
git clone -b stable/train https://git.openstack.org/openstack/tripleo-image-elements.git
fi
if [ ! -d heat-agents ]; then
git clone -b stable/train https://git.openstack.org/openstack/heat-agents.git
fi
export ELEMENTS_PATH=$DIR/elements
export LIBGUESTFS_BACKEND=direct
#required by disk-image-builder for heat
export ELEMENTS_PATH='elements:tripleo-image-elements/elements:heat-agents'
export DEPLOYMENT_BASE_ELEMENTS="heat-config heat-config-script"
export AGENT_ELEMENTS="os-collect-config os-refresh-config os-apply-config"
IFS=' ' read -ra ELEM <<< "$AGENT_ELEMENTS"
for i in "${ELEM[@]}"; do
ELEM_FILE="tripleo-image-elements/elements/$i/install.d/$i-source-install/10-$i"
PKG_FILE="tripleo-image-elements/elements/$i/package-installs.yaml"
# virtualenv version >= 20.0.0 doesn't work with
# https://github.com/openstack/tripleo-image-elements/blob/master/elements/os-apply-config/install.d/os-apply-config-source-install/10-os-apply-config#L6
# virtualenv: error: too few arguments [--setuptools version]
sed -i 's/virtualenv --setuptools/python3 -m venv/' $ELEM_FILE
if [ $i = 'os-collect-config' ]; then
sed -i '/^source*/a \$OS_COLLECT_CONFIG_VENV_DIR\/bin\/pip install --upgrade pip' $ELEM_FILE
fi
# error in anyjson setup command: use_2to3 is invalid
# setuptools>=58 breaks support for use_2to3
sed -i "s/'setuptools>=1.0'/'setuptools>=1.0,<58.0'/" $ELEM_FILE
sed -i "s/python-dev://" $PKG_FILE
done
#install pip and virtualenv from distribution because of a conflict between pip version and PyYAML
#ref: https://stackoverflow.com/questions/49911550/how-to-upgrade-disutils-package-pyyaml
export DIB_INSTALLTYPE_pip_and_virtualenv=package
TMPDIR=`mktemp -d`
mkdir -p $TMPDIR/common
OUTPUT_FILE="$TMPDIR/common/$IMAGE_NAME.qcow2"
ARCH="amd64"
if [ "$VARIANT" = 'arm64' ]; then
ARCH=$VARIANT
fi
if [ -f "$OUTPUT_FILE" ]; then
echo "removing existing $OUTPUT_FILE"
rm -f "$OUTPUT_FILE"
fi
ELEMENTS="vm block-device-efi dhcp-all-interfaces pip-and-virtualenv $AGENT_ELEMENTS $DEPLOYMENT_BASE_ELEMENTS"
disk-image-create \
chameleon-common \
$ELEMENTS \
$EXTRA_ELEMENTS \
-a $ARCH \
-o $OUTPUT_FILE
if [ -f "$OUTPUT_FILE.qcow2" ]; then
mv $OUTPUT_FILE.qcow2 $OUTPUT_FILE
fi
COMPRESSED_OUTPUT_FILE="$OUTPUT_FILE-compressed"
qemu-img convert $OUTPUT_FILE -O qcow2 -c $COMPRESSED_OUTPUT_FILE
echo "mv $COMPRESSED_OUTPUT_FILE $OUTPUT_FILE"
mv $COMPRESSED_OUTPUT_FILE $OUTPUT_FILE
if [ $? -eq 0 ]; then
# The below line echoed to stdout is used by Abracadabra, do not change alone!
echo "Image built in $OUTPUT_FILE"
if [ -f "$OUTPUT_FILE" ]; then
echo "to add the image in glance run the following command:"
echo "openstack image create --disk-format qcow2 --container-format bare --file $OUTPUT_FILE \"$IMAGE_NAME\""
fi
else
echo "Failed to build image in $OUTPUT_FOLDER"
exit 1
fi