-
Notifications
You must be signed in to change notification settings - Fork 3
/
makefile
98 lines (80 loc) · 2.87 KB
/
makefile
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
# Makefile for KubeLearn project
help:
@echo "Makefile Help"
@echo ""
@echo "Targets:"
@echo " all Installs all YAML manifests."
@echo " clean Deletes all installed resources."
@echo " check-syntax Checks the syntax of all manifests without actually installing them."
@echo " init Initializes the Terraform repository."
@echo " apply Applies Terraform configurations."
@echo " destroy Destroys Terraform resources."
@echo " Kubelearn Sets up and runs both backend and frontend."
@echo " stopKubelearn Stops both backend and frontend."
@echo ""
@echo "Usage:"
@echo " make all"
@echo " make clean"
@echo " make check-syntax"
@echo " make init"
@echo " make apply"
@echo " make destroy"
@echo " make Kubelearn"
@echo " make stopKubelearn"
# Directory where the YAML manifests are located
MANIFESTS_DIR := manifests
# Command to install the manifests
INSTALL_COMMAND := kubectl apply -f
# List all YAML files in the manifests folder
YAML_FILES := $(wildcard $(MANIFESTS_DIR)/*.yaml)
# Get only the file names (without the directory path)
BASE_NAMES := $(notdir $(YAML_FILES))
# Add a prefix for the install target
TARGETS := $(addprefix install-,$(BASE_NAMES))
# Default rule to install all manifests
all: $(TARGETS)
# Rules to install each individual manifest
$(TARGETS): install-%: $(MANIFESTS_DIR)/%
$(INSTALL_COMMAND) $<
# Rule to clean up all installed resources
clean:
kubectl delete -f $(MANIFESTS_DIR)
# Rule to check syntax of all manifests without actually installing them
check-syntax:
for file in $(YAML_FILES); do \
kubectl apply --dry-run=client -f $$file; \
done
# Directory where the Terraform code is
TERRAFORM_DIR := config
# Commands
TERRAFORM := terraform
TERRAFORM_CMD := $(TERRAFORM) -chdir=$(TERRAFORM_DIR)
TERRAFORM_INIT := $(TERRAFORM_CMD) init
TERRAFORM_APPLY := $(TERRAFORM_CMD) apply -auto-approve
TERRAFORM_DESTROY := $(TERRAFORM_CMD) destroy -auto-approve
# Targets
.PHONY: init apply destroy init-upgrade
# Rules
init: ## Initialize Terraform repository
@echo "Initializing Terraform..."
$(TERRAFORM_INIT)
apply: ## Apply Terraform configurations
@echo "Applying Terraform configurations..."
$(TERRAFORM_APPLY)
destroy: ## Destroy Terraform resources
@echo "Destroying Terraform resources..."
$(TERRAFORM_DESTROY)
# Initializes Terraform and sets up the backend and frontend
Kubelearn:
@echo "Setting up the environment..."
@$(TERRAFORM_INIT)
@$(TERRAFORM_APPLY)
@echo "Setting up and starting the backend..."
@cd cmd && go build -o kubelearn && nohup ./kubelearn > backend.log 2>&1 &
@echo "Setting up and starting the frontend..."
@cd kubelearn-frontend && npm install && nohup npm start > frontend.log 2>&1 &
# Stops the backend and frontend
stopKubelearn:
@echo "Stopping the backend and frontend..."
@pkill -f kubelearn || true
@pkill -f "npm start" || true