Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
160 lines (139 loc) · 7 KB
/
Copy pathMakefile
File metadata and controls
160 lines (139 loc) · 7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# ==============================================================================
# TweakPHP E2E Testing Environment - Makefile
# ==============================================================================
.DEFAULT_GOAL := help
SHELL := /bin/bash
# Detect docker compose implementation (V2 plugin vs V1 standalone)
DOCKER_COMPOSE := $(shell if docker compose version >/dev/null 2>&1; then echo "docker compose"; else echo "docker-compose"; fi)
# Colors for terminal output
BOLD := \033[1m
CYAN := \033[36m
GREEN := \033[32m
YELLOW := \033[33m
RESET := \033[0m
.PHONY: help up start down stop restart setup clean purge status ps logs info connections shell-docker shell-sail shell-ssh shell-k8s
## Show helper documentation
help:
@printf "\n$(BOLD)$(YELLOW)==============================================================================$(RESET)\n"
@printf " $(BOLD)🚀 TweakPHP E2E Testing Environment$(RESET)\n"
@printf "$(BOLD)$(YELLOW)==============================================================================$(RESET)\n\n"
@printf "$(BOLD)Usage:$(RESET) make [target]\n\n"
@printf "$(BOLD)$(YELLOW)Environment Lifecycle:$(RESET)\n"
@printf " $(CYAN)%-18s$(RESET) Start environment (Docker & K8s) and show credentials\n" "up, start"
@printf " $(CYAN)%-18s$(RESET) Stop services safely (preserves apps/ for instant restart)\n" "down, stop"
@printf " $(CYAN)%-18s$(RESET) Restart running Docker containers\n" "restart"
@printf " $(CYAN)%-18s$(RESET) Build containers & provision Laravel apps from scratch\n" "setup"
@printf " $(CYAN)%-18s$(RESET) Full teardown: stop services and wipe apps/ directory\n" "clean, purge"
@printf "\n"
@printf "$(BOLD)$(YELLOW)Inspection & Logs:$(RESET)\n"
@printf " $(CYAN)%-18s$(RESET) Show status of Docker containers and Kubernetes pods\n" "status, ps"
@printf " $(CYAN)%-18s$(RESET) Display TweakPHP connection credentials & parameters\n" "info, connections"
@printf " $(CYAN)%-18s$(RESET) Follow Docker logs (optional filter: s=docker-laravel)\n" "logs"
@printf "\n"
@printf "$(BOLD)$(YELLOW)Interactive Shells:$(RESET)\n"
@printf " $(CYAN)%-18s$(RESET) Open bash shell inside tweakphp-docker-app\n" "shell-docker"
@printf " $(CYAN)%-18s$(RESET) Open bash shell inside tweakphp-sail-app\n" "shell-sail"
@printf " $(CYAN)%-18s$(RESET) Open bash shell inside tweakphp-ssh-app\n" "shell-ssh"
@printf " $(CYAN)%-18s$(RESET) Open bash shell inside Kubernetes Laravel pod\n" "shell-k8s"
@printf "\n$(BOLD)$(YELLOW)==============================================================================$(RESET)\n\n"
# Lifecycle commands
up: start
start:
@bash ./start.sh
down: stop
stop:
@CLEAN_APPS=false bash ./stop.sh
restart:
@echo "--> Restarting Docker Compose services..."
@$(DOCKER_COMPOSE) restart
@echo "--> Containers restarted."
setup:
@bash ./setup.sh
clean: purge
purge:
@CLEAN_APPS=true bash ./stop.sh
# Inspection commands
status: ps
ps:
@echo "================ Docker Containers ================"
@$(DOCKER_COMPOSE) ps
@if command -v kubectl >/dev/null 2>&1 && kubectl cluster-info >/dev/null 2>&1; then \
echo ""; \
echo "================ Kubernetes Pods ==================="; \
kubectl get pods -n tweakphp-test -o wide 2>/dev/null || echo "Namespace tweakphp-test not active"; \
fi
logs:
@$(DOCKER_COMPOSE) logs -f $(s)
info: connections
connections:
@echo "============================================================"
@echo " 📋 TWEAKPHP CONNECTION PARAMETERS"
@echo "============================================================"
@if command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1; then \
DOCKER_ID=$$(docker inspect -f '{{.Id}}' tweakphp-docker-app 2>/dev/null | cut -c1-12); \
SAIL_ID=$$(docker inspect -f '{{.Id}}' tweakphp-sail-app 2>/dev/null | cut -c1-12); \
SSH_ID=$$(docker inspect -f '{{.Id}}' tweakphp-ssh-app 2>/dev/null | cut -c1-12); \
echo ""; \
echo "🐳 [1] DOCKER CONNECTION"; \
echo "------------------------------------------------------------"; \
echo " • Connection Type: Docker"; \
echo " • Connection Name: Docker E2E Test"; \
echo " • Container Name: tweakphp-docker-app"; \
echo " • Container ID: $${DOCKER_ID:-tweakphp-docker-app}"; \
echo " • Working Directory: /var/www/html"; \
echo " • PHP Path: php"; \
echo ""; \
echo "⛵ [2] LARAVEL SAIL CONNECTION"; \
echo "------------------------------------------------------------"; \
echo " • Connection Type: Docker"; \
echo " • Connection Name: Sail E2E Test"; \
echo " • Container Name: tweakphp-sail-app"; \
echo " • Container ID: $${SAIL_ID:-tweakphp-sail-app}"; \
echo " • Working Directory: /var/www/html"; \
echo " • PHP Path: php"; \
echo ""; \
echo "🔑 [3] SSH CONNECTION"; \
echo "------------------------------------------------------------"; \
echo " • Connection Type: SSH"; \
echo " • Connection Name: SSH E2E Test"; \
echo " • Host: 127.0.0.1 (or localhost)"; \
echo " • Port: 2222"; \
echo " • Username: tweakphp"; \
echo " • Auth Type: password"; \
echo " • Password: secret123"; \
echo " • Path / WorkingDir: /var/www/html"; \
echo " • PHP Path: php"; \
else \
echo " [!] Docker is not running or not available."; \
fi
@if command -v kubectl >/dev/null 2>&1 && kubectl cluster-info >/dev/null 2>&1; then \
K8S_POD=$$(kubectl get pods -n tweakphp-test -l app=tweakphp-k8s-laravel --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}' 2>/dev/null); \
[ -z "$$K8S_POD" ] && K8S_POD=$$(kubectl get pods -n tweakphp-test -l app=tweakphp-k8s-laravel -o jsonpath='{.items[0].metadata.name}' 2>/dev/null); \
K8S_CONTEXT=$$(kubectl config current-context 2>/dev/null || echo "default"); \
echo ""; \
echo "☸️ [4] KUBERNETES (KUBECTL) CONNECTION"; \
echo "------------------------------------------------------------"; \
echo " • Connection Type: Kubectl"; \
echo " • Connection Name: Kubernetes E2E Test"; \
echo " • Context: $$K8S_CONTEXT"; \
echo " • Namespace: tweakphp-test"; \
echo " • Pod Name: $${K8S_POD:-tweakphp-k8s-laravel-xxxx}"; \
echo " • Path / WorkingDir: /var/www/html"; \
echo " • PHP Path: php"; \
fi
@echo "============================================================"
# Shell access helpers
shell-docker:
@docker exec -it tweakphp-docker-app bash
shell-sail:
@docker exec -it tweakphp-sail-app bash
shell-ssh:
@docker exec -it tweakphp-ssh-app bash
shell-k8s:
@POD=$$(kubectl get pods -n tweakphp-test -l app=tweakphp-k8s-laravel --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}' 2>/dev/null); \
[ -z "$$POD" ] && POD=$$(kubectl get pods -n tweakphp-test -l app=tweakphp-k8s-laravel -o jsonpath='{.items[0].metadata.name}' 2>/dev/null); \
if [ -n "$$POD" ]; then \
kubectl exec -it "$$POD" -n tweakphp-test -- bash; \
else \
echo "No running Kubernetes pod found in tweakphp-test namespace."; \
fi