Skip to content

Instantly share code, notes, and snippets.

@ernstki
Created September 2, 2026 22:16
Show Gist options
  • Select an option

  • Save ernstki/ad68bcc8db0fcff79da47ec9a95a38c7 to your computer and use it in GitHub Desktop.

Select an option

Save ernstki/ad68bcc8db0fcff79da47ec9a95a38c7 to your computer and use it in GitHub Desktop.
A Makefile that does the minimum stuff you'd want for a simple Docker Compose setup (example for a Rails app)
TITLE = Project tasks
SERVICE = campfire
CONTAINER = $(shell basename ${PWD} | tr -dc -- -_A-Za-z0-9)-$(SERVICE)-1
HOMEPAGE = https://gist.github.com/ernstki/ad68bcc8db0fcff79da47ec9a95a38c7
include .env
help: # prints this help
@perl -e "$$AUTOGEN_HELP_PL" Makefile
up: BUILD = 1
up: # bring up the container
docker compose up $(if $(BUILD)$(REBUILD),--build )$(if $(DETACH),-d )$(SERVICE)
down: # shut down the container
docker compose down
sh: shell
shell: # (alias: sh) run a Bash shell within the container
docker exec -it --user=$(if $(ROOT),root,rails) $(CONTAINER) bash
con: rails-console
console: rails-console
rails-console: # (alias: con, console) bring up a Rails console
docker exec -it $(CONTAINER) bash -c 'bin/rails console'
b: browse
browse: # (alias: b) open the site in a browser
xdg-open http://localhost:$(DOCKER_PORT)
keypair: # generate API keys
docker-compose exec -it $(SERVICE) -- \
/rails/script/admin/create-vapid-key
##
## internals you can safely ignore
##
define AUTOGEN_HELP_PL
# line XXX
if (-t 1) {
$$UL = "\e[0;4m"; $$BOLDBLUE = "\e[1m\e[1;34m"; $$RESET = "\e[0m";
}
$$max = 0;
@targets = ();
print "\n ", $$UL, "Makefile targets - $(TITLE)", $$RESET, "\n\n";
while (<>) {
push @targets, [$$1, $$2] if /^(\w.+):[^=].*#\s*(.*)/;
$$max = length($$1) if length($$1) > $$max;
}
foreach (@targets) {
printf " %smake %-$${max}s%s %s\n", $$BOLDBLUE, @$$_[0], $$RESET, @$$_[1];
}
print "\n";
endef
export AUTOGEN_HELP_PL
# vim: ft=make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment