Merge lp:~ricardokirkner/isitdeployable/generic-deployment-infra into lp:isitdeployable

Proposed by Ricardo Kirkner
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: 270
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~ricardokirkner/isitdeployable/generic-deployment-infra
Merge into: lp:isitdeployable
Diff against target: 244 lines (+12/-196)
3 files modified
.bzrignore (+1/-0)
deployment/Makefile (+5/-152)
deployment/README (+6/-44)
To merge this branch: bzr merge lp:~ricardokirkner/isitdeployable/generic-deployment-infra
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+333804@code.launchpad.net

Commit message

rely on generic Makefile from ols-k8s project

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

I like red!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2017-11-10 16:19:27 +0000
+++ .bzrignore 2017-11-16 11:28:00 +0000
@@ -1,4 +1,5 @@
1branches/*1branches/*
2deployment/ols-k8s
2deployment/secrets.yaml3deployment/secrets.yaml
3deployment/tmp/*4deployment/tmp/*
4test.db5test.db
56
=== modified file 'deployment/Makefile'
--- deployment/Makefile 2017-11-15 15:42:19 +0000
+++ deployment/Makefile 2017-11-16 11:28:00 +0000
@@ -1,122 +1,17 @@
1IMAGE_NAME ?= isitdeployable1IMAGE_NAME ?= isitdeployable
22
3# include generic Makefile
4include ols-k8s/Makefile
5
3# pre-process arguments6# pre-process arguments
4# if the first argument is "special" (logs, describe, shell, bzr-check-lock, bzr-break-lock)...7# if the first argument is "special" (bzr-check-lock, bzr-break-lock)...
5ifneq (,$(filter $(firstword $(MAKECMDGOALS)),logs describe shell bzr-check-lock bzr-break-lock))8ifneq (,$(filter $(firstword $(MAKECMDGOALS)),bzr-check-lock bzr-break-lock))
6# use the rest as sub-arguments9# use the rest as sub-arguments
7ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))10ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
8# ...and turn them into do-nothing targets11# ...and turn them into do-nothing targets
9$(eval $(ARGS):;@:)12$(eval $(ARGS):;@:)
10endif13endif
1114
12.DEFAULT_GOAL := status
13
14.PHONY: help
15help:
16 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
17 | cut -d ':' -f 2,3 \
18 | sort \
19 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
20
21.PHONY: status
22status: ## Show cluster status info
23 @$(check-env-vars)
24 @kubectl cluster-info | grep 'Kubernetes master'
25 kubectl -n $(NAMESPACE) get -L revision po,rs,deploy,svc,cm,secrets,ingress
26
27.PHONY: namespace
28namespace: tmp/namespace.yaml ## Create namespace
29 @$(check-env-vars)
30 kubectl apply -f tmp/namespace.yaml --record
31 kubectl get secret registry-access -o yaml | sed 's/default/$(NAMESPACE)/g' | kubectl -n $(NAMESPACE) apply -f - --record
32
33.PHONY: deploy
34deploy: render-config ## Deploy stack (from scratch)
35 @$(check-env-vars)
36 @$(check-image-vars)
37 kubectl apply --record \
38 -f tmp/configmaps.yaml \
39 -f secrets.yaml \
40 -f tmp/services.yaml \
41 -f tmp/ingress.yaml
42 $(MAKE) migrate-db
43 kubectl apply --record -f tmp/deployments.yaml
44 kubectl -n $(NAMESPACE) rollout status deployment/app
45 $(MAKE) clean-migrate-db
46
47.PHONY: update-deploy
48update-deploy: FILENAME ?= tmp/deployments.yaml
49update-deploy: render-config ## Update deployment
50 @$(check-env-vars)
51 @$(check-image-vars)
52 kubectl replace -f $(FILENAME) --record
53 kubectl -n $(NAMESPACE) rollout status deployment/app
54
55.PHONY: update-config
56update-config: tmp/configmaps.yaml ## Update config options
57 @$(check-env-vars)
58 kubectl replace -f tmp/configmaps.yaml --record
59
60.PHONY: update-secrets
61update-secrets: ## Update secrets
62 @$(check-env-vars)
63 kubectl replace -f secrets.yaml --record
64
65.PHONY: update-code
66update-code: ## Update image only
67 @$(check-env-vars)
68 @$(check-image-vars)
69 kubectl -n $(NAMESPACE) set image deployment/app app=$(DOCKER_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) worker=$(DOCKER_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) --record
70 kubectl -n $(NAMESPACE) rollout status deployment/app
71
72.PHONY: migrate-db
73migrate-db: tmp/migrate-db-job.yaml ## Run schema migrations
74 @$(check-env-vars)
75 kubectl apply -f tmp/migrate-db-job.yaml --record
76 until kubectl -n $(NAMESPACE) get jobs migrate-db -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep True ; do sleep 1 ; done
77
78.PHONY: clean-migrate-db
79clean-migrate-db: tmp/migrate-db-job.yaml ## Remove job for schema migrations
80 @$(check-env-vars)
81 kubectl delete -f tmp/migrate-db-job.yaml
82
83.PHONY: release
84release: ## Cut a new release
85 @$(check-env-vars)
86 @$(check-image-vars)
87 $(MAKE) clean-config
88 $(MAKE) render-config
89 $(MAKE) migrate-db
90 $(MAKE) update-deploy
91 $(MAKE) clean-migrate-db
92
93.PHONY: rollback
94rollback: ## Undo latest release
95 @$(check-env-vars)
96 kubectl -n $(NAMESPACE) rollout undo deploy/app
97
98.PHONY: logs
99logs: ## Show logs
100 @$(check-env-vars)
101 kubectl -n $(NAMESPACE) logs $(ARGS)
102
103.PHONY: describe
104describe: ## Describe pod
105 @$(check-env-vars)
106 kubectl -n $(NAMESPACE) describe $(ARGS)
107
108.PHONY: shell
109shell: ## Open a shell
110 @$(check-env-vars)
111 kubectl -n $(NAMESPACE) exec -it $(ARGS) bash
112
113.PHONY: render-config
114render-config: $(shell find config -name '*.yaml.tpl' -printf 'tmp/%f\n' | sed -e 's/.tpl//g') ## Render config from templates
115
116.PHONY: clean-config
117clean-config: ## Delete rendered config files
118 rm -f tmp/*.yaml
119
120.PHONY: bzr-check-lock15.PHONY: bzr-check-lock
121bzr-check-lock: ## Check for bzr locks held in place16bzr-check-lock: ## Check for bzr locks held in place
122 @$(check-env-vars)17 @$(check-env-vars)
@@ -130,47 +25,5 @@
130 @$(check-env-vars)25 @$(check-env-vars)
131 kubectl -n $(NAMESPACE) exec -it $(ARGS) -c worker bash -- -c 'for branch in `find tmp/branches -name .bzr -type d | xargs dirname`; do (cd $${branch}; bzr break-lock); done'26 kubectl -n $(NAMESPACE) exec -it $(ARGS) -c worker bash -- -c 'for branch in `find tmp/branches -name .bzr -type d | xargs dirname`; do (cd $${branch}; bzr break-lock); done'
13227
133
134# helper targets
135
136tmp/%.yaml: config/%.yaml.tpl
137 $(MAKE) render-template SRC=$< DST=$@
138
139.PHONY: render-template
140render-template:
141 @$(eval REVISION=$(shell docker inspect -f '{{.Config.Labels.revision}}' $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)))
142 @REVISION=$(REVISION) IMAGE_NAME=$(IMAGE_NAME) IMAGE_TAG=$(IMAGE_TAG) envsubst < $(SRC) > $(DST)
143
144# defines
145
146define check-env-vars
147 if test -z "$(NAMESPACE)"; then \
148 echo "NAMESPACE variable not defined; aborting."; \
149 exit 1; \
150 elif test -z "$(DOMAIN)"; then \
151 echo "DOMAIN variable not defined; aborting."; \
152 exit 1; \
153 elif test -z "$(DB_EXTERNAL_NAME)"; then \
154 echo "DB_EXTERNAL_NAME variable not defined; aborting."; \
155 exit 1; \
156 elif test -z "$(AMQP_EXTERNAL_NAME)"; then \
157 echo "AMQP_EXTERNAL_NAME variable not defined; aborting."; \
158 exit 1; \
159 fi
160endef
161
162define check-image-vars
163 if test -z "$(DOCKER_REGISTRY)"; then \
164 echo "DOCKER_REGISTRY variable not defined; aborting."; \
165 exit 1; \
166 elif test -z "$(IMAGE_NAME)"; then \
167 echo "IMAGE_NAME variable not defined; aborting."; \
168 exit 1; \
169 elif test -z "$(IMAGE_TAG)"; then \
170 echo "IMAGE_TAG variable not defined; aborting."; \
171 exit 1; \
172 fi
173endef
174
175# other makefiles28# other makefiles
176include dev.mk29include dev.mk
17730
=== modified file 'deployment/README'
--- deployment/README 2017-11-10 18:54:25 +0000
+++ deployment/README 2017-11-16 11:28:00 +0000
@@ -1,44 +1,6 @@
1= Bootstrap Kubernetes cluster1= Get started
22
3make cluster3git clone lp:ols-k8s
4make registry-proxy4
55The follow README from ols-k8s/README
6= Build image6
7
8cd .. && make k8s-build k8s-upload
9
10Take note of the tag applied to the build image. See last line of output, should be
11something along the lines of:
12
13Successfully tagged isitdeployable:trunk-<revno>
14
15Then, from now on use IMAGE_TAG=trunk-<revno>
16
17= Initial deploy
18
19source envrc
20make namespace
21make external-services (for development only)
22make secrets.yaml (for development only)
23
24Wait until the cluster is ready (check using `make status` until all pods are ready).
25Then deploy the app:
26
27make deploy IMAGE_TAG=trunk-<revno>
28
29= Code update
30
31Assuming a new revision is available and an image was built and uploaded for it:
32
33make release IMAGE_TAG=trunk-<revno>
34
35= Config / Secret update
36
37make update-config
38make update-secret
39
40= Redeploy
41
42You can easily redeploy any revision by just releasing it again:
43
44make release IMAGE_TAG=trunk-<revno>

Subscribers

People subscribed via source and target branches