From 14382439345d42c8e6e449c3b271e91296d8a568 Mon Sep 17 00:00:00 2001 From: Giancarlo Rubio Date: Tue, 24 Jan 2017 11:19:44 +0100 Subject: [PATCH] test docker image before pushing --- Makefile | 4 ++++ circle.yml | 1 + test_image.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100755 test_image.sh diff --git a/Makefile b/Makefile index 78dcc97f..1ccd4d08 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,10 @@ docker: @echo ">> building docker image" @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . +test-docker: + @echo ">> testing docker image" + ./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100 + $(GOPATH)/bin/promu promu: @GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu diff --git a/circle.yml b/circle.yml index 54f2b1b7..bfcb3027 100644 --- a/circle.yml +++ b/circle.yml @@ -33,6 +33,7 @@ dependencies: test: override: - docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T + - make test-docker deployment: hub_branch: diff --git a/test_image.sh b/test_image.sh new file mode 100755 index 00000000..c23523a4 --- /dev/null +++ b/test_image.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -exo pipefail + +docker_image=$1 +port=$2 + +wait_start() { + for in in {1..10}; do + if /usr/bin/curl -s -m 5 -f "http://localhost:${port}/metrics" > /dev/null ; then exit 0 ; + else + sleep 1 + fi + done + + exit 1 + +} + +docker_start() { + docker run -d -p "${port}":"${port}" "${docker_image}" +} + +if [[ "$#" -ne 2 ]] ; then + echo "Usage: $0 quay.io/prometheus/node-exporter:v0.13.0 9100" >&2 + exit 1 +fi + +docker_start +wait_start