From 208946d71a30735feb37109da2caf212932e9ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Thu, 19 Sep 2024 12:18:42 +0200 Subject: [PATCH] fix: use printf to fix color output --- {{cookiecutter.project_slug}}/Makefile | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/{{cookiecutter.project_slug}}/Makefile b/{{cookiecutter.project_slug}}/Makefile index e98763a..3f5cf33 100644 --- a/{{cookiecutter.project_slug}}/Makefile +++ b/{{cookiecutter.project_slug}}/Makefile @@ -4,12 +4,15 @@ KUBECTL_EXEC_FRONTEND = kubectl exec -it $$(kubectl get pods -l app=frontend -o {% endif %} PREREQUISITE_COMMANDS := kubectl tilt kind -# colors -BLUE:=$(shell echo "\033[0;36m") -GREEN:=$(shell echo "\033[0;32m") -YELLOW:=$(shell echo "\033[0;33m") -RED:=$(shell echo "\033[0;31m") -END:=$(shell echo "\033[0m") +# escape character for colors +ESC := \033 + +# color variables +BLUE := $(ESC)[0;36m +GREEN := $(ESC)[0;32m +YELLOW := $(ESC)[0;33m +RED := $(ESC)[0;31m +END := $(ESC)[0m PROJECT_SLUG:="{{ cookiecutter.project_slug }}" REGISTRY_HOSTNAME := localhost @@ -69,7 +72,7 @@ backend/requirements/production.txt: compile backend/requirements/tests.txt: compile setup: - @echo " $(YELLOW)⛭$(END) Checking if the setup is correct and all prerequisites are installed..." + @printf " $(YELLOW)⛭$(END) Checking if the setup is correct and all prerequisites are installed..." @MISSING=""; \ for exec in $(PREREQUISITE_COMMANDS); do \ if ! which $$exec > /dev/null 2>&1; then \ @@ -77,40 +80,40 @@ setup: fi; \ done; \ if [ -n "$$MISSING" ]; then \ - echo " $(RED)❌$(END)Missing executables:$$MISSING. These must be installed by you to continue"; \ + printf " $(RED)❌$(END)Missing executables:$$MISSING. These must be installed by you to continue"; \ false; \ else \ - echo " $(GREEN)✔️$(END) All prerequisites are installed."; \ + printf " $(GREEN)✔️$(END) All prerequisites are installed."; \ fi @CURRENT_CONTEXT="$$(kubectl config current-context 2>&1)"; \ CLUSTER_NAME=$(shell echo $(PROJECT_SLUG) | sed 's/_/-/g'); \ NEW_CONTEXT=kind-$$CLUSTER_NAME; \ CLUSTER_EXISTS = $(shell kind get clusters | grep -w $$CLUSTER_NAME$$ || true); \ if [ -z "$$CLUSTER_EXISTS" ]; then \ - echo " $(YELLOW)⛭$(END) No cluster found for $$CLUSTER_NAME. Creating your cluster. Please wait, this may take a couple of minutes on a slower machine..."; \ + printf " $(YELLOW)⛭$(END) No cluster found for $$CLUSTER_NAME. Creating your cluster. Please wait, this may take a couple of minutes on a slower machine..."; \ k8s/scripts/kind-with-registry.sh $$CLUSTER_NAME > /tmp/scaf_cluster.log 2>&1; \ - echo " $(GREEN)✔️$(END) $$NEW_CONTEXT cluster and context created."; \ - echo " $(BLUE)🗣️ $(END) Pre-loading upstream images into cluster."; \ + printf " $(GREEN)✔️$(END) $$NEW_CONTEXT cluster and context created."; \ + printf " $(BLUE)🗣️ $(END) Pre-loading upstream images into cluster."; \ docker pull postgres:16; \ docker pull redis:6.0.5; \ docker pull mailhog/mailhog:v1.0.0; \ kind load docker-image postgres:16 --name $$CLUSTER_NAME; \ kind load docker-image redis:6.0.5 --name $$CLUSTER_NAME; \ kind load docker-image mailhog/mailhog:v1.0.0 --name $$CLUSTER_NAME; \ - echo " $(GREEN)✔️$(END) $$NEW_CONTEXT cluster and context created."; \ - echo " $(BLUE)🗣️ Remember, you can safely run \"make setup\" any time to switch between Scaf projects.$(END)"; \ - echo " $(GREEN)✔️$(END) Finished! Run 'tilt up' to start your cluster! "; \ + printf " $(GREEN)✔️$(END) $$NEW_CONTEXT cluster and context created."; \ + printf " $(BLUE)🗣️ Remember, you can safely run \"make setup\" any time to switch between Scaf projects.$(END)"; \ + printf " $(GREEN)✔️$(END) Finished! Run 'tilt up' to start your cluster! "; \ else \ if [ "$$CURRENT_CONTEXT" = "$$NEW_CONTEXT" ]; then \ - echo " $(GREEN)✔️$(END) The kubectl context is correctly set to '$$NEW_CONTEXT'. Run 'tilt up' to start your cluster!"; \ + printf " $(GREEN)✔️$(END) The kubectl context is correctly set to '$$NEW_CONTEXT'. Run 'tilt up' to start your cluster!"; \ else \ kubectl config use-context $$NEW_CONTEXT 1>/dev/null 2>/tmp/scaf_error.log; \ - echo " $(GREEN)✔️$(END) Context switched to $$NEW_CONTEXT. Run 'tilt up' to start your cluster! "; \ + printf " $(GREEN)✔️$(END) Context switched to $$NEW_CONTEXT. Run 'tilt up' to start your cluster! "; \ fi; \ fi; \ list-local-docker-images: - @echo " $(YELLOW)⛭$(END) Listing local docker images..." + @printf " $(YELLOW)⛭$(END) Listing local docker images..." @curl -s "$(REGISTRY_HOSTNAME):$(REGISTRY_PORT)/v2/_catalog" | jq -r '.repositories[]' | while read REPO; do \ echo "Repository: $$REPO"; \ curl -s "$(REGISTRY_HOSTNAME):$(REGISTRY_PORT)/v2/$$REPO/tags/list" | jq -r '.tags[]' | while read TAG; do \