Last active
April 13, 2019 13:29
-
-
Save cmattoon/630b315a647d236299ca1c1040f197ad to your computer and use it in GitHub Desktop.
Makefile Templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DEFAULT_GOAL := help | |
.PHONY: | |
PROJECT_NAME = foo-bar | |
PROJECT_NS = cmattoon | |
GIT_REPO ?= $(PROJECT_NS)/$(PROJECT_NAME) | |
GIT_URL ?= [email protected]/$(GIT_REPO).git | |
VCS_REF = $(strip $(shell git describe --tags --dirty --always)) | |
BUILD_DATE = $(shell date +"%Y-%m-%dT%H:%M:%S") | |
DOCKER_REPO ?= $(REPO) | |
DOCKER_IMAGE ?= $(PROJECT_NAME) | |
DOCKER_TAG ?= $(VCS_REF) | |
DOCKER_FULLTAG?= $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) | |
DOCKER_LATEST ?= $(DOCKER_REPO)/$(DOCKER_IMAGE):latest | |
DOCKERDIR ?= . | |
DOCKERFILE ?= Dockerfile | |
# LABEL | |
DOCKER_BUILD_ARGS ?= --build-arg "VCS_REF=$(VCS_REF)" | |
.PHONY: help | |
help: ## Displays this message | |
help: | |
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | |
.PHONY: build | |
build: ## Build DOCKER_FULLTAG | |
build: BUILD_ARGS=$(DOCKER_BUILD_ARGS) | |
build: container | |
.PHONY: | |
container: | |
docker build \ | |
--label org.label-schema.build-date="$(BUILD_DATE)" \ | |
--label org.label-schema.vcs-url="$(GIT_URL)" \ | |
--label org.label-schema.vcs-ref="$(VCS_REF)" \ | |
--label org.label-schema.version="$(VERSION)" \ | |
--label org.label-schema.schema-version="1.0" \ | |
--label org.label-schema.name="$(PROJECT_NAME)" \ | |
$(BUILD_ARGS) -t $(DOCKER_FULLTAG) $(DOCKERDIR) -f $(DOCKERFILE) | |
.PHONY: | |
push: ## Push the image | |
push: | |
docker push $(DOCKER_FULLTAG) | |
docker tag $(DOCKER_FULLTAG) $(DOCKER_LATEST) | |
docker push $(DOCKER_LATEST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment