| 1 | #!/bin/sh |
| 2 | |
| 3 | docker run -i -v `pwd`:/gopath/src/github.com/kumina/libvirt_exporter alpine:3.8 /bin/sh << 'EOF' |
| 4 | set -ex |
| 5 | |
| 6 | # Install prerequisites for the build process. |
| 7 | apk update |
| 8 | apk add ca-certificates g++ git go libnl-dev linux-headers make perl pkgconf libtirpc-dev wget |
| 9 | update-ca-certificates |
| 10 | |
| 11 | # Install libxml2. Alpine's version does not ship with a static library. |
| 12 | cd /tmp |
| 13 | wget ftp://xmlsoft.org/libxml2/libxml2-2.9.4.tar.gz |
| 14 | tar -xf libxml2-2.9.4.tar.gz |
| 15 | cd libxml2-2.9.4 |
| 16 | ./configure --disable-shared --enable-static |
| 17 | make -j2 |
| 18 | make install |
| 19 | |
| 20 | # Install libvirt. Alpine's version does not ship with a static library. |
| 21 | cd /tmp |
| 22 | wget https://libvirt.org/sources/libvirt-3.2.0.tar.xz |
| 23 | tar -xf libvirt-3.2.0.tar.xz |
| 24 | cd libvirt-3.2.0 |
| 25 | ./configure --disable-shared --enable-static --localstatedir=/var --without-storage-mpath |
| 26 | make -j2 |
| 27 | make install |
| 28 | sed -i 's/^Libs:.*/& -lnl -ltirpc -lxml2/' /usr/local/lib/pkgconfig/libvirt.pc |
| 29 | |
| 30 | # Build the libvirt_exporter. |
| 31 | cd /gopath/src/github.com/kumina/libvirt_exporter |
| 32 | export GOPATH=/gopath |
| 33 | go get -d ./... |
| 34 | go build --ldflags '-extldflags "-static"' |
| 35 | strip libvirt_exporter |
| 36 | EOF |