Move COPY in Dockerfile and add build script.

COPY in the Dockerfile has been moved so that changes to the source code
do not cause an apt update unnecessarily.
A build script has aslo been added to build and extract the build artefacts.
This build script is usedby Ansible to deploy the application to compute hosts.

Change-Id: I66d2b671d991d1ce3bef544532b058d33f32d282

Create build script which exports the build artefacts

Change-Id: Ifa1458a6b17484d378ec14b4cba2e0493b722f7b

Make build script fail if any of the stages fail

Change-Id: I325cf2d44f40f19a198bc03858625add20e10494
This commit is contained in:
James Gibson 2020-05-20 16:41:16 +01:00
parent b13f6200db
commit 01f8569011
3 changed files with 17 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.tox
doc/build
libvirtd_exporter

View File

@ -1,9 +1,9 @@
FROM golang:1.13.5 AS builder
WORKDIR /go/src/app
COPY . .
RUN apt-get update && \
apt-get -y install libvirt-dev && \
apt-get clean all
COPY . .
RUN go build
FROM golang:1.13.5

14
build.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
# Small script to build libvirtd-exporter using docker and export the resulting binary
set -e
docker build -t libvirtd-exporter .
# Start container with result
docker run --entrypoint sh -itd --name libvirtd-exporter libvirtd-exporter
# Extract build atifact to host
docker cp libvirtd-exporter:/libvirtd_exporter .
docker stop libvirtd-exporter
docker rm -f libvirtd-exporter