Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. .PHONY: help purge uninstall-src uninstall clean
  17. .PHONY: lint-dependencies lint-server black-format prettier-check-ui eslint-check-ui prettier-ui eslint-ui lint-ui lint
  18. .PHONY: dev-link dev-unlink
  19. .PHONY: build-dependencies yarn-install build-ui package-ui package-ui-dev build-server install-server-package install-server
  20. .PHONY: install install-all install-dev install-examples install-gitlab-dependency check-install watch release
  21. .PHONY: test-dependencies pytest test-server test-ui-unit test-integration test-integration-debug test-ui test
  22. .PHONY: docs-dependencies docs
  23. .PHONY: elyra-image elyra-image-env publish-elyra-image kf-notebook-image publish-kf-notebook-image
  24. .PHONY: container-images publish-container-images validate-runtime-images
  25. .ONESHELL:
  26. SHELL:=/bin/bash
  27. # Python execs
  28. PYTHON?=python3
  29. PYTHON_PIP=$(PYTHON) -m pip
  30. PYTHON_VERSION?=3.9
  31. CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate
  32. ELYRA_VERSION:=$$(grep __version__ elyra/_version.py | cut -d"\"" -f2)
  33. TAG:=dev
  34. ELYRA_IMAGE=elyra/elyra:$(TAG)
  35. ELYRA_IMAGE_LATEST=elyra/elyra:latest
  36. ELYRA_IMAGE_ENV?=elyra-image-env
  37. KF_NOTEBOOK_IMAGE=elyra/kf-notebook:$(TAG)
  38. KF_NOTEBOOK_IMAGE_LATEST=elyra/kf-notebook:latest
  39. # Contains the set of commands required to be used by elyra
  40. REQUIRED_RUNTIME_IMAGE_COMMANDS?="curl python3"
  41. REMOVE_RUNTIME_IMAGE?=0 # Invoke `make REMOVE_RUNTIME_IMAGE=1 validate-runtime-images` to have images removed after validation
  42. UPGRADE_STRATEGY?=only-if-needed
  43. # Black CMD for code formatting
  44. BLACK_CMD:=$(PYTHON) -m black --check --diff --color .
  45. help:
  46. # http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
  47. @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
  48. ## Clean targets
  49. purge:
  50. rm -rf build *.egg-info yarn-error.log
  51. rm -rf node_modules lib dist
  52. rm -rf $$(find packages -name node_modules -type d -maxdepth 2)
  53. rm -rf $$(find packages -name dist -type d)
  54. rm -rf $$(find packages -name lib -type d)
  55. rm -rf $$(find packages -name *.egg-info -type d)
  56. rm -rf $$(find . -name __pycache__ -type d)
  57. rm -rf $$(find . -name tsconfig.tsbuildinfo)
  58. rm -rf $$(find . -name package-lock.json)
  59. rm -rf $$(find . -name .pytest_cache)
  60. rm -rf $(yarn cache dir)
  61. uninstall-src: # Uninstalls source extensions if they're still installed
  62. - jupyter labextension unlink --no-build @elyra/services
  63. - jupyter labextension unlink --no-build @elyra/ui-components
  64. - jupyter labextension unlink --no-build @elyra/metadata-common
  65. - jupyter labextension unlink --no-build @elyra/script-editor
  66. - jupyter labextension uninstall --no-build @elyra/theme-extension
  67. - jupyter labextension uninstall --no-build @elyra/code-snippet-extension
  68. - jupyter labextension uninstall --no-build @elyra/metadata-extension
  69. - jupyter labextension uninstall --no-build @elyra/pipeline-editor-extension
  70. - jupyter labextension uninstall --no-build @elyra/python-editor-extension
  71. - jupyter labextension uninstall --no-build @elyra/r-editor-extension
  72. - jupyter labextension uninstall --no-build @elyra/code-viewer-extension
  73. - jupyter labextension unlink --no-build @elyra/pipeline-services
  74. - jupyter labextension unlink --no-build @elyra/pipeline-editor
  75. uninstall: uninstall-src
  76. $(PYTHON_PIP) uninstall -y jupyterlab-git
  77. $(PYTHON_PIP) uninstall -y nbdime
  78. $(PYTHON_PIP) uninstall -y jupyter-lsp
  79. - jupyter labextension uninstall @krassowski/jupyterlab-lsp
  80. $(PYTHON_PIP) uninstall -y jupyterlab-lsp
  81. $(PYTHON_PIP) uninstall -y python-lsp-server
  82. $(PYTHON_PIP) uninstall -y jupyter-resource-usage
  83. - jupyter labextension uninstall @jupyter-server/resource-usage
  84. $(PYTHON_PIP) uninstall -y elyra
  85. - jupyter lab clean
  86. # remove Kubeflow Pipelines example components
  87. - $(PYTHON_PIP) uninstall -y elyra-examples-kfp-catalog
  88. # remove GitLab dependency
  89. - $(PYTHON_PIP) uninstall -y python-gitlab
  90. clean: purge uninstall ## Make a clean source tree and uninstall extensions
  91. ## Lint targets
  92. lint-dependencies:
  93. @$(PYTHON_PIP) install -q -r lint_requirements.txt
  94. lint-server: lint-dependencies
  95. $(PYTHON) -m flake8 elyra
  96. @echo $(BLACK_CMD)
  97. @$(BLACK_CMD) || (echo "Black formatting encountered issues. Use 'make black-format' to apply the suggested changes."; exit 1)
  98. black-format: # Apply black formatter to Python source code
  99. $(PYTHON) -m black .
  100. prettier-check-ui:
  101. yarn prettier:check
  102. eslint-check-ui:
  103. yarn eslint:check --max-warnings=0
  104. prettier-ui:
  105. yarn prettier
  106. eslint-ui:
  107. yarn eslint --max-warnings=0
  108. lint-ui: prettier-ui eslint-ui
  109. lint: lint-ui lint-server ## Run linters
  110. ## Library linking targets
  111. dev-link:
  112. - yarn link @elyra/pipeline-services
  113. - yarn link @elyra/pipeline-editor
  114. - lerna run link:dev
  115. dev-unlink:
  116. - yarn unlink @elyra/pipeline-services
  117. - yarn unlink @elyra/pipeline-editor
  118. - lerna run unlink:dev
  119. yarn install --force
  120. ## Build and install targets
  121. build-dependencies:
  122. @$(PYTHON_PIP) install -q --upgrade pip
  123. @$(PYTHON_PIP) install -q -r build_requirements.txt
  124. yarn-install:
  125. yarn install
  126. build-ui: # Build packages
  127. yarn lerna run build --stream
  128. package-ui: build-dependencies yarn-install lint-ui build-ui
  129. package-ui-dev: build-dependencies yarn-install dev-link lint-ui build-ui
  130. build-server: # Build backend
  131. $(PYTHON) -m setup bdist_wheel sdist
  132. uninstall-server-package:
  133. @$(PYTHON_PIP) uninstall elyra -y
  134. install-server-package: uninstall-server-package
  135. $(PYTHON_PIP) install --upgrade --upgrade-strategy $(UPGRADE_STRATEGY) "$(shell find dist -name "elyra-*-py3-none-any.whl")[kfp-tekton]"
  136. install-server: build-dependencies lint-server build-server install-server-package ## Build and install backend
  137. install: package-ui install-server check-install ## Build and install
  138. install-all: package-ui install-server install-examples install-gitlab-dependency check-install ## Build and install, including examples
  139. install-dev: package-ui-dev install-server install-examples install-gitlab-dependency check-install
  140. install-examples: ## Install example pipeline components
  141. # install Kubeflow Pipelines example components
  142. # -> https://github.com/elyra-ai/examples/tree/master/component-catalog-connectors/kfp-example-components-connector
  143. - $(PYTHON_PIP) install --upgrade elyra-examples-kfp-catalog
  144. install-gitlab-dependency:
  145. # install GitLab support for Airflow
  146. - $(PYTHON_PIP) install --upgrade python-gitlab
  147. check-install:
  148. jupyter server extension list
  149. jupyter labextension list
  150. watch: ## Watch packages. For use alongside jupyter lab --watch
  151. yarn lerna run watch --parallel
  152. release: yarn-install build-ui build-server ## Build wheel file for release
  153. elyra-image-env: ## Creates a conda env consisting of the dependencies used in images
  154. conda env remove -y -n $(ELYRA_IMAGE_ENV)
  155. conda create -y -n $(ELYRA_IMAGE_ENV) python=$(PYTHON_VERSION)
  156. if [ "$(PYTHON_VERSION)" == "3.7" ]; then \
  157. $(CONDA_ACTIVATE) $(ELYRA_IMAGE_ENV) && \
  158. $(PYTHON_PIP) install -r etc/generic/requirements-elyra-py37.txt && \
  159. conda deactivate; \
  160. else \
  161. $(CONDA_ACTIVATE) $(ELYRA_IMAGE_ENV) && \
  162. $(PYTHON_PIP) install -r etc/generic/requirements-elyra.txt && \
  163. conda deactivate; \
  164. fi
  165. ## Test targets
  166. test-dependencies:
  167. @$(PYTHON_PIP) install -q -r test_requirements.txt
  168. pytest:
  169. $(PYTHON) -m pytest -v elyra
  170. test-server: test-dependencies pytest # Run python unit tests
  171. test-ui-unit: # Run frontend jest unit tests
  172. yarn test:unit
  173. test-integration: # Run frontend cypress integration tests
  174. yarn test:integration
  175. test-integration-debug: # Open cypress integration test debugger
  176. yarn test:integration:debug
  177. test-ui: lint-ui test-ui-unit test-integration # Run frontend tests
  178. test: test-server test-ui ## Run all tests (backend, frontend and cypress integration tests)
  179. ## Doc targets
  180. docs-dependencies:
  181. @$(PYTHON_PIP) install -q -r docs/requirements.txt
  182. docs: docs-dependencies ## Build docs
  183. make -C docs clean html
  184. ## Docker targets
  185. elyra-image: # Build Elyra stand-alone container image
  186. @mkdir -p build/docker
  187. cp etc/docker/elyra/Dockerfile build/docker/Dockerfile
  188. cp etc/docker/elyra/start-elyra.sh build/docker/start-elyra.sh
  189. cp etc/docker/elyra/requirements.txt build/docker/requirements.txt
  190. @mkdir -p build/docker/elyra
  191. if [ "$(TAG)" == "dev" ]; then \
  192. cp dist/elyra-$(ELYRA_VERSION)-py3-none-any.whl build/docker/; \
  193. fi
  194. docker buildx build \
  195. --progress=plain \
  196. --output=type=docker \
  197. --tag docker.io/$(ELYRA_IMAGE) \
  198. --tag quay.io/$(ELYRA_IMAGE) \
  199. --build-arg TAG=$(TAG) \
  200. --build-arg ELYRA_VERSION=$(ELYRA_VERSION) \
  201. build/docker/;
  202. publish-elyra-image: elyra-image # Publish Elyra stand-alone container image
  203. # this is a privileged operation; a `docker login` might be required
  204. docker push docker.io/$(ELYRA_IMAGE)
  205. docker push quay.io/$(ELYRA_IMAGE)
  206. # If we're building a release from master, tag latest and push
  207. if [ "$(TAG)" != "dev" -a "$(shell git branch --show-current)" == "master" ]; then \
  208. docker tag docker.io/$(ELYRA_IMAGE) docker.io/$(ELYRA_IMAGE_LATEST); \
  209. docker push docker.io/$(ELYRA_IMAGE_LATEST); \
  210. docker tag quay.io/$(ELYRA_IMAGE) quay.io/$(ELYRA_IMAGE_LATEST); \
  211. docker push quay.io/$(ELYRA_IMAGE_LATEST); \
  212. fi
  213. kf-notebook-image: # Build elyra image for use with Kubeflow Notebook Server
  214. @mkdir -p build/docker-kubeflow
  215. cp etc/docker/kubeflow/* build/docker-kubeflow/
  216. if [ "$(TAG)" == "dev" ]; then \
  217. cp dist/elyra-$(ELYRA_VERSION)-py3-none-any.whl build/docker-kubeflow/; \
  218. fi
  219. docker buildx build \
  220. --progress=plain \
  221. --output=type=docker \
  222. --tag docker.io/$(KF_NOTEBOOK_IMAGE) \
  223. --tag quay.io/$(KF_NOTEBOOK_IMAGE) \
  224. --build-arg TAG=$(TAG) \
  225. --build-arg ELYRA_VERSION=$(ELYRA_VERSION) \
  226. build/docker-kubeflow;
  227. publish-kf-notebook-image: kf-notebook-image # Publish elyra image for use with Kubeflow Notebook Server
  228. # this is a privileged operation; a `docker login` might be required
  229. docker push docker.io/$(KF_NOTEBOOK_IMAGE)
  230. docker push quay.io/$(KF_NOTEBOOK_IMAGE)
  231. # If we're building a release from master, tag latest and push
  232. if [ "$(TAG)" != "dev" -a "$(shell git branch --show-current)" == "master" ]; then \
  233. docker tag docker.io/$(KF_NOTEBOOK_IMAGE) docker.io/$(KF_NOTEBOOK_IMAGE_LATEST); \
  234. docker push docker.io/$(KF_NOTEBOOK_IMAGE_LATEST); \
  235. docker tag quay.io/$(KF_NOTEBOOK_IMAGE) quay.io/$(KF_NOTEBOOK_IMAGE_LATEST); \
  236. docker push quay.io/$(KF_NOTEBOOK_IMAGE_LATEST); \
  237. fi
  238. container-images: elyra-image kf-notebook-image ## Build all container images
  239. docker images $(ELYRA_IMAGE)
  240. docker images quay.io/$(ELYRA_IMAGE)
  241. docker images $(KF_NOTEBOOK_IMAGE)
  242. docker images quay.io/$(KF_NOTEBOOK_IMAGE)
  243. publish-container-images: publish-elyra-image publish-kf-notebook-image ## Publish all container images
  244. validate-runtime-images: # Validates delivered runtime-images meet minimum criteria
  245. @required_commands=$(REQUIRED_RUNTIME_IMAGE_COMMANDS) ; \
  246. $(PYTHON_PIP) install jq ; \
  247. for file in `find etc/config/metadata/runtime-images -name "*.json"` ; do \
  248. image=`cat $$file | jq -e -r '.metadata.image_name'` ; \
  249. if [ $$? -ne 0 ]; then \
  250. echo ERROR: $$file does not define the image_name property ; \
  251. exit 1; \
  252. fi; \
  253. fail=0; \
  254. for cmd in $$required_commands ; do \
  255. echo Checking $$image in $$file for $$cmd... ; \
  256. docker inspect $$image > /dev/null 2>&1 ; \
  257. if [ $$? -ne 0 ]; then \
  258. echo Image $$image is not present, pulling... ; \
  259. fi; \
  260. docker run --rm $$image which $$cmd > /dev/null 2>&1 ; \
  261. if [ $$? -ne 0 ]; then \
  262. echo ERROR: Image $$image did not meet criteria for command: $$cmd ; \
  263. fail=1; \
  264. fi; \
  265. if [ $$cmd == "python3" ]; then \
  266. IMAGE_PYTHON3_MINOR_VERSION=`docker run --rm $$image $$cmd --version | cut -d' ' -f2 | cut -d'.' -f2` ; \
  267. if [[ $$IMAGE_PYTHON3_MINOR_VERSION -lt 8 ]]; then \
  268. echo WARNING: Image $$image requires at Python 3.8 or greater for latest generic component dependency installation; \
  269. docker run -v $$(pwd)/etc/generic:/opt/elyra/ --rm $$image /bin/bash -c "python3 -m pip install -r /opt/elyra/requirements-elyra-py37.txt && \
  270. curl https://raw.githubusercontent.com/nteract/papermill/main/papermill/tests/notebooks/simple_execute.ipynb --output simple_execute.ipynb && \
  271. python3 -m papermill simple_execute.ipynb output.ipynb > /dev/null" ; \
  272. if [ $$? -ne 0 ]; then \
  273. echo ERROR: Image $$image did not meet python requirements criteria in requirements-elyra-py37.txt ; \
  274. fail=1; \
  275. fi; \
  276. elif [[ $$IMAGE_PYTHON3_MINOR_VERSION -ge 8 ]]; then \
  277. docker run -v $$(pwd)/etc/generic:/opt/elyra/ --rm $$image /bin/bash -c "python3 -m pip install -r /opt/elyra/requirements-elyra.txt && \
  278. curl https://raw.githubusercontent.com/nteract/papermill/main/papermill/tests/notebooks/simple_execute.ipynb --output simple_execute.ipynb && \
  279. python3 -m papermill simple_execute.ipynb output.ipynb > /dev/null" ; \
  280. if [ $$? -ne 0 ]; then \
  281. echo ERROR: Image $$image did not meet python requirements criteria in requirements-elyra.txt ; \
  282. fail=1; \
  283. fi; \
  284. else \
  285. echo ERROR: Image $$image unable to parse python version ; \
  286. fail=1; \
  287. fi; \
  288. fi; \
  289. done; \
  290. if [ $(REMOVE_RUNTIME_IMAGE) -eq 1 ]; then \
  291. echo Removing image $$image... ; \
  292. docker rmi $$image > /dev/null ; \
  293. fi; \
  294. if [ $$fail -eq 1 ]; then \
  295. exit 1; \
  296. fi; \
  297. done