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 <superq@gmail.com>
This commit is contained in:
Ben Kochie 2018-07-04 11:27:10 +02:00 committed by GitHub
parent 1f8c40943f
commit 709ad10d97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 19 deletions

View file

@ -34,10 +34,6 @@ jobs:
- image: circleci/golang:1.10 - image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/prometheus working_directory: /go/src/github.com/prometheus/prometheus
environment:
DOCKER_IMAGE_NAME: prom/prometheus
QUAY_IMAGE_NAME: quay.io/prometheus/prometheus
steps: steps:
- checkout - checkout
- setup_remote_docker - setup_remote_docker
@ -45,23 +41,19 @@ jobs:
at: . at: .
- run: ln -s .build/linux-amd64/prometheus prometheus - run: ln -s .build/linux-amd64/prometheus prometheus
- run: ln -s .build/linux-amd64/promtool promtool - run: ln -s .build/linux-amd64/promtool promtool
- run: make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME - run: make docker
- run: make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME - run: make docker DOCKER_REPO=quay.io/prometheus
- run: docker images - run: docker images
- run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- run: docker push $DOCKER_IMAGE_NAME - run: make docker-publish
- run: docker push $QUAY_IMAGE_NAME - run: make docker-publish DOCKER_REPO=quay.io/prometheus
docker_hub_release_tags: docker_hub_release_tags:
docker: docker:
- image: circleci/golang:1.10 - image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/prometheus working_directory: /go/src/github.com/prometheus/prometheus
environment:
DOCKER_IMAGE_NAME: prom/prometheus
QUAY_IMAGE_NAME: quay.io/prometheus/prometheus
steps: steps:
- checkout - checkout
- setup_remote_docker - setup_remote_docker
@ -79,17 +71,17 @@ jobs:
destination: releases destination: releases
- run: ln -s .build/linux-amd64/prometheus prometheus - run: ln -s .build/linux-amd64/prometheus prometheus
- run: ln -s .build/linux-amd64/promtool promtool - 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_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 DOCKER_REPO=quay.io/prometheus
- run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- run: | - run: |
if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" make docker-tag-latest DOCKER_IMAGE_TAG="$CIRCLE_TAG"
docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest" make docker-tag-latest DOCKER_IMAGE_TAG="$CIRCLE_TAG" DOCKER_REPO=quay.io/prometheus
fi fi
- run: docker push $DOCKER_IMAGE_NAME - run: make docker-publish
- run: docker push $QUAY_IMAGE_NAME - run: make docker-publish DOCKER_REPO=quay.io/prometheus
workflows: workflows:
version: 2 version: 2

View file

@ -36,6 +36,7 @@ pkgs = ./...
PREFIX ?= $(shell pwd) PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd) BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
DOCKER_REPO ?= prom
.PHONY: all .PHONY: all
all: style staticcheck unused build test all: style staticcheck unused build test
@ -98,7 +99,15 @@ tarball: promu
.PHONY: docker .PHONY: docker
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 .PHONY: promu
promu: promu: