Skip to content

Commit 10715a6

Browse files
author
Dmitry Smirnov
committed
makefile improvements
1 parent bc9bdbe commit 10715a6

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

Makefile

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,70 +9,85 @@ include Makefile.help
99

1010
# Build the Docker image
1111
build:
12-
@echo "Building Docker image..."
12+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Building Docker image...$(COLOR_RESET)\n"
1313
@if [ "$(MULTIPLATFORM)" = "true" ]; then \
14-
echo "Building Docker image for multiple platforms..."; \
14+
printf "$(COLOR_BLUE)$(SYM_ARROW) Building for multiple platforms...$(COLOR_RESET)\n" && \
1515
docker buildx build --platform $(BUILD_PLATFORMS) -t $(DOCKER_IMAGE) .; \
1616
else \
17-
echo "Building Docker image for the local platform..."; \
17+
printf "$(COLOR_BLUE)$(SYM_ARROW) Building for local platform...$(COLOR_RESET)\n" && \
1818
docker build -t $(DOCKER_IMAGE) .; \
19-
fi
20-
@echo "Docker image build completed."
19+
fi && \
20+
printf "$(COLOR_GREEN)$(SYM_SUCCESS) Docker image build completed$(COLOR_RESET)\n" || \
21+
{ printf "$(COLOR_RED)$(SYM_ERROR) Docker build failed$(COLOR_RESET)\n"; exit 1; }
2122

2223
# Run Docker container (supports interactive mode)
2324
run: clean
24-
@echo "Running Docker container..."
25+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Running Docker container...$(COLOR_RESET)\n"
2526

2627
@if [ ! -f $(ENV_FILE) ]; then \
27-
echo "Creating environment file..."; \
28+
printf "$(COLOR_YELLOW)$(SYM_WARNING) Creating environment file...$(COLOR_RESET)\n" && \
2829
touch $(ENV_FILE); \
2930
else \
30-
echo "Environment file exists..."; \
31+
printf "$(COLOR_BLUE)$(SYM_ARROW) Using existing environment file$(COLOR_RESET)\n"; \
3132
fi
3233

3334
@docker run $(if $(INTERACTIVE),-it,-d) --rm --name $(CONTAINER_NAME) \
3435
--env-file $(ENV_FILE) \
3536
-p $(HOST_PORT):$(CONTAINER_PORT) \
3637
$(foreach vol,$(VOLUMES),-v $(vol)) \
37-
$(DOCKER_IMAGE) $(COMMAND)
38+
$(DOCKER_IMAGE) $(CMD) && \
39+
printf "$(COLOR_GREEN)$(SYM_SUCCESS) Container started successfully$(COLOR_RESET)\n" || \
40+
{ printf "$(COLOR_RED)$(SYM_ERROR) Failed to start container$(COLOR_RESET)\n"; exit 1; }
3841
@$(MAKE) wait-container-ready
3942

4043

4144
# Run Docker container in interactive mode
4245
run-it:
46+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Starting interactive container...$(COLOR_RESET)\n"
4347
@$(MAKE) run INTERACTIVE=true CMD="/bin/bash"
4448

4549
# Execute a command in the running container
4650
exec:
47-
@echo "Executing into Docker container..."
48-
@docker exec -it $(CONTAINER_NAME) /bin/bash
51+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Executing into container...$(COLOR_RESET)\n"
52+
@docker exec -it $(CONTAINER_NAME) /bin/bash || \
53+
{ printf "$(COLOR_RED)$(SYM_ERROR) Failed to execute into container$(COLOR_RESET)\n"; exit 1; }
54+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Successfully executed into container$(COLOR_RESET)\n"
4955

5056
# View the container logs
5157
log:
52-
@echo "Viewing Docker container logs..."
53-
@docker logs $(CONTAINER_NAME) || echo "No running container to log."
58+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Fetching container logs...$(COLOR_RESET)\n"
59+
@if [ "$(FOLLOW_LOGS)" = "true" ]; then \
60+
docker logs -f $(CONTAINER_NAME) || \
61+
{ printf "$(COLOR_RED)$(SYM_ERROR) Failed to retrieve logs$(COLOR_RESET)\n"; exit 1; }; \
62+
else \
63+
docker logs $(CONTAINER_NAME) || \
64+
{ printf "$(COLOR_RED)$(SYM_ERROR) Failed to retrieve logs$(COLOR_RESET)\n"; exit 1; }; \
65+
fi
66+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Logs retrieved successfully$(COLOR_RESET)\n"
5467

5568
# Stop and remove the running container if it exists
5669
clean:
57-
@echo "Stopping and removing Docker container if it exists..."
58-
@docker rm -f $(CONTAINER_NAME) || true
70+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Cleaning up containers...$(COLOR_RESET)\n"
71+
@docker stop $(CONTAINER_NAME) 2>/dev/null || true
72+
@docker rm -f $(CONTAINER_NAME) 2>/dev/null || true
73+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Cleanup completed$(COLOR_RESET)\n"
5974

