From 0a550672d8de6cac4765445d95212a149a17618b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 4 Feb 2023 23:50:00 +0100 Subject: Makefile best practices --- GNUmakefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 41 ----------------------------------------- 2 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 GNUmakefile delete mode 100644 Makefile diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..0ec97b3 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,48 @@ +.SHELLFLAGS := -eu -o pipefail -c +.ONESHELL: +.DELETE_ON_ERROR: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules + +CACHEDIR=/tmp/hugo-cache-$(USER) +DESTDIR=public/ +HOSTNAME=$(shell hostname) +REVISION=$(shell git rev-parse HEAD) + +.PHONY: build +build: ## make build # builds an optimized version of the website in $(DESTDIR) + @echo "----- Generating site -----" + hugo --gc --minify --cleanDestinationDir -d $(DESTDIR) --cacheDir $(CACHEDIR) + cp public/index.json search/ + cp public/search/index.html search/ + (cd search && CGO_ENABLED=0 go build -ldflags '-s -w -extldflags "-static"' ./search.go) + +.PHONY: buildah +buildah: ## make buildah # builds the container images + deploy/build-image.sh + +.PHONY: clean +clean: ## make clean # removed all $(DESTDIR) contents + @echo "----- Cleaning old build -----" + rm -f search/index.html search/index.json search/search + rm -rf $(DESTDIR) + +.PHONY: deploy +deploy: ## make deploy # deploy the website the active kubernetes context + sed -i deploy/www.yaml -e 's/^\(\s*image:[^:]*:\).*$$/\1$(REVISION)/' + kubectl apply -f deploy/www.yaml + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +.PHONY: push +push: ## make push # push the built images to quay.io + buildah push adyxax/www quay.io/adyxax/www:$(REVISION) + buildah push adyxax/www-search quay.io/adyxax/www-search:$(REVISION) + +.PHONY: serve +serve: ## make serve # hugo web server development mode + hugo serve --disableFastRender --noHTTPCache --cacheDir $(CACHEDIR) --bind 0.0.0.0 --port 1313 -b http://$(HOSTNAME):1313/ + +.DEFAULT_GOAL := help diff --git a/Makefile b/Makefile deleted file mode 100644 index 94300bf..0000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -CACHEDIR=/tmp/hugo-cache-$(USER) -DESTDIR=public/ -HOSTNAME=$(shell hostname) -REVISION=$(shell git rev-parse HEAD) - -.PHONY: build -build: ## make build # builds an optimized version of the website in $(DESTDIR) - @echo "----- Generating site -----" - hugo --gc --minify --cleanDestinationDir -d $(DESTDIR) --cacheDir $(CACHEDIR) - cp public/index.json search/ - cp public/search/index.html search/ - (cd search && CGO_ENABLED=0 go build -ldflags '-s -w -extldflags "-static"' ./search.go) - -.PHONY: buildah -buildah: ## make buildah # builds the container images - deploy/build-image.sh - -.PHONY: clean -clean: ## make clean # removed all $(DESTDIR) contents - @echo "----- Cleaning old build -----" - rm -f search/index.html search/index.json search/search - rm -rf $(DESTDIR) - -.PHONY: deploy -deploy: ## make deploy # deploy the website the active kubernetes context - sed -i deploy/www.yaml -e 's/^\(\s*image:[^:]*:\).*$$/\1$(REVISION)/' - kubectl apply -f deploy/www.yaml - -.PHONY: push -push: ## make push # push the built images to quay.io - buildah push adyxax/www quay.io/adyxax/www:$(REVISION) - buildah push adyxax/www-search quay.io/adyxax/www-search:$(REVISION) - -.PHONY: serve -serve: ## make serve # hugo web server development mode - hugo serve --disableFastRender --noHTTPCache --cacheDir $(CACHEDIR) --bind 0.0.0.0 --port 1313 -b http://$(HOSTNAME):1313/ - -help: - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' - -.DEFAULT_GOAL := help -- cgit v1.2.3