Last active
January 1, 2025 16:05
-
-
Save kwmiebach/dbc834b6a848d520fd64b22b134c438d to your computer and use it in GitHub Desktop.
Demo Makefile: 'Make help' with awk. Targets source .env and pass vars to docker compose. Vars are escaped with '$$'. Instructions: save and run 'make help'.
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
.PHONY: help | |
help: | |
# Keep this comment line, it is imortant so awk ignores the help target. | |
@echo "Available targets:" | |
@echo " help\t\t Show this help message" | |
@awk '/^[^.][a-zA-Z0-9_-]+:/{t=$$1;getline;if($$0~"@echo"){gsub(/^[^"]*"|".*$$/,"",$$0);printf " %-20s %s\n",substr(t,1,length(t)-1),$$0}}' $(MAKEFILE_LIST) | |
.PHONY: it | |
it: | |
@echo "Start bash in the container as user 1000" | |
. ./.env && docker compose -f docker-compose-$$DOCKER_STACK.yml exec -u1000 -it $$DOCKER_SERVICE /bin/bash | |
.PHONY: it0 | |
it0: | |
@echo "Start bash in the container as root" | |
. ./.env && docker compose -f docker-compose-$$DOCKER_STACK.yml exec -u0 -it $$DOCKER_SERVICE /bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment