Makefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .PHONY: build-all help environment-check release-all
  2. # Use bash for inline if-statements in test target
  3. SHELL:=bash
  4. OWNER:=mikebirdgeneau
  5. # need to list these manually because there's a dependency tree
  6. ALL_STACKS:=jupyterlab
  7. ALL_IMAGES:=$(ALL_STACKS)
  8. GIT_MASTER_HEAD_SHA:=$(shell git rev-parse --short=12 --verify HEAD)
  9. help:
  10. # http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
  11. @echo "mikebirdgeneau/jupyterlab"
  12. @echo "====================="
  13. @echo "Replace % with a stack directory name (e.g., make build/jupyter)\n"
  14. @grep -E '^[a-zA-Z0-9_%/-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  15. build/%: DARGS?=
  16. build/%: ## build the latest image for a stack
  17. docker build $(DARGS) --rm --force-rm -t $(OWNER)/$(notdir $@):latest ./$(notdir $@)
  18. build-all: $(ALL_IMAGES:%=build/%) ## build all stacks
  19. build-test-all: $(foreach I,$(ALL_IMAGES),build/$(I) test/$(I) )
  20. dev/%: ARGS?=
  21. dev/%: DARGS?=
  22. dev/%: PORT?=8888
  23. dev/%: ## run a foreground container for a stack
  24. docker run -it --rm -p $(PORT):8888 $(DARGS) $(OWNER)/$(notdir $@) $(ARGS)
  25. environment-check:
  26. test -e ~/.docker-stacks-builder
  27. push/%: ## push the latest and HEAD git SHA tags for a stack to Docker Hub
  28. docker push $(OWNER)/$(notdir $@):latest
  29. docker push $(OWNER)/$(notdir $@):$(GIT_MASTER_HEAD_SHA)
  30. push-all: $(ALL_IMAGES:%=push/%) ## push all stacks
  31. refresh/%: ## pull the latest image from Docker Hub for a stack
  32. # skip if error: a stack might not be on dockerhub yet
  33. -docker pull $(OWNER)/$(notdir $@):latest
  34. refresh-all: $(ALL_IMAGES:%=refresh/%) ## refresh all stacks
  35. release-all: environment-check \
  36. refresh-all \
  37. build-test-all \
  38. tag-all \
  39. push-all
  40. release-all: ## build, test, tag, and push all stacks
  41. tag/%: ##tag the latest stack image with the HEAD git SHA
  42. docker tag -f $(OWNER)/$(notdir $@):latest $(OWNER)/$(notdir $@):$(GIT_MASTER_HEAD_SHA)
  43. tag-all: $(ALL_IMAGES:%=tag/%) ## tag all stacks
  44. test/%: ## run a stack container, check for jupyter server liveliness
  45. @-docker rm -f iut
  46. docker run -d --name iut $(OWNER)/$(notdir $@)
  47. @for i in $$(seq 0 9); do \
  48. sleep $$i; \
  49. docker exec iut bash -c 'wget http://localhost:8888 -O- | grep -i jupyter'; \
  50. if [[ $$? == 0 ]]; then break; fi; \
  51. done
  52. @docker rm -f iut
  53. test-all: $(ALL_IMAGES:%=test/%) ## test all stacks