-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (119 loc) · 4.91 KB
/
Copy pathMakefile
File metadata and controls
145 lines (119 loc) · 4.91 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
# These can be overridden with env vars.
REGISTRY ?= cluster-registry:5000
IMAGE_NAME ?= petshop
IMAGE_TAG ?= 1.0
IMAGE ?= $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
PLATFORM ?= "linux/amd64,linux/arm64"
CLUSTER ?= nyu-devops
.SILENT:
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: all
all: help
##@ Development
.PHONY: clean
clean: ## Removes all dangling build cache
$(info Removing all dangling build cache..)
-docker rmi $(IMAGE)
docker image prune -f
docker buildx prune -f
.PHONY: install
install: ## Install Python dependencies
$(info Installing dependencies...)
sudo pipenv install --system --dev
.PHONY: lint
lint: ## Run the linter
$(info Running linting...)
-flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics
-flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
-pylint service tests --max-line-length=127
.PHONY: test
test: ## Run the unit tests
$(info Running tests...)
export RETRY_COUNT=1; pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
.PHONY: run
run: ## Run the service
$(info Starting service...)
honcho start
.PHONY: secret
secret: ## Generate a secret hex key
$(info Generating a new secret key...)
python3 -c 'import secrets; print(secrets.token_hex())'
##@ Kubernetes
.PHONY: cluster
cluster: ## Create or reuse a K3D Kubernetes cluster with 2 worker nodes
@if k3d cluster list | awk 'NR > 1 {print $$1}' | grep -Fxq '$(CLUSTER)'; then \
echo "Kubernetes cluster $(CLUSTER) already exists; reusing it..."; \
else \
echo "Creating Kubernetes cluster $(CLUSTER) with 2 worker nodes..."; \
k3d cluster create $(CLUSTER) --agents 2 --registry-create cluster-registry:0.0.0.0:5000 --port '8080:80@loadbalancer'; \
fi
@mkdir -p $(HOME)/.kube
@k3d kubeconfig get $(CLUSTER) > $(HOME)/.kube/config
@echo "kubectl context configured for cluster $(CLUSTER)"
.PHONY: cluster-rm
cluster-rm: ## Remove a K3D Kubernetes cluster
$(info Removing Kubernetes cluster...)
k3d cluster delete $(CLUSTER)
.PHONY: tekton
tekton: ## Install Tekton
$(info Installing Tekton in the Cluster...)
kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml
kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/latest/tekton-dashboard-release.yaml
.PHONY: tekton-clean
tekton-clean: ## Clean up all PipelineRuns and TaskRuns
$(info Cleaning up all PipelineRuns and TaskRuns...)
tkn taskrun ls
tkn taskrun rm --all -f
tkn pipelinerun ls
tkn pipelinerun rm --all -f
.PHONY: knative
knative: ## Install Knative
$(info Installing Knative in the Cluster...)
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-core.yaml
# kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.12.0/eventing-crds.yaml
# kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.12.0/eventing-core.yaml
.PHONY: import
import: ## Import the image into the local K3D cluster
$(info Importing $(IMAGE) into k3d cluster $(CLUSTER)...)
k3d image import --cluster $(CLUSTER) $(IMAGE)
.PHONY: postgresql
postgresql: ## Deploys the PostgreSQL database on local Kubernetes
$(info Deploying PostgreSQL locally...)
oc apply -f k8s/postgresql
.PHONY: deploy
deploy: ## Deploy the service on local Kubernetes
$(info Deploying service locally...)
oc apply -f k8s/
oc rollout status deployment/petshop
############################################################
# COMMANDS FOR BUILDING THE IMAGE
############################################################
##@ Image Build and Push
.PHONY: init
init: export DOCKER_BUILDKIT=1
init: ## Creates the buildx instance
$(info Initializing Builder...)
-docker buildx create --use --name=qemu
docker buildx inspect --bootstrap
.PHONY: build
build: ## Build the project container image for local platform
$(info Building $(IMAGE)...)
docker build --rm --pull --tag $(IMAGE) .
.PHONY: push
push: ## Push the image to the container registry
$(info Pushing $(IMAGE)...)
docker push $(IMAGE)
.PHONY: buildx
buildx: ## Build multi-platform image with buildx
$(info Building multi-platform image $(IMAGE) for $(PLATFORM)...)
docker buildx build --file Dockerfile --pull --platform=$(PLATFORM) --tag $(IMAGE) --push .
.PHONY: remove
remove: ## Stop and remove the buildx builder
$(info Stopping and removing the builder image...)
docker buildx stop
docker buildx rm