From 01f85690115b8fd06afd4fb488993752f6bceaf8 Mon Sep 17 00:00:00 2001 From: James Gibson Date: Wed, 20 May 2020 16:41:16 +0100 Subject: [PATCH] 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 --- .gitignore | 2 ++ Dockerfile | 2 +- build.sh | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index 3f213bf..a6212c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .tox doc/build + +libvirtd_exporter diff --git a/Dockerfile b/Dockerfile index 134a961..685b016 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0a9b182 --- /dev/null +++ b/build.sh @@ -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