diff --git a/Makefile b/Makefile index e1a6ae1d..6d9ff0ae 100644 --- a/Makefile +++ b/Makefile @@ -12,38 +12,70 @@ DOCKER_FILE_PATH := deployment/containers IMAGE ?= filer TAG ?= testing -# Default target, build image if `make` is called without any arguments -default: build +default: help + +# Help message +.PHONY: help +help: + @echo "Usage: make [target]" + @echo "Available targets:" + @echo " \033[1mvenv \033[37m(v\033[0m)" + @echo " \033[36mCreate virtual environment\033[0m" + @echo " \033[1mclean-venv \033[37m(cv\033[0m)" + @echo " \033[36mRemove virtual environment\033[0m" + @echo " \033[1minstall \033[37m(i\033[0m)" + @echo " \033[36mInstall dependencies\033[0m" + @echo " \033[1mbuild-service-image \033[37m(bsi\033[0m)" + @echo " \033[36mBuild image for service (tesk_core)\033[0m" + @echo " \033[36mEg: make bsi IMAGE=filer TAG=1.1.0\033[0m" + @echo " \033[1mbuild-service-image-all \033[37m(bsia\033[0m)" + @echo " \033[36mBuild images for all services\033[0m" + @echo " \033[1mrun-service\033[0m" + @echo " \033[36mRun container for service (tesk_core)\033[0m" + @echo " \033[36mEg: make run-service IMAGE=filer TAG=testing\033[0m" + @echo " \033[1mclean-service-image \033[37m(csi\033[0m)" + @echo " \033[36mClean image for service (tesk_core)\033[0m" + @echo " \033[36mEg: make csi IMAGE=filer TAG=testing\033[0m" + @echo " \033[1mclean-service-image-all \033[37m(csia\033[0m)" + @echo " \033[36mClean images for all services of the given tag\033[0m" + @echo " \033[36mEg: make csia TAG=testing\033[0m" + @echo " \033[1mhelp\033[0m" + @echo " \033[36mDisplay this help message\033[0m" -# Create and activate virtual environment .PHONY: venv venv: @if [ -x "$(PYTHON_CMD)" ]; then \ $(PYTHON_CMD) -m venv .venv; \ - echo "Virtual environment created. To activate, run: source .venv/bin/activate"; \ + echo "🙏 Virtual environment created. To activate, run:"; \ + echo "source .venv/bin/activate"; \ else \ - echo "Please install python3 to create virtual environment."; \ + echo "🐍 Please install `python3` to create virtual environment."; \ exit 1; \ fi -# Remove virtual environment +.PHONY: v +v: venv + .PHONY: clean-venv clean-venv: rm -rf .venv -# TODO: Install package manages and change the below commands -# Install dependencies +.PHONY: cv +cv: clean-venv + .PHONY: install install: @if [ -f .venv/bin/activate ]; then \ pip install .; \ else \ - echo "Virtual environment not found. Please create it first using 'make venv'."; \ + echo "🐍 Virtual environment not found. Please create it first using 'make venv'."; \ fi -# Build image -.PHONY: build -build: +.PHONY: i +i: install + +.PHONY: build-service-image +build-service-image: @if [ -x "$(BUILDAH_CMD)" ]; then \ $(BUILDAH_CMD) bud \ -t $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) \ @@ -55,21 +87,57 @@ build: -t $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) \ -f $(DOCKER_FILE_PATH)/$(IMAGE).Dockerfile .; \ else \ - echo "Please install buildah or docker to build images."; \ + echo "🐳 Please install buildah or docker to build images."; \ exit 1; \ fi -# Run image -.PHONY: run -run: +.PHONY: bsi +bsi: build-service-image + +.PHONY: build-service-image-all +build-service-image-all: + @make build-service-image IMAGE=filer TAG=$(TAG) + @make build-service-image IMAGE=taskmaster TAG=$(TAG) + +.PHONY: bsia +bsia: build-service-image-all + +.PHONY: run-service +run-service: @if [ -x "$(DOCKER_CMD)" ]; then \ $(DOCKER_CMD) run \ -it --rm $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG); \ else \ - echo "Please install docker to run images."; \ + echo "🐳 Please install docker to run images."; \ exit 1; \ fi -# Clean up built images or other generated artifacts -clean: - docker rmi $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) +.PHONY: clean-service-image +clean-service-image: + @if [ -x "$(BUILDAH_CMD)" ]; then \ + if $(BUILDAH_CMD) inspect $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) > /dev/null 2>&1; then \ + $(BUILDAH_CMD) rmi $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG); \ + else \ + echo "🔍 Image $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) not found."; \ + fi \ + elif [ -x "$(DOCKER_CMD)" ]; then \ + if $(DOCKER_CMD) inspect $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) > /dev/null 2>&1; then \ + $(DOCKER_CMD) rmi $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG); \ + else \ + echo "🔍 Image $(ELIXIR_CLOUD_REGISTRY)/tesk-core-$(IMAGE):$(TAG) not found."; \ + fi \ + else \ + echo "🐳 Please install buildah or docker to clean images."; \ + exit 1; \ + fi + +.PHONY: csi +csi: clean-service-image + +.PHONY: clean-service-image-all +clean-service-image-all: + @make clean-service-image IMAGE=filer TAG=$(TAG) + @make clean-service-image IMAGE=taskmaster TAG=$(TAG) + +.PHONY: csia +csia: clean-service-image-all \ No newline at end of file