Skip to content

Commit

Permalink
Push all Docker tags at once
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophShyper committed Dec 4, 2019
1 parent 5087012 commit ac951c2
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ CURRENT_BRANCH := $(shell echo $(GITHUB_REF) | sed 's/refs\/heads\///')
GITHUB_SHORT_SHA := $(shell echo $(GITHUB_SHA) | cut -c1-7)
RELEASE_BRANCH := master
DOCKER_USER_ID := christophshyper
DOCKER_NAME := christophshyper/docker-terragrunt
DOCKER_IMAGE := docker-terragrunt
DOCKER_NAME := $(DOCKER_USER_ID)/$(DOCKER_IMAGE)

clean:
@docker images -a | grep "$(DOCKER_IMAGE)" | awk '{print $3}' | xargs docker rmi

get-versions:
ifeq ($(TF_VERSION),latest)
Expand All @@ -40,10 +44,6 @@ endif
$(info Build number: $(BUILD_NUMBER))

docker-build: get-versions
@docker rm $(DOCKER_NAME):latest || true
@docker rmi $(DOCKER_NAME):latest || true
@docker rm $(DOCKER_NAME):$(VERSION) || true
@docker rmi $(DOCKER_NAME):$(VERSION) || true
@docker build \
--build-arg TF_VERSION=$(TF_VERSION) \
--build-arg TG_VERSION=$(TG_VERSION) \
Expand All @@ -57,18 +57,12 @@ docker-login:

docker-push: docker-login
ifeq ($(CURRENT_BRANCH),$(RELEASE_BRANCH))
@docker push $(DOCKER_NAME):$(VERSION) \
&& docker tag $(DOCKER_NAME):$(VERSION) build-$(BUILD_NUMBER) \
&& docker push $(DOCKER_NAME):build-$(BUILD_NUMBER) \
&& docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):latest \
&& docker push $(DOCKER_NAME):latest
@docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):latest
@docker push $(DOCKER_NAME)
else
@docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):$(CURRENT_BRANCH)-$(VERSION) \
&& docker push $(DOCKER_NAME):$(CURRENT_BRANCH)-$(VERSION) \
&& docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):$(CURRENT_BRANCH)-build-$(BUILD_NUMBER) \
&& docker push $(DOCKER_NAME):$(CURRENT_BRANCH)-build-$(BUILD_NUMBER) \
&& docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):$(CURRENT_BRANCH)-latest \
&& docker push $(DOCKER_NAME):$(CURRENT_BRANCH)-latest
@docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):$(CURRENT_BRANCH)-$(VERSION)
@docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):$(CURRENT_BRANCH)-latest
@docker push $(DOCKER_NAME)
endif

build-and-push: docker-build docker-push
build-and-push: docker-build docker-push clean

0 comments on commit ac951c2

Please sign in to comment.