Merge lp:~mthaddon/mojo/mojo-how-to-autodeploy into lp:mojo/mojo-specs

Proposed by Tom Haddon
Status: Merged
Merged at revision: 11
Proposed branch: lp:~mthaddon/mojo/mojo-how-to-autodeploy
Merge into: lp:mojo/mojo-specs
Diff against target: 301 lines (+210/-0)
16 files modified
mojo-how-to/README (+7/-0)
mojo-how-to/devel/build-desired-revno (+15/-0)
mojo-how-to/devel/build-production-revno (+25/-0)
mojo-how-to/devel/check_for_diff_production_desired_revno (+10/-0)
mojo-how-to/devel/get_common_variables (+5/-0)
mojo-how-to/devel/publish_revno (+10/-0)
mojo-how-to/devel/store_desired_revno (+9/-0)
mojo-how-to/devel/store_production_revno (+9/-0)
mojo-how-to/manifests/check-autodeploy (+11/-0)
mojo-how-to/manifests/perform-autodeploy (+15/-0)
mojo-how-to/manifests/perform-autodeploy-unchecked (+16/-0)
mojo-how-to/manifests/prepare-autodeploy (+13/-0)
mojo-how-to/manifests/test-autodeploy (+36/-0)
mojo-how-to/production/publish_revno (+10/-0)
mojo-how-to/production/store_desired_revno (+9/-0)
mojo-how-to/production/store_production_revno (+10/-0)
To merge this branch: bzr merge lp:~mthaddon/mojo/mojo-how-to-autodeploy
Reviewer Review Type Date Requested Status
Paul Collins Approve
Review via email: mp+273817@code.launchpad.net

Description of the change

Add autodeployment mechanisms for mojo-how-to. This will only address updating built content, not charm upgrades, which will need further work.

To post a comment you must log in.
12. By Tom Haddon

Pull in the desired and production build revnos from common script

13. By Tom Haddon

We need to actually build the env with current production revno on CI first as part of test-autodeploy before updating it

14. By Tom Haddon

Use the correct option to get stdout for wget

15. By Tom Haddon

We need bzr as a builddep too

16. By Tom Haddon

Arithmetic expression for comparing revnos

17. By Tom Haddon

We need to collect before running store_desired_revno on CI because that tells us what revno to start with

18. By Tom Haddon

Create dummy secrets file as part of a step that will get run for auto-deploy

19. By Tom Haddon

Print what revnos we have

20. By Tom Haddon

We need to pass the BUILD_LABEL to our upload and update script in autodeploy otherwise it'll just overwrite mojo.tar

21. By Tom Haddon

Print what revno we are publishing

22. By Tom Haddon

Also print what we're publishing in production

Revision history for this message
Tom Haddon (mthaddon) wrote :

Ok, this has been tested on https://ci.admin.canonical.com/job/autodeploy-is-mojo-dot-canonical-dot-com/ - not yet tested the actually rollout portions on production though

23. By Tom Haddon

Missing config from check-autodeploy

24. By Tom Haddon

Make sure we have the correct builddeps for performing the autodeploy

25. By Tom Haddon

We need to pass the packages variable, not config to builddeps

Revision history for this message
Tom Haddon (mthaddon) wrote :

And this has now been tested on production as well. Successfully performed the rollout, and then exited with "Production is on 206 and the desired revno is 206. Nothing to do, exiting..." when rerun.

26. By Tom Haddon

Add a comment when we've autodeployed so we can more easily look for this and report on it

