forked from bstocker/Image_to_Cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
35 lines (26 loc) · 1.3 KB
/
makefile
File metadata and controls
35 lines (26 loc) · 1.3 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
# Variables
CLUSTER_NAME=lab
IMAGE_NAME=my-custom-nginx
IMAGE_TAG=v1
PYTHON_PATH=$(shell which python3)
.PHONY: help install cluster build deploy all clean
help: ## Affiche cette aide
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
install: ## Installe les dépendances nécessaires (Packer, Ansible, Librairies Python)
sudo apt-get update && sudo apt-get install packer ansible -y
sudo pip3 install kubernetes
ansible-galaxy collection install kubernetes.core
cluster: ## Crée le cluster K3d (Séquence 2)
k3d cluster create $(CLUSTER_NAME) --servers 1 --agents 2 || echo "Le cluster existe déjà"
build: ## Construit l'image avec Packer et l'importe dans K3d
packer init .
packer build nginx.pkr.hcl
k3d image import $(IMAGE_NAME):$(IMAGE_TAG) -c $(CLUSTER_NAME)
deploy: ## Déploie l'application via Ansible
ansible-playbook deploy.yml -e "ansible_python_interpreter=$(PYTHON_PATH)"
all: install cluster build deploy ## Exécute toute la chaîne de bout en bout
port-forward: ## Lance l'accès à l'application sur le port 8081
@echo "Lien disponible dans l'onglet PORTS (8081)"
kubectl port-forward svc/my-nginx-service 8081:80
clean: ## Supprime le cluster et les ressources
k3d cluster delete $(CLUSTER_NAME)