Skip to content

Commit

Permalink
fix: use printf to fix color output
Browse files Browse the repository at this point in the history
  • Loading branch information
rochecompaan committed Sep 19, 2024
1 parent 725947f commit 208946d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,48 +72,48 @@ 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 \
MISSING="$$MISSING $$exec"; \
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 \
Expand Down

0 comments on commit 208946d

Please sign in to comment.