Skip to content

Instantly share code, notes, and snippets.

@kwmiebach
Last active January 1, 2025 16:05
Show Gist options
  • Save kwmiebach/dbc834b6a848d520fd64b22b134c438d to your computer and use it in GitHub Desktop.
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'.
.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