Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml --log-level ERROR
  2. BUILD_NUMBER ?= local
  3. BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
  4. PROJECT_NAME = web
  5. BUILD_DIR_NAME = $(shell pwd | xargs basename | tr -cd '[a-zA-Z0-9_.\-]')
  6. DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
  7. BRANCH_NAME=$(BRANCH_NAME) \
  8. PROJECT_NAME=$(PROJECT_NAME) \
  9. MOCHA_GREP=${MOCHA_GREP} \
  10. SHARELATEX_CONFIG=/app/test/acceptance/config/settings.test.coffee \
  11. docker-compose ${DOCKER_COMPOSE_FLAGS}
  12. MODULE_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
  13. MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
  14. MODULE_NAME=$(shell basename $(MODULE))
  15. $(MODULE_MAKEFILES): Makefile.module
  16. cp Makefile.module $@
  17. #
  18. # Clean
  19. #
  20. clean_ci:
  21. $(DOCKER_COMPOSE) down -v -t 0
  22. docker container list | grep 'days ago' | cut -d ' ' -f 1 - | xargs -r docker container stop
  23. docker image prune -af --filter "until=48h"
  24. docker network prune -f
  25. #
  26. # Tests
  27. #
  28. test: test_unit test_frontend test_acceptance
  29. test_module: test_unit_module test_acceptance_module
  30. #
  31. # Unit tests
  32. #
  33. test_unit: test_unit_app test_unit_modules
  34. test_unit_app:
  35. COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  36. COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --name unit_test_$(BUILD_DIR_NAME) --rm test_unit
  37. COMPOSE_PROJECT_NAME=unit_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  38. test_unit_app_parallel: export COMPOSE_PROJECT_NAME = \
  39. unit_test_parallel_$(BUILD_DIR_NAME)
  40. test_unit_app_parallel:
  41. $(DOCKER_COMPOSE) down -v -t 0
  42. $(DOCKER_COMPOSE) run --rm test_unit npm run test:unit:app:parallel
  43. $(DOCKER_COMPOSE) down -v -t 0
  44. TEST_UNIT_MODULES = $(MODULE_DIRS:=/test_unit)
  45. $(TEST_UNIT_MODULES): %/test_unit: %/Makefile
  46. test_unit_modules: $(TEST_UNIT_MODULES)
  47. test_unit_module:
  48. $(MAKE) modules/$(MODULE_NAME)/test_unit
  49. #
  50. # Frontend unit tests
  51. #
  52. test_frontend: build_test_frontend test_frontend_run
  53. test_frontend_run:
  54. COMPOSE_PROJECT_NAME=frontend_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  55. COMPOSE_PROJECT_NAME=frontend_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_frontend
  56. COMPOSE_PROJECT_NAME=frontend_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  57. test_frontend_build_run: build_test_frontend test_frontend_run
  58. #
  59. # Acceptance tests
  60. #
  61. test_acceptance: test_acceptance_app test_acceptance_modules
  62. test_acceptance_app:
  63. COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  64. COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm test_acceptance
  65. COMPOSE_PROJECT_NAME=acceptance_test_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  66. TEST_ACCEPTANCE_MODULES = $(MODULE_DIRS:=/test_acceptance)
  67. $(TEST_ACCEPTANCE_MODULES): %/test_acceptance: %/Makefile
  68. test_acceptance_modules: $(TEST_ACCEPTANCE_MODULES)
  69. CLEAN_TEST_ACCEPTANCE_MODULES = $(MODULE_DIRS:=/clean_test_acceptance)
  70. $(CLEAN_TEST_ACCEPTANCE_MODULES): %/clean_test_acceptance: %/Makefile
  71. clean_test_acceptance_modules: $(CLEAN_TEST_ACCEPTANCE_MODULES)
  72. clean_ci: clean_test_acceptance_modules
  73. test_acceptance_module:
  74. $(MAKE) modules/$(MODULE_NAME)/test_acceptance
  75. #
  76. # CI tests
  77. #
  78. ci:
  79. MOCHA_ARGS="--reporter tap" \
  80. $(MAKE) test
  81. #
  82. # Lint & format
  83. #
  84. ORG_PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  85. RUN_LINT_FORMAT ?= \
  86. docker run --rm \
  87. --volume $(PWD):/src \
  88. --workdir /src \
  89. --env NODE_PATH=/app/node_modules \
  90. --env PATH=$(ORG_PATH):/app/node_modules/.bin \
  91. gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-deps
  92. format:
  93. npm -q run format
  94. format_in_docker:
  95. $(RUN_LINT_FORMAT) make format
  96. format_fix:
  97. npm -q run format:fix
  98. lint:
  99. npm -q run lint
  100. lint_in_docker:
  101. $(RUN_LINT_FORMAT) make lint
  102. #
  103. # Build & publish
  104. #
  105. build_deps:
  106. docker build --pull \
  107. --tag gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-deps \
  108. --cache-from gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-deps \
  109. --cache-from gcr.io/overleaf-ops/$(PROJECT_NAME):master-deps \
  110. --target deps \
  111. .
  112. build: build_deps
  113. docker build --pull --tag ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) \
  114. --tag gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) \
  115. --cache-from gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-deps \
  116. --build-arg SENTRY_RELEASE=${COMMIT_SHA} \
  117. --build-arg BRANCH_NAME=$(BRANCH_NAME) \
  118. .
  119. build_test_frontend:
  120. COMPOSE_PROJECT_NAME=frontend_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) build test_frontend
  121. publish:
  122. docker push $(DOCKER_REPO)/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  123. tar:
  124. COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) run --rm tar
  125. COMPOSE_PROJECT_NAME=tar_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE) down -v -t 0
  126. MODULE_TARGETS = \
  127. $(TEST_ACCEPTANCE_MODULES) \
  128. $(CLEAN_TEST_ACCEPTANCE_MODULES) \
  129. $(TEST_UNIT_MODULES) \
  130. $(MODULE_TARGETS):
  131. $(MAKE) -C $(dir $@) $(notdir $@) BUILD_DIR_NAME=$(BUILD_DIR_NAME)
  132. .PHONY:
  133. $(MODULE_TARGETS) \
  134. compile_modules compile_modules_full clean_ci \
  135. test test_module test_unit test_unit_app \
  136. test_unit_modules test_unit_module test_frontend test_frontend_run \
  137. test_frontend_build_run test_acceptance test_acceptance_app \
  138. test_acceptance_modules test_acceptance_module ci format format_fix lint \
  139. build build_test_frontend publish tar