From edbed92c95aa3dee00d9ff49d52068e46a643e13 Mon Sep 17 00:00:00 2001 From: Hao Liu Date: Wed, 15 Mar 2023 16:14:10 -0400 Subject: [PATCH] Refine UI_NEXT Makefile and update README --- Makefile | 7 +- awx/ui_next/Makefile | 203 ++++++++++++++++-------------------------- awx/ui_next/README.md | 12 ++- 3 files changed, 93 insertions(+), 129 deletions(-) diff --git a/Makefile b/Makefile index f4404e8809..9f428ce6d0 100644 --- a/Makefile +++ b/Makefile @@ -451,7 +451,7 @@ HEADLESS ?= no ifeq ($(HEADLESS), yes) dist/$(SDIST_TAR_FILE): else -dist/$(SDIST_TAR_FILE): $(UI_BUILD_FLAG_FILE) awx/ui_next/build +dist/$(SDIST_TAR_FILE): $(UI_BUILD_FLAG_FILE) ui-next endif $(PYTHON) -m build -s ln -sf $(SDIST_TAR_FILE) dist/awx.tar.gz @@ -592,7 +592,7 @@ awx-kube-dev-build: Dockerfile.kube-dev -t $(DEV_DOCKER_TAG_BASE)/awx_kube_devel:$(COMPOSE_TAG) . ## Build awx image for deployment on Kubernetes environment. -awx-kube-build: Dockerfile awx/ui_next/src +awx-kube-build: Dockerfile DOCKER_BUILDKIT=1 docker build -f Dockerfile \ --build-arg VERSION=$(VERSION) \ --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(VERSION) \ @@ -659,6 +659,9 @@ help/generate: help/%: @make -s help MAKEFILE_LIST="$*/Makefile" +help/ui-next: + @make -s help MAKEFILE_LIST="awx/ui_next/Makefile" + ## Display help for a specific target folder help/%/aliases: @make -s help/all MAKEFILE_LIST="$*/Makefile.aliases" diff --git a/awx/ui_next/Makefile b/awx/ui_next/Makefile index 6fed498d5f..bcbaf0f623 100644 --- a/awx/ui_next/Makefile +++ b/awx/ui_next/Makefile @@ -1,142 +1,97 @@ -## UI_NEXT_MKFILE_PATH: Path to this Makefile -UI_NEXT_MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +## UI_NEXT_DIR: Relative path to the directory containing this Makefile +UI_NEXT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) -## UI_NEXT_DIR_ABS: Absolute path to the directory containing this Makefile -UI_NEXT_DIR_ABS := $(dir $(UI_NEXT_MKFILE_PATH)) - -## UI_NEXT_REL_DIR: Relative path to the directory containing this Makefile -# NOTE: UI_NEXT_REL_DIR swallowed the / because we want to be able to run `make src` from the ui_next dir -UI_NEXT_REL_DIR := $(subst $(CURDIR)/,, $(UI_NEXT_DIR_ABS)) - -## UI_NEXT_SRC_DIR: Path to the ui_next src directory -UI_NEXT_SRC_DIR := $(UI_NEXT_REL_DIR)src - -## UI_NEXT_BUILD_DIR: Path to the ui_next build directory -UI_NEXT_BUILD_DIR := $(UI_NEXT_REL_DIR)build - -## Path to your local clone of the UI_NEXT repo -# NOTE: This does not work with docker-compose development environment +# ## Path to your local clone of the UI_NEXT repo +# # NOTE: you will not be able to build within the docker-compose development environment if you use this option UI_NEXT_LOCAL ?= # Git repo and branch to the UI_NEXT repo -UI_NEXT_GIT_REPO_SSH ?= git@github.com:ansible/ansible-ui.git -UI_NEXT_GIT_REPO_HTTPS ?= https://github.com/ansible/ansible-ui.git +UI_NEXT_GIT_REPO ?= https://github.com/ansible/ansible-ui.git UI_NEXT_GIT_BRANCH ?= main -# awx-manage collect static require the awx/ui_next/build to exist -# therefore we have to commit the build directory to source control -# so that make docker-compose will be able to start up uwsgi -# UI_NEXT_BUILT_FILE is here so that we can use it as the non-phony build target -UI_NEXT_BUILT_FILE = $(UI_NEXT_REL_DIR).ui-built +.PHONY: ui-next +## Default build target of ui-next Makefile, builds ui-next/build +ui-next: ui-next/build -## Default target of this Makefile build the ui_next/build from source -ui-next: ui_next/build +.PHONY: ui-next/build +## Build ui-next/build +ui-next/build: $(UI_NEXT_DIR)/build -.PHONY: ui_next/clone-https -## Shallow clone the ui_next repo via https skip if UI_NEXT_GIT_REPO_HTTPS is undefined -ui_next/clone-https: - @if [ -z "$(UI_NEXT_GIT_REPO_HTTPS)" ]; then \ - echo "SKIP: ui_next/clone-https. UI_NEXT_GIT_REPO_HTTPS is not set."; \ - elif [ -d $(UI_NEXT_SRC_DIR) ]; then \ - echo "SKIP: ui_next/clone-https. $(UI_NEXT_SRC_DIR) already exists."; \ +## Real target for ui-next. +$(UI_NEXT_DIR)/build: ui-next/src/build + @echo "=== Copying $(UI_NEXT_DIR)/src/build to $(UI_NEXT_DIR)/build ===" + @rm -rf $(UI_NEXT_DIR)/build + @cp -r $(UI_NEXT_DIR)/src/build $(UI_NEXT_DIR) + @echo "=== Done building $(UI_NEXT_DIR)/build ===" + +.PHONY: ui-next/src/build +## Build ui-next/src/build +ui-next/src/build: $(UI_NEXT_DIR)/src/build + +## Real target for ui-next/src/build. +$(UI_NEXT_DIR)/src/build: ui-next/src ui-next/src/webpack + @echo "=== Building ui_next ===" + @cd $(UI_NEXT_DIR)/src && npm run build:awx + +.PHONY: ui-next/src +ui-next/src: $(UI_NEXT_DIR)/src + +.PHONY: $(UI_NEXT_DIR)/src +## Real target for ui-next/src. +$(UI_NEXT_DIR)/src: + @echo "=== Setting up $(UI_NEXT_DIR)/src ===" + @if [ ! -z "$(UI_NEXT_LOCAL)" ]; then \ + if [ -d $(UI_NEXT_DIR)/src ]; then \ + if [ "$$(readlink $(UI_NEXT_DIR)/src)" = "$(UI_NEXT_LOCAL)" ]; then \ + echo "SKIP: ui-next/src. $(UI_NEXT_DIR)/src already linked to $(UI_NEXT_LOCAL)."; \ + else \ + echo "=== Linking $(UI_NEXT_DIR)/src to $(UI_NEXT_LOCAL) ==="; \ + rm -rf $(UI_NEXT_DIR)/src; \ + ln -s $(UI_NEXT_LOCAL) $(UI_NEXT_DIR)/src; \ + fi; \ + else \ + echo "=== Linking $(UI_NEXT_DIR)/src to $(UI_NEXT_LOCAL) ==="; \ + ln -s $(UI_NEXT_LOCAL) $(UI_NEXT_DIR)/src; \ + fi; \ + elif [ ! -z "$(UI_NEXT_GIT_REPO)" ]; then \ + if [ -d $(UI_NEXT_DIR)/src ]; then \ + GIT_REMOTE_ORIGIN=$$(cd $(UI_NEXT_DIR)/src && git remote get-url origin); \ + GIT_REMOTE_BRANCH=$$(cd $(UI_NEXT_DIR)/src && git rev-parse --abbrev-ref HEAD); \ + if [ "$$GIT_REMOTE_ORIGIN" = "$(UI_NEXT_GIT_REPO)" ] && [ "$$GIT_REMOTE_BRANCH" = "$(UI_NEXT_GIT_BRANCH)" ]; then \ + echo "=== Updating $(UI_NEXT_DIR)/src from $(UI_NEXT_GIT_BRANCH) of $(UI_NEXT_GIT_REPO) ==="; \ + git fetch && git pull; \ + else \ + echo "=== Cloning $(UI_NEXT_DIR)/src from $(UI_NEXT_GIT_BRANCH) of $(UI_NEXT_GIT_REPO) ==="; \ + rm -rf $(UI_NEXT_DIR)/src; \ + git clone --depth 1 --branch $(UI_NEXT_GIT_BRANCH) $(UI_NEXT_GIT_REPO) $(UI_NEXT_DIR)/src || true; \ + fi; \ + else \ + echo "=== Cloning $(UI_NEXT_DIR)/src from $(UI_NEXT_GIT_BRANCH) of $(UI_NEXT_GIT_REPO) ==="; \ + git clone --depth 1 --branch $(UI_NEXT_GIT_BRANCH) $(UI_NEXT_GIT_REPO) $(UI_NEXT_DIR)/src || true; \ + fi; \ else \ - git clone --depth 1 --branch $(UI_NEXT_GIT_BRANCH) $(UI_NEXT_GIT_REPO_HTTPS) $(UI_NEXT_SRC_DIR) || true; \ + echo "SKIP: ui-next/src. UI_NEXT_LOCAL and UI_NEXT_GIT_REPO are not set."; \ fi -.PHONY: ui_next/clone-ssh -## Shallow clone the ui_next repo via ssh. -ui_next/clone-ssh: - @if [ -z "$(UI_NEXT_GIT_REPO_SSH)" ]; then \ - echo "SKIP: ui_next/clone-ssh. UI_NEXT_GIT_REPO_SSH is not set."; \ - elif [ -d $(UI_NEXT_SRC_DIR) ]; then \ - echo "SKIP: ui_next/clone-ssh. $(UI_NEXT_SRC_DIR) already exists."; \ - else \ - git clone --depth 1 --branch $(UI_NEXT_GIT_BRANCH) $(UI_NEXT_GIT_REPO_SSH) $(UI_NEXT_SRC_DIR) || true; \ - fi +.PHONY: ui-next/src/webpack +## Install webpack. +ui-next/src/webpack: $(UI_NEXT_DIR)/src/node_modules/webpack -.PHONY: ui_next/link-local -## Link to a existing local clone of ui_next repo. If method will not be able to build inside docker-compose environment -ui_next/link-local: - @if [ -z "$(UI_NEXT_LOCAL)" ]; then \ - echo "SKIP: ui_next/link-local. UI_NEXT_LOCAL is not set."; \ - elif [ -d $(UI_NEXT_SRC_DIR) ]; then \ - echo "SKIP: ui_next/link-local. $(UI_NEXT_SRC_DIR) already exists."; \ - else \ - ln -s $(UI_NEXT_LOCAL) $(UI_NEXT_SRC_DIR); \ - fi +## Real target for ui-next/src/webpack. +$(UI_NEXT_DIR)/src/node_modules/webpack: + @echo "=== Installing webpack ===" + @cd $(UI_NEXT_DIR)/src && npm install webpack -.PHONY: ui_next/src -## Try to link to a local clone of ui_next repo if it exist otherwise clone via ssh than https. -ui_next/src: - @if [ -d $(UI_NEXT_SRC_DIR) ]; then \ - echo "SKIP: ui_next. $(UI_NEXT_SRC_DIR) already exists."; \ - else \ - $(MAKE) ui_next/link-local ui_next/clone-ssh ui_next/clone-https; \ - fi - -## Alias for ui_next, will not run if ui_next/src already exist -$(UI_NEXT_SRC_DIR): - $(MAKE) ui_next/src - -## Alias for ui_next/build, will not run if ui_next/src/build already exist -$(UI_NEXT_SRC_DIR)/build: - $(MAKE) ui_next/src/build - -.PHONY: ui_next/build -## Build ui_next from source -ui_next/src/build: $(UI_NEXT_SRC_DIR) $(UI_NEXT_SRC_DIR)/node_modules/webpack - @cd $(UI_NEXT_SRC_DIR) && npm run build:awx - - -## Install webpack if does not exist. -ui_next/src/node_modules/webpack: $(UI_NEXT_SRC_DIR) - @if [ -d $(UI_NEXT_SRC_DIR)/node_modules/webpack ]; then \ - echo "SKIP: ui_next/src/node_modules/webpack. $(UI_NEXT_SRC_DIR)/node_modules/webpack already exists."; \ - else \ - cd $(UI_NEXT_SRC_DIR) && npm install webpack; \ - fi - -## Alias for ui_next/src/node_modules/webpack. will not run if webpack already exist -$(UI_NEXT_SRC_DIR)/node_modules/webpack: - $(MAKE) ui_next/src/node_modules/webpack - -## Copy ui_next/src/build to ui_next/build -ui_next/build: ui_next/clean/build - $(MAKE) $(UI_NEXT_SRC_DIR)/build - @mkdir $(UI_NEXT_DIR_ABS)build && \ - cp -r $(UI_NEXT_SRC_DIR)/build/awx $(UI_NEXT_DIR_ABS)build/awx &&\ - touch $(UI_NEXT_BUILT_FILE) - -## Alias for ui_next/build. Will not run if .ui-built file already exist -$(UI_NEXT_BUILT_FILE): - $(MAKE) ui_next/build - -## Alias for ui_next/build. -.PHONY: $(UI_NEXT_BUILD_DIR) -$(UI_NEXT_BUILD_DIR): - $(MAKE) ui_next/build - -.PHONY: $(UI_NEXT_REL_DIR)clean -## Alias for ui_next/clean. -$(UI_NEXT_REL_DIR)clean: - rm -rf $(UI_NEXT_SRC_DIR) - rm -rf $(UI_NEXT_BUILD_DIR) - -.PHONY: ui_next/clean +.PHONY: clean/ui-next ## Clean ui_next -ui_next/clean: ui_next/clean/build - rm -rf $(UI_NEXT_SRC_DIR) +clean/ui-next: clean/ui-next/build clean/ui-next/src -.PHONY: ui_next/clean/src +.PHONY: clean/ui-next/src ## Clean ui_next src -ui_next/clean/src: - rm -rf $(UI_NEXT_SRC_DIR) +clean/ui-next/src: + rm -rf $(UI_NEXT_DIR)/src -.PHONY: ui_next/clean/build +.PHONY: clean/ui-next/build ## Clean ui_next build -ui_next/clean/build: - rm -rf $(UI_NEXT_BUILD_DIR) - rm -rf $(UI_NEXT_BUILT_FILE) - -print-%: - @echo $($*) \ No newline at end of file +clean/ui-next/build: + rm -rf $(UI_NEXT_DIR)/build diff --git a/awx/ui_next/README.md b/awx/ui_next/README.md index 35c5beb7c2..77d719e050 100644 --- a/awx/ui_next/README.md +++ b/awx/ui_next/README.md @@ -5,13 +5,13 @@ ### via GIT ```bash -export UI_NEXT_GIT_BRANCH_REPO_HTTPS=https:// +export UI_NEXT_GIT_BRANCH_REPO=https:// ``` or ```bash -export UI_NEXT_GIT_BRANCH_REPO_SSH=git@ +export UI_NEXT_GIT_BRANCH_REPO=git@ ``` optionally set branch (default is main) @@ -29,5 +29,11 @@ export UI_NEXT_LOCAL = /path/to/your/ui_next ## Build ```bash -make ui_next/build +make ui-next +``` + +## Clean + +```bash +make clean/ui-next ```