forked from benapetr/xapi_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_container.sh
executable file
·66 lines (56 loc) · 1.28 KB
/
build_container.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
#!/bin/sh
#
# this script will attempt to build the static binary of xapi_exporter
# and then install it into a more space-conscious container
#
if [ -z "${1}" ]
then
echo "This script takes one argument: the tag name for the final container"
echo ""
echo "Example: ${0} xapi_exporter"
exit 1
fi
docker build -t xapi_exporter_staticbuild -f Dockerfile.build .
CONTAINER_ID=`docker run -d -t xapi_exporter_staticbuild`
if [ -z "${CONTAINER_ID}" ]
then
echo "Failed to get static build container id" >&2
exit 1
fi
docker cp ${CONTAINER_ID}:/bin/xapi_exporter ./xapi_exporter
if [ $? != 0 ]
then
echo "Failed to cp /bin/xapi_exporter out of static build container" >&2
exit 1
fi
docker stop ${CONTAINER_ID}
if [ $? != 0 ]
then
echo "Failed to stop static build container" >&2
exit 1
fi
docker rm ${CONTAINER_ID}
if [ $? != 0 ]
then
echo "Failed to remove static build container" >&2
exit 1
fi
IMAGE_ID=`docker images -q xapi_exporter_staticbuild`
if [ -z "${IMAGE_ID}" ]
then
echo "Failed to determine static build image id" >&2
exit 1
fi
docker rmi ${IMAGE_ID}
if [ $? != 0 ]
then
echo "Failed to remove static build image" >&2
exit 1
fi
docker build -t "${1}" -f Dockerfile.run .
if [ $? != 0 ]
then
echo "Failed to build run image" >&2
exit 1
fi
rm xapi_exporter