-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild.sh
executable file
·117 lines (91 loc) · 2.94 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
#!/bin/bash -e
RPM_VERSION="1.16.0"
KUBEVIRT_VERSION="2.0.0"
KUBEVIRT_CONVERSION_RELEASE="3"
KUBEVIRT_VMWARE_RELEASE="3"
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
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="oVirt.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"
do_dist() {
echo "Creating tar archive '$TARBALL' ... "
sed \
-e "s|@RPM_VERSION@|$RPM_VERSION|g" \
-e "s|@RPM_RELEASE@|$RPM_RELEASE|g" \
-e "s|@PACKAGE_NAME@|$PACKAGE_NAME|g" \
< "$PACKAGE_NAME.spec.in" > "$PACKAGE_NAME.spec"
git ls-files | 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_vmware() {
TAG="v$KUBEVIRT_VERSION-$KUBEVIRT_CONVERSION_RELEASE"
IMAGE="$QUAY_NS/kubevirt-vmware"
# Prepare golang environment
pushd kubevirt-vmware > /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/ovirt/v2v-conversion-host/"
mkdir -p "$IPATH"
pushd $IPATH > /dev/null
ln -s $(dirs +2)/kubevirt-vmware
cd kubevirt-vmware
# Build operator
operator-sdk build "$IMAGE:$TAG"
# Drop out and clean
popd > /dev/null # $IPATH/kubevirt-vmware
popd > /dev/null # /kubevirt-vmware
rm -frv "$GOPATH"
}
do_images() {
do_build_conversion
do_build_vmware
}
do_$1