Skip to content

Instantly share code, notes, and snippets.

@eze-kiel
Last active March 22, 2024 02:18
Show Gist options
  • Save eze-kiel/018f907cf15c2e5b7804a1173ec461d2 to your computer and use it in GitHub Desktop.
Save eze-kiel/018f907cf15c2e5b7804a1173ec461d2 to your computer and use it in GitHub Desktop.
Makefile with enhanced help command
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
.PHONY: all build clean
all: help
## Build:
build: ## Build the Go project
mkdir -p out/bin
GO111MODULE=on $(GOCMD) build \
-o out/bin/$(BINARY_NAME) \
-ldflags="-X 'main.Version=$(VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" \
.
clean: ## Clean all the files and binaries generated by the Makefile
rm -rf ./out
## Docker:
docker-build: ## Use the Dockerfile to build the container
@echo '${GREEN}---> Build docker container${RESET}'
docker build --rm --tag $(BINARY_NAME) --build-arg VERSION=${VERSION} --build-arg BUILD_DATE=$(shell date +%s) .
@echo '${GREEN}---> Tag as 'latest'${RESET}'
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)/$(BINARY_NAME):latest
docker-release: ## Release the container with tag latest and version
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)/$(BINARY_NAME):$(VERSION)
docker push $(DOCKER_REGISTRY)/$(BINARY_NAME):latest
docker push $(DOCKER_REGISTRY)/$(BINARY_NAME):$(VERSION)
## Help:
help: ## Show this help
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[0-9a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
version: ## Display current version
@echo ${VERSION}
@eze-kiel
Copy link
Author

        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
                    Version 2, December 2004 

 Everyone is permitted to copy and distribute verbatim or modified 
 copies of this license document, and changing it is allowed as long 
 as the name is changed. 

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 

  0. You just DO WHAT THE FUCK YOU WANT TO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment