-
Notifications
You must be signed in to change notification settings - Fork 614
/
Makefile
109 lines (89 loc) · 3.27 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
99
100
101
102
103
104
105
106
107
108
109
# These can be overidden with env vars.
REGISTRY ?= us.icr.io
NAMESPACE ?= nyu-devops
IMAGE_NAME ?= lab-bluemix-cf
IMAGE_TAG ?= 1.0
IMAGE ?= $(REGISTRY)/$(NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
# PLATFORM ?= "linux/amd64,linux/arm64"
PLATFORM ?= "linux/amd64"
CLUSTER ?= nyu-devops
SPACE ?= dev
.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: venv
venv: ## Create a Python virtual environment
$(info Creating Python 3 virtual environment...)
python3 -m venv .venv
.PHONY: install
install: ## Install dependencies
$(info Installing dependencies...)
sudo pip install -r requirements.txt
.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...)
green -vvv --processes=1 --run-coverage --termcolor --minimum-coverage=95
.PHONY: run
run: ## Run the service
$(info Starting service...)
honcho start
.PHONY: namespace
namespace: ## Create the namespace assigned to the SPACE env variable
$(info Creatng the $(SPACE) namespace...)
kubectl create namespace $(SPACE)
kubectl get secret all-icr-io -n default -o yaml | sed 's/default/$(SPACE)/g' | kubectl create -n $(SPACE) -f -
kubectl config set-context --current --namespace $(SPACE)
############################################################
# COMMANDS FOR DEPLOYING THE IMAGE
############################################################
##@ Deployment
.PHONY: login
login: ## Login to IBM Cloud using yur api key
$(info Logging into IBM Cloud cluster $(CLUSTER)...)
ibmcloud login -a cloud.ibm.com -g Default -r us-south --apikey @~/.bluemix/apikey.json
ibmcloud cr login
ibmcloud ks cluster config --cluster $(CLUSTER)
kubectl cluster-info
.PHONY: push
image-push: ## Push to a Docker image registry
$(info Logging into IBM Cloud cluster $(CLUSTER)...)
ibmcloud cr login
docker push $(IMAGE)
.PHONY: deploy
deploy: ## Deploy the service on local Kubernetes
$(info Deploying service locally...)
kubectl apply -f deploy/
############################################################
# COMMANDS FOR BUILDING THE IMAGE
############################################################
##@ Docker Build
.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 all of the project Docker images
$(info Building $(IMAGE) for $(PLATFORM)...)
docker buildx build --file Dockerfile --pull --platform=$(PLATFORM) --tag $(IMAGE) --load .
.PHONY: remove
remove: ## Stop and remove the buildx builder
$(info Stopping and removing the builder image...)
docker buildx stop
docker buildx rm