6075
# Wait for container to be ready (using HTTP readiness check on NGINX)
6176
wait-container-ready:
62-
@echo "Waiting for the container to be ready..."
77+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Waiting for container readiness...$(COLOR_RESET)\n"
6378
@counter=0; \
6479
while ! curl -s -o /dev/null -w "%{http_code}" http://localhost:$(HOST_PORT) | grep -q "200"; do \
6580
if [ $$counter -ge 30 ]; then \
66-
echo "Timeout: Services did not start"; \
67-
echo "Displaying NGINX logs for troubleshooting:"; \
68-
docker logs $(CONTAINER_NAME) || echo "No logs available"; \
81+
printf "$(COLOR_RED)$(SYM_ERROR) Timeout: Services did not start$(COLOR_RESET)\n"; \
82+
printf "$(COLOR_YELLOW)$(SYM_WARNING) Displaying NGINX logs for troubleshooting:$(COLOR_RESET)\n"; \
83+
docker logs $(CONTAINER_NAME) || printf "$(COLOR_RED)$(SYM_ERROR) No logs available$(COLOR_RESET)\n"; \
6984
exit 1; \
7085
fi; \
71-
echo "Waiting for services to be ready..."; \
86+
printf "$(COLOR_BLUE)$(SYM_ARROW) Waiting for services to be ready...$(COLOR_RESET)\n"; \
7287
sleep 5; \
7388
counter=$$((counter + 1)); \
7489
done
75-
@echo "Container is ready."
90+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Container is ready$(COLOR_RESET)\n"
7691

7792
# Run a specific test script (specified by TEST_SCRIPT)
7893
run-test:
@@ -81,22 +96,23 @@ run-test:
8196

8297
# Run all tests in the tests directory
8398
run-all-tests: clean
84-
@echo "Starting Docker container for test execution..."
99+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Starting test container...$(COLOR_RESET)\n"
85100
@docker run -d --name $(CONTAINER_NAME) -v $(CURDIR)/$(SRC_PATH):$(CONTAINER_SRC_PATH) -p $(HOST_PORT):$(CONTAINER_PORT) $(DOCKER_IMAGE)
86101
@$(MAKE) wait-container-ready
87-
@echo "Executing all test scripts..."
102+
@printf "$(COLOR_BLUE)$(SYM_ARROW) Executing all test scripts...$(COLOR_RESET)\n"
88103
@for test_script in $(SRC_PATH)/tests/*.php; do \
89-
echo "Running $$(basename $$test_script)..."; \
90-
docker exec $(CONTAINER_NAME) php $(CONTAINER_SRC_PATH)/tests/$$(basename $$test_script) || echo "Test $$(basename $$test_script) failed"; \
104+
printf "$(COLOR_BLUE)$(SYM_ARROW) Running $$(basename $$test_script)...$(COLOR_RESET)\n"; \
105+
docker exec $(CONTAINER_NAME) php $(CONTAINER_SRC_PATH)/tests/$$(basename $$test_script) && \
106+
printf "$(COLOR_GREEN)$(SYM_SUCCESS) Test $$(basename $$test_script) passed$(COLOR_RESET)\n" || \
107+
{ printf "$(COLOR_RED)$(SYM_ERROR) Test $$(basename $$test_script) failed$(COLOR_RESET)\n"; exit 1; }; \
91108
done
92-
@echo "Stopping and removing Docker container..."
93-
@docker rm -f $(CONTAINER_NAME)
94-
@echo "All tests completed."
109+
@$(MAKE) clean
110+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) All tests completed successfully$(COLOR_RESET)\n"
95111

96112
# Run the validation tests (build and run-all-tests)
97113
test: build run-all-tests
98-
@echo "Validation tests completed."
114+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Validation tests completed successfully$(COLOR_RESET)\n"
99115

100116
# Development pipeline (build and test)
101117
dev-pipeline: build test
102-
@echo "Development pipeline completed successfully."
118+
@printf "$(COLOR_GREEN)$(SYM_SUCCESS) Development pipeline completed successfully$(COLOR_RESET)\n"

Makefile.variables

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Colors for better visibility
2+
COLOR_RESET=\033[0m
3+
COLOR_BLUE=\033[34m
4+
COLOR_GREEN=\033[32m
5+
COLOR_RED=\033[31m
6+
COLOR_YELLOW=\033[33m
7+
8+
# Symbols
9+
SYM_ARROW=➜
10+
SYM_SUCCESS=✔
11+
SYM_ERROR=✖
12+
SYM_WARNING=⚠
13+
114
# Image and Container Configuration
215
DOCKER_IMAGE := usabilitydynamics/udx-worker-php:latest
316
CONTAINER_NAME := udx-worker-php-container
@@ -28,3 +41,6 @@ TESTS_PATH := $(CONTAINER_SRC_PATH)/tests
2841

2942
# Parallelism for running tests
3043
TEST_PARALLELISM := 4
44+
45+
# Additional flags
46+
FOLLOW_LOGS ?= false

0 commit comments

Comments
 (0)