forked from ManageIQ/manageiq-v2v-conversion_host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·133 lines (105 loc) · 3.28 KB
/
build.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash -e
KUBEVIRT_VERSION="2.0.0"
KUBEVIRT_CONVERSION_RELEASE="3"
KUBEVIRT_VMIMPORT_PROVIDER="9"
QUAY_NS=quay.io/kubevirt
CONTAINER_MGMT=docker
if ! type "${CONTAINER_MGMT}" &>/dev/null; then
if type "podman" &>/dev/null; then
CONTAINER_MGMT=podman
fi
fi
RPM_VERSION="$(
git describe --always --tags --match "v[0-9]*" |
sed -e '/^v[0-9.]\+\(-\|$\)/!{q1}; s/^v\([0-9.]\+\).*/\1/'
)"
if git describe --exact-match --tags --match "v[0-9]*" > /dev/null 2>&1 ; then
RPM_RELEASE="1"
else
GIT="$(
git describe --always --tags --match "v[0-9]*" --dirty=.dr |
sed -r 's/^/git/; s/^[^-]*-//; s/-g/.git/; s/-/_/g'
)"
RPM_RELEASE="0.$GIT.$(date -u +%Y%m%d%H%M%S)"
fi
ROLE_NAME="manageiq.v2v-conversion-host"
PACKAGE_NAME="v2v-conversion-host"
ROLE_RPM_NAME="${PACKAGE_NAME}-ansible"
PREFIX="${PREFIX:-/usr/local}"
DATA_DIR="${DATA_DIR:-${PREFIX}/share}"
BIN_DIR="${BIN_DIR:-${PREFIX}/bin}"
ROLES_DIR="$DATA_DIR/ansible/roles"
AUX_DATA_DIR="$DATA_DIR/$ROLE_RPM_NAME"
TARBALL="$PACKAGE_NAME-$RPM_VERSION.tar.gz"
_replace_vars() {
sed \
-e "s|@RPM_VERSION@|$RPM_VERSION|g" \
-e "s|@RPM_RELEASE@|$RPM_RELEASE|g" \
-e "s|@PACKAGE_NAME@|$PACKAGE_NAME|g" \
< "$1" > "$2"
echo "Wrote $2"
}
do_prep() {
_replace_vars "$PACKAGE_NAME.spec.in" "$PACKAGE_NAME.spec"
_replace_vars "wrapper/meta.py.in" "wrapper/meta.py"
}
do_dist() {
do_prep
echo "Creating spec file and tar archive '$TARBALL' ... "
(
git ls-files ; ls \
wrapper/meta.py \
) | tar --files-from /proc/self/fd/0 -czf "$TARBALL" "$PACKAGE_NAME.spec"
echo "tar archive '$TARBALL' created."
}
do_install() {
echo "Installing data..."
mkdir -p $ROLES_DIR
cp -pR "ansible/$ROLE_NAME" "$ROLES_DIR"
if [[ -z "${RPM_BUILD_ROOT}" ]]; then
PYTHON_PREFIX="${PREFIX:-$(python-config --prefix)}"
python setup.py install --prefix "${PYTHON_PREFIX}"
fi
mkdir -p "$AUX_DATA_DIR/playbooks"
install -t "$AUX_DATA_DIR/playbooks" ansible/examples/*.yml
echo "Installation done."
}
do_build_conversion() {
TAG="v$KUBEVIRT_VERSION-$KUBEVIRT_CONVERSION_RELEASE"
IMAGE="$QUAY_NS/kubevirt-v2v-conversion"
# TODO: make sure the TAG is not used yet to avoid overwrite
pushd kubevirt-conversion
# TODO: use RPM with wrapper
${CONTAINER_MGMT} build -v "$(dirname $PWD)":/source -t "$IMAGE:$TAG" .
popd
# TODO: When to tag as 'latest'? Do it manualy for now.
#${CONTAINER_MGMT} push quay.io/nyoxi/kubevirt-conversion:latest
}
do_build_provider() {
TAG="v$KUBEVIRT_VERSION-$KUBEVIRT_VMIMPORT_PROVIDER"
IMAGE="$QUAY_NS/vm-import-provider"
# Prepare golang environment
pushd vm-import-provider > /dev/null
export GOPATH="$(pwd)/build/GOPATH"
if [ -e "$GOPATH" ] ; then
echo "GOPATH exists ($GOPATH)" >&2
echo "Remove it and try again" >&2
exit 1
fi
IPATH="$GOPATH/src/github.com/ManageIQ/manageiq-v2v-conversion_host/"
mkdir -p "$IPATH"
pushd $IPATH > /dev/null
ln -s $(dirs -l +2)/vm-import-provider
cd vm-import-provider
# Build operator
operator-sdk build "$IMAGE:$TAG"
# Drop out and clean
popd > /dev/null # $IPATH/vm-import-provider
popd > /dev/null # /vm-import-provider
rm -frv "$GOPATH"
}
do_images() {
do_build_conversion
do_build_provider
}
do_$1