Revision history for this message
Paul Collins (pjdc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mojo-how-to/README'
2--- mojo-how-to/README 2015-05-07 14:11:05 +0000
3+++ mojo-how-to/README 2015-10-12 10:20:25 +0000
4@@ -20,3 +20,10 @@
5 ksplice:
6 options:
7 access-key: $YOUR_KSPLICE_ACCESS_KEY
8+
9+
10+If you are using the autodeploy manifests, you will also need the following in
11+a secrets file called "autodeploy-secrets":
12+
13+CI_SWIFT_CONTAINER=URL_OF_SWIFT_CONTAINER
14+PROD_SWIFT_CONTAINER=URL_OF_SWIFT_CONTAINER
15
16=== added file 'mojo-how-to/devel/build-desired-revno'
17--- mojo-how-to/devel/build-desired-revno 1970-01-01 00:00:00 +0000
18+++ mojo-how-to/devel/build-desired-revno 2015-10-12 10:20:25 +0000
19@@ -0,0 +1,15 @@
20+#!/bin/bash
21+
22+# Script to generate docs from Mojo source tree
23+
24+set -e
25+set -u
26+
27+source ${MOJO_SPEC_DIR}/${MOJO_STAGE}/get_common_variables
28+
29+cd ${MOJO_BUILD_DIR}/mojo
30+
31+bzr pull -r $DESIRED_REVNO --overwrite .
32+
33+make generate-docs
34+tar cvpf ${MOJO_LOCAL_DIR}/mojo.tar --directory=docs/www .
35
36=== added file 'mojo-how-to/devel/build-production-revno'
37--- mojo-how-to/devel/build-production-revno 1970-01-01 00:00:00 +0000
38+++ mojo-how-to/devel/build-production-revno 2015-10-12 10:20:25 +0000
39@@ -0,0 +1,25 @@
40+#!/bin/bash
41+
42+# Script to generate docs from Mojo source tree
43+
44+set -e
45+set -u
46+
47+source ${MOJO_SPEC_DIR}/${MOJO_STAGE}/get_common_variables
48+
49+cd ${MOJO_BUILD_DIR}/mojo
50+
51+bzr pull -r $PRODUCTION_REVNO --overwrite .
52+
53+make generate-docs
54+tar cvpf ${MOJO_LOCAL_DIR}/mojo.tar --directory=docs/www .
55+
56+if [ ${MOJO_STAGE##*/} != "production" ]; then
57+ # We don't deploy landscape in non-production environments, but we need a
58+ # dummy secrets file
59+ echo "Creating dummy services-secret file in ${MOJO_LOCAL_DIR}"
60+ echo "mojo-how-to:
61+ services:
62+ nrpe:
63+ charm: nrpe-external-master" > ${MOJO_LOCAL_DIR}/services-secret
64+fi
65
66=== added file 'mojo-how-to/devel/check_for_diff_production_desired_revno'
67--- mojo-how-to/devel/check_for_diff_production_desired_revno 1970-01-01 00:00:00 +0000
68+++ mojo-how-to/devel/check_for_diff_production_desired_revno 2015-10-12 10:20:25 +0000
69@@ -0,0 +1,10 @@
70+#!/bin/bash
71+
72+source ${MOJO_SPEC_DIR}/${MOJO_STAGE}/get_common_variables
73+
74+if [[ $PRODUCTION_REVNO -ge $DESIRED_REVNO ]]; then
75+ echo "Production is on ${PRODUCTION_REVNO} and the desired revno is ${DESIRED_REVNO}. Nothing to do, exiting..."
76+ exit 1
77+fi
78+
79+echo "Production is on ${PRODUCTION_REVNO} and the desired revno is ${DESIRED_REVNO}"
80
81=== added file 'mojo-how-to/devel/get_common_variables'
82--- mojo-how-to/devel/get_common_variables 1970-01-01 00:00:00 +0000
83+++ mojo-how-to/devel/get_common_variables 2015-10-12 10:20:25 +0000
84@@ -0,0 +1,5 @@
85+#!/bin/bash
86+
87+# Source variables used by other scripts
88+PRODUCTION_REVNO=$(cat ${MOJO_LOCAL_DIR}/production_revno)
89+DESIRED_REVNO=$(cat ${MOJO_LOCAL_DIR}/desired_revno)
90
91=== added file 'mojo-how-to/devel/publish_revno'
92--- mojo-how-to/devel/publish_revno 1970-01-01 00:00:00 +0000
93+++ mojo-how-to/devel/publish_revno 2015-10-12 10:20:25 +0000
94@@ -0,0 +1,10 @@
95+#!/bin/bash
96+
97+source ${MOJO_SPEC_DIR}/${MOJO_STAGE}/get_common_variables
98+
99+echo $DESIRED_REVNO > ${MOJO_LOCAL_DIR}/tested_revno
100+
101+echo "Publishing $DESIRED_REVNO as tested_revno"
102+
103+cd ${MOJO_LOCAL_DIR}
104+swift upload mojo-how-to-autodeploy tested_revno
105
106=== added file 'mojo-how-to/devel/store_desired_revno'
107--- mojo-how-to/devel/store_desired_revno 1970-01-01 00:00:00 +0000
108+++ mojo-how-to/devel/store_desired_revno 2015-10-12 10:20:25 +0000
109@@ -0,0 +1,9 @@
110+#!/bin/bash
111+
112+# Store the desired revno we want to upgrade to. In our case this is going to
113+# be the current tip of trunk whenever we run this script, which will have been
114+# collected already, so we can just query the revno.
115+
116+DESIRED_REVNO=$(bzr revno ${MOJO_BUILD_DIR}/mojo)
117+
118+echo $DESIRED_REVNO > ${MOJO_LOCAL_DIR}/desired_revno
119
120=== added file 'mojo-how-to/devel/store_production_revno'
121--- mojo-how-to/devel/store_production_revno 1970-01-01 00:00:00 +0000
122+++ mojo-how-to/devel/store_production_revno 2015-10-12 10:20:25 +0000
123@@ -0,0 +1,9 @@
124+#!/bin/bash
125+
126+# Store the current revno used on production (grab from production swift
127+# container)
128+
129+. ${MOJO_LOCAL_DIR}/autodeploy-secrets
130+PRODUCTION_REVNO=$(wget -q -O- ${PROD_SWIFT_CONTAINER}/production_revno)
131+
132+echo $PRODUCTION_REVNO > ${MOJO_LOCAL_DIR}/production_revno
133
134=== added directory 'mojo-how-to/manifests'
135=== added file 'mojo-how-to/manifests/check-autodeploy'
136--- mojo-how-to/manifests/check-autodeploy 1970-01-01 00:00:00 +0000
137+++ mojo-how-to/manifests/check-autodeploy 2015-10-12 10:20:25 +0000
138@@ -0,0 +1,11 @@
139+## This manifest should invoke prepare-autodeploy and then verify that the
140+## proposed deployment can be done. This is usually done by invoking
141+## utils/confirm-autodeployable, which will check that the current spec revno has
142+## successfully been used in ci.admin and that the requested build label has been
143+## tested. This manifest may also perhaps run a verify phase to ensure the
144+## environment is healthy. This manifest is usually invoked by
145+## deploy-from-blessed-branch.
146+
147+include config=manifests/prepare-autodeploy
148+
149+include config=manifest-verify
150
151=== added file 'mojo-how-to/manifests/perform-autodeploy'
152--- mojo-how-to/manifests/perform-autodeploy 1970-01-01 00:00:00 +0000
153+++ mojo-how-to/manifests/perform-autodeploy 2015-10-12 10:20:25 +0000
154@@ -0,0 +1,15 @@
155+## This manifest should invoke check-autodeploy to ensure the deployment can be
156+## done, and then perform the deployment, most preferably by invoking
157+## perform-autodeploy-unchecked. The manifest may invoke database
158+## migrations, if necessary and should also verify that the deployment was
159+## successful. This manifest is usually invoked by deploy-from-blessed-branch.
160+
161+include config=manifests/check-autodeploy
162+include config=manifests/perform-autodeploy-unchecked
163+include config=manifest-verify
164+
165+script config=publish_revno
166+
167+## And now just print a comment that we've successfully auto-deployed so it's
168+## easier to report on that
169+# Successfully auto-deployed new code for mojo-how-to
170
171=== added file 'mojo-how-to/manifests/perform-autodeploy-unchecked'
172--- mojo-how-to/manifests/perform-autodeploy-unchecked 1970-01-01 00:00:00 +0000
173+++ mojo-how-to/manifests/perform-autodeploy-unchecked 2015-10-12 10:20:25 +0000
174@@ -0,0 +1,16 @@
175+## This manifest should perform the "meat" of the autodeploy, *without*
176+## checking whether or not do so. In general this manifest is invoked by
177+## perform-autodeploy (below) and by test-autodeploy (further below).
178+
179+# Pull down the latest content
180+collect
181+# Set builddeps
182+builddeps packages=make,markdown,bzr
183+# Run the build step
184+build config=build-desired-revno
185+# Copy our built resources to the instances
186+script config=upload-built-content BUILD_LABEL=revno
187+# Update the config variable so our content is updated
188+script config=update-content BUILD_LABEL=revno
189+# Sleep to let the update be applied
190+sleep config=60
191
192=== added file 'mojo-how-to/manifests/prepare-autodeploy'
193--- mojo-how-to/manifests/prepare-autodeploy 1970-01-01 00:00:00 +0000
194+++ mojo-how-to/manifests/prepare-autodeploy 2015-10-12 10:20:25 +0000
195@@ -0,0 +1,13 @@
196+## This manifest should prepare the workspace for a deployment test or
197+## autodeploy. Tasks commonly performed here are storing the build label to be
198+## deployed and fetching and storing the currently-live build label from the
199+## production environment or elsewhere (but ideally the former). This manifest
200+## exists in particular so that the build label to be deployed is specified in one
201+## and only one location.
202+
203+script config=store_production_revno
204+collect
205+script config=store_desired_revno
206+
207+# Now check there's actually a rollout that we want to attempt
208+script config=check_for_diff_production_desired_revno
209
210=== added file 'mojo-how-to/manifests/test-autodeploy'
211--- mojo-how-to/manifests/test-autodeploy 1970-01-01 00:00:00 +0000
212+++ mojo-how-to/manifests/test-autodeploy 2015-10-12 10:20:25 +0000
213@@ -0,0 +1,36 @@
214+## After invoking check-autodeploy-testable, this manifest should deploy an
215+## environment to match the existing production environment and then upgrade to
216+## the DESIRED BUILD LABEL, most preferably by invoking
217+## perform-autodeploy-unchecked. Following the upgrade this manifest
218+## should perform any verification needed, and then publish suitable objects to
219+## the swift container recording the result.
220+
221+# Get what revnos we're interested in for this deployment
222+include config=manifests/prepare-autodeploy
223+
224+# Having confirmed there's a deployment to test, we first need to bring the
225+# environment up in it's current state on production
226+
227+# We need the markdown package to be able to generate the docs for Mojo
228+builddeps packages=make,markdown,bzr
229+# Run the collect step
230+collect
231+# Run the build step
232+build config=build-production-revno
233+# Deploy services only
234+deploy config=services local=services-secret delay=0
235+# Copy our built resources to the instances
236+script config=upload-built-content
237+# And now deploy relations as well
238+deploy config=relations
239+# Run verify steps
240+include config=manifest-verify
241+
242+# Now perform the autodeploy
243+include config=manifests/perform-autodeploy-unchecked
244+
245+# And verify our environment again
246+include config=manifest-verify
247+
248+# Now publish the revno we've successfully rolled out
249+script config=publish_revno
250
251=== added symlink 'mojo-how-to/production/build-desired-revno'
252=== target is u'../devel/build-desired-revno'
253=== added symlink 'mojo-how-to/production/build-production-revno'
254=== target is u'../devel/build-production-revno'
255=== added symlink 'mojo-how-to/production/check_for_diff_production_desired_revno'
256=== target is u'../devel/check_for_diff_production_desired_revno'
257=== added symlink 'mojo-how-to/production/get_common_variables'
258=== target is u'../devel/get_common_variables'
259=== added file 'mojo-how-to/production/publish_revno'
260--- mojo-how-to/production/publish_revno 1970-01-01 00:00:00 +0000
261+++ mojo-how-to/production/publish_revno 2015-10-12 10:20:25 +0000
262@@ -0,0 +1,10 @@
263+#!/bin/bash
264+
265+source ${MOJO_SPEC_DIR}/${MOJO_STAGE}/get_common_variables
266+
267+echo $DESIRED_REVNO > ${MOJO_LOCAL_DIR}/production_revno
268+
269+echo "Publishing $DESIRED_REVNO as production_revno"
270+
271+cd ${MOJO_LOCAL_DIR}
272+swift upload mojo-how-to-autodeploy production_revno
273
274=== added file 'mojo-how-to/production/store_desired_revno'
275--- mojo-how-to/production/store_desired_revno 1970-01-01 00:00:00 +0000
276+++ mojo-how-to/production/store_desired_revno 2015-10-12 10:20:25 +0000
277@@ -0,0 +1,9 @@
278+#!/bin/bash
279+
280+# Store the desired revno we want to upgrade to. In our case this is going to
281+# be the revno that's been tested on CI.
282+
283+. ${MOJO_LOCAL_DIR}/autodeploy-secrets
284+DESIRED_REVNO=$(wget -q -O- ${CI_SWIFT_CONTAINER}/tested_revno)
285+
286+echo $DESIRED_REVNO > ${MOJO_LOCAL_DIR}/desired_revno
287
288=== added file 'mojo-how-to/production/store_production_revno'
289--- mojo-how-to/production/store_production_revno 1970-01-01 00:00:00 +0000
290+++ mojo-how-to/production/store_production_revno 2015-10-12 10:20:25 +0000
291@@ -0,0 +1,10 @@
292+#!/bin/bash
293+
294+# Store the current revno used on production (grab from production swift
295+# container). Even though this is being run in the production stage, this is
296+# still the most reliable way of getting this.
297+
298+. ${MOJO_LOCAL_DIR}/autodeploy-secrets
299+PRODUCTION_REVNO=$(wget -q -O- ${PROD_SWIFT_CONTAINER}/production_revno)
300+
301+echo $PRODUCTION_REVNO > ${MOJO_LOCAL_DIR}/production_revno

Subscribers

People subscribed via source and target branches

to all changes: