-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
106 lines (76 loc) · 2.4 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
.PHONY: push \
rollout rollout-prod rollout-staging \
imagestream-tag \
deploy deploy-prod deploy-staging \
rm-deploy \
docker docker-build docker-push
MAKE ?= make
APP ?= chat-bot-api
DOCKER_TAG ?= kscout/${APP}:${ENV}-latest
KUBE_LABELS ?= app=${APP},env=${ENV}
KUBE_TYPES ?= dc,configmap,secret,deploy,statefulset,svc,route,is,pod,pv,pvc
KUBE_APPLY ?= oc apply -f -
#push local code to ENV deploy
push: docker imagestream-tag
# rollout ENV
rollout:
@if [ -z "${ENV}" ]; then echo "ENV must be set"; exit 1; fi
oc rollout latest dc/${ENV}-${APP}
# rollout production
rollout-prod:
${MAKE} rollout ENV=prod
# rollout staging
rollout-staging:
${MAKE} rollout ENV=staging
# import latest tag for ENV to imagestream
imagestream-tag:
@if [ -z "${ENV}" ]; then echo "ENV must be set"; exit 1; fi
oc tag docker.io/kscout/${APP}:${ENV}-latest ${ENV}-${APP}:${ENV}-latest --scheduled
# deploy to ENV
deploy:
@if [ -z "${ENV}" ]; then echo "ENV must be set"; exit 1; fi
helm template \
--values deploy/values.yaml \
--values deploy/values.secrets.${ENV}.yaml \
--set global.env=${ENV} deploy \
| ${KUBE_APPLY}
# deploy to production
deploy-prod:
${MAKE} deploy ENV=prod
# deploy to staging
deploy-staging:
${MAKE} deploy ENV=staging
# remove deployment for ENV
rm-deploy:
@if [ -z "${ENV}" ]; then echo "ENV must be set"; exit 1; fi
@echo "Remove ${ENV} ${APP} deployment"
@echo "Hit any key to confirm"
@read confirm
oc get -l ${KUBE_LABELS} ${KUBE_TYPES} -o yaml | oc delete -f -
# build and push docker image
docker: docker-build docker-push
# build docker image for ENV
docker-build:
@if [ -z "${ENV}" ]; then echo "ENV must be set"; exit 1; fi
docker build -t ${DOCKER_TAG} .
# push docker image for ENV
docker-push:
@if [ -z "${ENV}" ]; then echo "ENV must be set"; exit 1; fi
docker push ${DOCKER_TAG}
DB_DATA_DIR ?= container-data/db
DB_CONTAINER_NAME ?= prod-kscout-bot-api-db
DB_USER ?= prod-kscout-bot-api
DB_PASSWORD ?= secretpassword
# Start MongoDB server in container
# Pulls docker image for latest mongo build and runs the container
db:
mkdir -p ${DB_DATA_DIR}
docker run \
-it --rm --net host --name ${DB_CONTAINER_NAME} \
-v ${PWD}/${DB_DATA_DIR}:/data/db \
-e MONGO_INITDB_ROOT_USERNAME=${DB_USER} \
-e MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} \
mongo:latest
# Runs mongo on shell
db-cli:
docker run -it --rm --net host mongo:latest mongo -u ${DB_USER} -p ${DB_PASSWORD}