From 709ad10d977a4a12f7d74e5920c1cf81d48b8e4d Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Wed, 4 Jul 2018 11:27:10 +0200 Subject: [PATCH] Reduce CircleCI duplication (#4335) Reduce the duplication of per-project specifics in the CircleCI config. * Add docker repo variable, default to docker hub. * Add make targets for docker push and tag latest. Signed-off-by: Ben Kochie --- .circleci/config.yml | 28 ++++++++++------------------ Makefile.common | 11 ++++++++++- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6e49396af..1294c9cf5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,10 +34,6 @@ jobs: - image: circleci/golang:1.10 working_directory: /go/src/github.com/prometheus/prometheus - environment: - DOCKER_IMAGE_NAME: prom/prometheus - QUAY_IMAGE_NAME: quay.io/prometheus/prometheus - steps: - checkout - setup_remote_docker @@ -45,23 +41,19 @@ jobs: at: . - run: ln -s .build/linux-amd64/prometheus prometheus - run: ln -s .build/linux-amd64/promtool promtool - - run: make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME - - run: make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME + - run: make docker + - run: make docker DOCKER_REPO=quay.io/prometheus - run: docker images - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - - run: docker push $DOCKER_IMAGE_NAME - - run: docker push $QUAY_IMAGE_NAME + - run: make docker-publish + - run: make docker-publish DOCKER_REPO=quay.io/prometheus docker_hub_release_tags: docker: - image: circleci/golang:1.10 working_directory: /go/src/github.com/prometheus/prometheus - environment: - DOCKER_IMAGE_NAME: prom/prometheus - QUAY_IMAGE_NAME: quay.io/prometheus/prometheus - steps: - checkout - setup_remote_docker @@ -79,17 +71,17 @@ jobs: destination: releases - run: ln -s .build/linux-amd64/prometheus prometheus - run: ln -s .build/linux-amd64/promtool promtool - - run: make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG - - run: make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG + - run: make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG + - run: make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG DOCKER_REPO=quay.io/prometheus - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - run: | if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then - docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" - docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest" + make docker-tag-latest DOCKER_IMAGE_TAG="$CIRCLE_TAG" + make docker-tag-latest DOCKER_IMAGE_TAG="$CIRCLE_TAG" DOCKER_REPO=quay.io/prometheus fi - - run: docker push $DOCKER_IMAGE_NAME - - run: docker push $QUAY_IMAGE_NAME + - run: make docker-publish + - run: make docker-publish DOCKER_REPO=quay.io/prometheus workflows: version: 2 diff --git a/Makefile.common b/Makefile.common index eaee9f0b9..3ec207dac 100644 --- a/Makefile.common +++ b/Makefile.common @@ -36,6 +36,7 @@ pkgs = ./... PREFIX ?= $(shell pwd) BIN_DIR ?= $(shell pwd) DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) +DOCKER_REPO ?= prom .PHONY: all all: style staticcheck unused build test @@ -98,7 +99,15 @@ tarball: promu .PHONY: docker docker: - docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . + docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . + +.PHONY: docker-publish +docker-publish: + docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)" + +.PHONY: docker-tag-latest +docker-tag-latest: + docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest" .PHONY: promu promu: