Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # This file was auto-generated, do not edit it directly.
  2. # Instead run bin/update_build_scripts from
  3. # https://github.com/overleaf/internal/
  4. BUILD_NUMBER ?= local
  5. BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
  6. PROJECT_NAME = real-time
  7. BUILD_DIR_NAME = $(shell pwd | xargs basename | tr -cd '[a-zA-Z0-9_.\-]')
  8. HERE=$(shell pwd)
  9. export MONOREPO ?= $(shell cd ../../ && pwd)
  10. IMAGE_CI ?= ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
  11. IMAGE_REPO ?= us-east1-docker.pkg.dev/overleaf-ops/ol-docker/$(PROJECT_NAME)
  12. IMAGE_REPO_FINAL ?= $(IMAGE_REPO):$(BRANCH_NAME)-$(BUILD_NUMBER)
  13. IMAGE_CACHE ?= $(IMAGE_REPO):cache-$(shell cat \
  14. $(MONOREPO)/package.json \
  15. $(MONOREPO)/package-lock.json \
  16. $(MONOREPO)/libraries/fetch-utils/package.json \
  17. $(MONOREPO)/libraries/logger/package.json \
  18. $(MONOREPO)/libraries/metrics/package.json \
  19. $(MONOREPO)/libraries/o-error/package.json \
  20. $(MONOREPO)/libraries/redis-wrapper/package.json \
  21. $(MONOREPO)/libraries/settings/package.json \
  22. $(MONOREPO)/libraries/validation-tools/package.json \
  23. $(MONOREPO)/services/real-time/package.json \
  24. $(MONOREPO)/patches/* \
  25. | sha256sum | cut -d '-' -f1)
  26. DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
  27. DOCKER_COMPOSE := BUILD_NUMBER=$(BUILD_NUMBER) \
  28. BRANCH_NAME=$(BRANCH_NAME) \
  29. PROJECT_NAME=$(PROJECT_NAME) \
  30. MOCHA_GREP=${MOCHA_GREP} \
  31. docker compose ${DOCKER_COMPOSE_FLAGS}
  32. COMPOSE_PROJECT_NAME_TEST_ACCEPTANCE ?= test_acceptance_$(BUILD_DIR_NAME)
  33. DOCKER_COMPOSE_TEST_ACCEPTANCE = \
  34. COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME_TEST_ACCEPTANCE) $(DOCKER_COMPOSE)
  35. COMPOSE_PROJECT_NAME_TEST_UNIT ?= test_unit_$(BUILD_DIR_NAME)
  36. DOCKER_COMPOSE_TEST_UNIT = \
  37. COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME_TEST_UNIT) $(DOCKER_COMPOSE)
  38. clean:
  39. -docker rmi $(IMAGE_CI)
  40. -docker rmi $(IMAGE_REPO_FINAL)
  41. -$(DOCKER_COMPOSE_TEST_UNIT) down --remove-orphans --rmi local --timeout 0 --volumes
  42. -$(DOCKER_COMPOSE_TEST_ACCEPTANCE) down --remove-orphans --rmi local --timeout 0 --volumes
  43. -rm -rf reports/
  44. # Run the linting commands in the scope of the monorepo.
  45. # Eslint and prettier (plus some configs) are on the root.
  46. RUN_LINTING = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(HERE) node:22.18.0 npm run --silent
  47. RUN_LINTING_CI = docker run --rm --volume $(MONOREPO)/.editorconfig:/overleaf/.editorconfig --volume $(MONOREPO)/.eslintignore:/overleaf/.eslintignore --volume $(MONOREPO)/.eslintrc:/overleaf/.eslintrc --volume $(MONOREPO)/.prettierignore:/overleaf/.prettierignore --volume $(MONOREPO)/.prettierrc:/overleaf/.prettierrc --volume $(MONOREPO)/tsconfig.backend.json:/overleaf/tsconfig.backend.json --volume $(MONOREPO)/services/real-time/reports:/overleaf/services/real-time/reports $(IMAGE_CI) npm run --silent
  48. # Same but from the top of the monorepo
  49. RUN_LINTING_MONOREPO = docker run --rm -v $(MONOREPO):$(MONOREPO) -w $(MONOREPO) node:22.18.0 npm run --silent
  50. SHELLCHECK_OPTS = \
  51. --shell=bash \
  52. --external-sources
  53. SHELLCHECK_COLOR := $(if $(CI),--color=never,--color)
  54. SHELLCHECK_FILES := { git ls-files "*.sh" -z; git grep -Plz "\A\#\!.*bash"; } | sort -zu
  55. shellcheck:
  56. @$(SHELLCHECK_FILES) | xargs -0 -r docker run --rm -v $(HERE):/mnt -w /mnt \
  57. koalaman/shellcheck:stable $(SHELLCHECK_OPTS) $(SHELLCHECK_COLOR)
  58. shellcheck_fix:
  59. @$(SHELLCHECK_FILES) | while IFS= read -r -d '' file; do \
  60. diff=$$(docker run --rm -v $(HERE):/mnt -w /mnt koalaman/shellcheck:stable $(SHELLCHECK_OPTS) --format=diff "$$file" 2>/dev/null); \
  61. if [ -n "$$diff" ] && ! echo "$$diff" | patch -p1 >/dev/null 2>&1; then echo "\033[31m$$file\033[0m"; \
  62. elif [ -n "$$diff" ]; then echo "$$file"; \
  63. else echo "\033[2m$$file\033[0m"; fi \
  64. done
  65. format:
  66. $(RUN_LINTING) format
  67. format_ci:
  68. $(RUN_LINTING_CI) format
  69. format_fix:
  70. $(RUN_LINTING) format:fix
  71. lint:
  72. $(RUN_LINTING) lint
  73. lint_ci:
  74. -$(RUN_LINTING_CI) lint -- --format json --output-file reports/eslint.json
  75. sed -i 's_"filePath":"/overleaf_"filePath":"$(MONOREPO)_g' reports/eslint.json
  76. lint_fix:
  77. $(RUN_LINTING) lint:fix
  78. typecheck:
  79. $(RUN_LINTING) types:check
  80. typecheck_ci:
  81. $(RUN_LINTING_CI) types:check
  82. test: format lint typecheck shellcheck test_unit test_acceptance
  83. test_unit:
  84. ifneq (,$(wildcard test/unit))
  85. $(DOCKER_COMPOSE_TEST_UNIT) run --rm test_unit
  86. endif
  87. test_clean: test_unit_clean
  88. test_unit_clean:
  89. ifneq (,$(wildcard test/unit))
  90. $(DOCKER_COMPOSE_TEST_UNIT) down -v -t 0
  91. endif
  92. test_acceptance: test_acceptance_clean test_acceptance_pre_run test_acceptance_run
  93. $(MAKE) test_acceptance_clean
  94. test_acceptance_debug: test_acceptance_clean test_acceptance_pre_run test_acceptance_run_debug
  95. $(MAKE) test_acceptance_clean
  96. test_acceptance_run:
  97. ifneq (,$(wildcard test/acceptance))
  98. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run --rm test_acceptance
  99. endif
  100. test_acceptance_run_debug:
  101. ifneq (,$(wildcard test/acceptance))
  102. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run -p 127.0.0.9:19999:19999 --rm test_acceptance npm run test:acceptance -- --inspect=0.0.0.0:19999 --inspect-brk
  103. endif
  104. test_clean: test_acceptance_clean
  105. test_acceptance_clean:
  106. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) down -v -t 0
  107. test_acceptance_pre_run:
  108. ifneq (,$(wildcard test/acceptance/js/scripts/pre-run))
  109. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run --rm test_acceptance test/acceptance/js/scripts/pre-run
  110. endif
  111. benchmarks:
  112. $(DOCKER_COMPOSE_TEST_ACCEPTANCE) run --rm test_acceptance npm run benchmarks
  113. build:
  114. docker build \
  115. --pull \
  116. --build-arg BUILDKIT_INLINE_CACHE=1 \
  117. --tag $(IMAGE_CI) \
  118. --tag $(IMAGE_CACHE) \
  119. --tag $(IMAGE_REPO_FINAL) \
  120. --cache-from $(IMAGE_CACHE) \
  121. --file Dockerfile \
  122. ../..
  123. tar:
  124. $(DOCKER_COMPOSE) up tar
  125. push:
  126. docker push $(IMAGE_REPO_FINAL)
  127. push_branch:
  128. docker push $(IMAGE_CACHE)
  129. .PHONY: clean \
  130. format format_fix \
  131. lint lint_fix \
  132. build_types typecheck \
  133. lint_ci format_ci typecheck_ci \
  134. shellcheck shellcheck_fix \
  135. test test_clean test_unit test_unit_clean \
  136. test_acceptance test_acceptance_debug test_acceptance_pre_run \
  137. test_acceptance_run test_acceptance_run_debug test_acceptance_clean \
  138. benchmarks \
  139. build tar publish \