Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (137 loc) · 5.57 KB
/
Copy pathMakefile
File metadata and controls
153 lines (137 loc) · 5.57 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
KREW=./krew-"`uname | tr '[:upper:]' '[:lower:]'`_amd64"
BATS := $(shell command -v bats 2> /dev/null)
.PHONY: check-bats
check-bats: ## Check if bats is installed
ifndef BATS
$(error "bats-core not found. Please install it (e.g., 'sudo apt install bats' or 'npm install -g bats')")
endif
.PHONY: health
health: check-bats ## Run environment health checks
COLUMNS=80 LINES=24 bats tests/health_check.bats
.PHONY: init
init: ## Auto-detect environment and initialize dotfiles via chezmoi
@echo "Detected OS: $$(uname -s)"
@if [ "$$(uname -s)" = "Darwin" ]; then \
echo "Setting up macOS environment..."; \
if ! command -v brew >/dev/null 2>&1; then \
echo "Installing Homebrew..."; \
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"; \
fi; \
echo "Looking for chezmoi..."; \
if ! command -v chezmoi >/dev/null 2>&1; then \
echo "Installing chezmoi..."; \
brew install chezmoi; \
fi; \
chezmoi init --apply --source "$(PWD)"; \
elif [ "$$(uname -s)" = "Linux" ]; then \
echo "Setting up Linux environment..."; \
if ! command -v chezmoi >/dev/null 2>&1 && [ ! -x "$(HOME)/bin/chezmoi" ] && [ ! -x "./bin/chezmoi" ]; then \
echo "Installing chezmoi..."; \
curl -fsLS https://get.chezmoi.io | sh -s -- -b "$(HOME)/bin"; \
[ -f "$(HOME)/bin/chezmoi" ] && chmod +x "$(HOME)/bin/chezmoi"; \
fi; \
if [ -x "$(HOME)/bin/chezmoi" ]; then \
"$(HOME)/bin/chezmoi" init --apply --source "$(PWD)"; \
elif [ -x "./bin/chezmoi" ]; then \
"./bin/chezmoi" init --apply --source "$(PWD)"; \
elif command -v chezmoi >/dev/null 2>&1; then \
chezmoi init --apply --source "$(PWD)"; \
else \
echo "Error: chezmoi not found or not executable after install"; exit 1; \
fi; \
else \
echo "Unsupported OS: $$(uname -s)"; exit 1; \
fi
.PHONY: update
update: ## Sync current directory changes to dotfiles via chezmoi
chezmoi apply --source "$(PWD)"
.PHONY: clean
clean: ## Remove files managed by chezmoi and clean up third-party directories
@echo "Looking for chezmoi binary..."
@if command -v chezmoi >/dev/null 2>&1; then \
CHEZMOI_BIN=$$(command -v chezmoi); \
elif [ -f "$(HOME)/bin/chezmoi" ]; then \
CHEZMOI_BIN="$(HOME)/bin/chezmoi"; \
else \
echo "chezmoi not installed, nothing to clean."; exit 0; \
fi; \
echo "Removing chezmoi managed files in $(HOME)..."; \
if $$CHEZMOI_BIN source-path >/dev/null 2>&1; then \
$$CHEZMOI_BIN managed -i files | while read -r file; do \
target="$(HOME)/$$file"; \
if [ -f "$$target" ] || [ -L "$$target" ]; then \
echo "Removing $$target"; \
rm -f "$$target"; \
fi; \
done; \
$$CHEZMOI_BIN managed -i scripts | while read -r script; do \
target="$(HOME)/$$script"; \
if [ -f "$$target" ] || [ -L "$$target" ]; then \
echo "Removing $$target"; \
rm -f "$$target"; \
fi; \
done; \
else \
echo "Chezmoi state not found or initialized."; \
fi
@echo "Cleaning up third-party tool directories..."
rm -rf "$(HOME)/.zprezto" "$(HOME)/.tmux" "$(HOME)/.asdf"
@echo "Cleanup completed."
.PHONY: krew
krew: ## 配置 Kubernetes kubectl 外掛管理器
set -x; cd "$$(mktemp -d)" && \
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.{tar.gz,yaml}" && \
tar zxvf krew.tar.gz && \
"$$(KREW)" install --manifest=krew.yaml --archive=krew.tar.gz && \
"$$(KREW)" update
kubectl krew install access-matrix
kubectl krew install cssh
kubectl krew install pod-logs
kubectl krew install pod-shell
kubectl krew install rbac-lookup
kubectl krew install rbac-view
kubectl krew install trace
kubectl krew install view-secret
kubectl krew install view-utilization
kubectl krew install warp
.PHONY: helm
helm: ## 配置 kubernetes helm
asdf plugin add helm && asdf install helm latest
helm plugin install https://github.com/technosophos/helm-template
helm plugin install https://github.com/maorfr/helm-backup
helm plugin install https://github.com/maorfr/helm-restore
helm plugin install https://github.com/maorfr/helm-inject
helm plugin install https://github.com/maorfr/helm-logs
helm plugin install https://github.com/mstrzele/helm-edit
helm plugin install https://github.com/adamreese/helm-env
helm plugin install https://github.com/adamreese/helm-last
helm plugin install https://github.com/ContainerSolutions/helm-monitor
helm plugin install https://github.com/databus23/helm-diff
helm plugin install https://github.com/futuresimple/helm-secrets
.PHONY: iterm
iterm: ## 配置 iTerm
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
curl -L https://iterm2.com/utilities/imgcat -o /usr/local/bin/imgcat
curl -L https://iterm2.com/utilities/imgls -o /usr/local/bin/imgls
chmod a+x /usr/local/bin/*
.PHONY: test
test: test-macos test-linux ## Run all simulation tests
.PHONY: test-linux
test-linux: ## Test Linux template rendering
@bash ./tests/run_test.sh linux
.PHONY: test-macos
test-macos: ## Test macOS template rendering
@bash ./tests/run_test.sh darwin
.PHONY: bundle-offline
bundle-offline: ## Generate an offline installation bundle for Ubuntu
mkdir -p dist/
docker build -t xprofile-bundler -f docker/ubuntu/Dockerfile.bundle .
docker run --rm -v "$(PWD)/dist:/output" xprofile-bundler sh -c "tar -czf /output/xProfile-offline.tar.gz -C /offline ."
.PHONY: clean-offline
clean-offline: ## Remove generated offline bundles
rm -rf dist/
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help