add TEST flag to Dockerfile to run unit tests during build

This commit is contained in:
Max Kuznetsov 2020-06-03 12:08:10 -04:00
parent 2e09636ca1
commit 6978043dba
2 changed files with 9 additions and 4 deletions

View File

@ -1,6 +1,8 @@
FROM ubuntu:16.04 as builder
MAINTAINER Vaibhav Bhembre <vaibhav@digitalocean.com>
ARG TEST
ENV GOROOT /goroot
ENV GOPATH /go
ENV PATH $GOROOT/bin:$PATH
@ -21,9 +23,9 @@ RUN \
ADD . $APPLOC
WORKDIR $APPLOC
RUN go get -d && \
go build -o /bin/ceph_exporter
RUN go get -d
RUN if [ -n "${TEST}" ]; then go test -v ./...; fi
RUN go build -o /bin/ceph_exporter
FROM ubuntu:16.04
MAINTAINER Vaibhav Bhembre <vaibhav@digitalocean.com>
@ -36,7 +38,6 @@ RUN echo "deb https://download.ceph.com/debian-luminous xenial main" >> /etc/apt
apt-get install -y --force-yes librados2 librbd1 ceph-common && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /bin/ceph_exporter /bin/ceph_exporter
RUN chmod +x /bin/ceph_exporter

View File

@ -58,6 +58,10 @@ A sample build command would look like:
$ docker build -t digitalocean/ceph_exporter .
```
A `--build-args TEST=true` flag can be added to the build command above
to also run `go test` during build:
`docker build -t digitalocean/ceph_exporter . --build-arg TEST=true --no-cache`
You can start running your ceph exporter container now.
```bash