Merge lp:~nottrobin/webteam-project-builder/restructure into lp:webteam-project-builder

Proposed by Robin Winslow
Status: Needs review
Proposed branch: lp:~nottrobin/webteam-project-builder/restructure
Merge into: lp:webteam-project-builder
Diff against target: 296 lines (+177/-86)
6 files modified
.bzrignore (+2/-2)
.gitignore (+2/-2)
README.md (+6/-5)
create-archive-and-update-spec.sh (+0/-77)
create-upload-archive.sh (+93/-0)
rebuild-pip-cache.sh (+74/-0)
To merge this branch: bzr merge lp:~nottrobin/webteam-project-builder/restructure
Reviewer Review Type Date Requested Status
Tristram Oaten Pending
Review via email: mp+248292@code.launchpad.net

Description of the change

Add "rebuild-pip-cache.sh";
Restructure to use bzr revno as build label;
create "latest" file to contain the current build label.

To post a comment you must log in.
6. By Robin Winslow

Spit out public interface for kelpie

7. By Robin Winslow

Make sure pip cache doesnt already exist

8. By Robin Winslow

Use the actual real echo command (remove @)

9. By Robin Winslow

Make that stuff at the end comments

10. By Robin Winslow

Add latest_file_url variable, just for out benefit

11. By Robin Winslow

Remove replacement of kelpie

12. By Robin Winslow

Actually, scratch that

13. By Robin Winslow

It'll be quicker to pull pip-cache if we can.

Unmerged revisions

13. By Robin Winslow

It'll be quicker to pull pip-cache if we can.

12. By Robin Winslow

Actually, scratch that

11. By Robin Winslow

Remove replacement of kelpie

10. By Robin Winslow

Add latest_file_url variable, just for out benefit

9. By Robin Winslow

Make that stuff at the end comments

8. By Robin Winslow

Use the actual real echo command (remove @)

7. By Robin Winslow

Make sure pip cache doesnt already exist

6. By Robin Winslow

Spit out public interface for kelpie

5. By Robin Winslow

Add "rebuild-pip-cache.sh"; Restructure to use bzr revno as build label; create "latest" file to contain the current build label.

4. By Tristram Oaten

whitespace test of bzr-sync

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2015-01-08 17:52:15 +0000
3+++ .bzrignore 2015-02-04 00:15:03 +0000
4@@ -1,3 +1,3 @@
5-/build/
6-/spec/
7+/builds/
8+/pip-caches/
9 .git/
10
11=== modified file '.gitignore'
12--- .gitignore 2015-01-08 17:52:15 +0000
13+++ .gitignore 2015-02-04 00:15:03 +0000
14@@ -1,3 +1,3 @@
15-/build/
16-/spec/
17+/builds/
18+/pip-caches/
19 .bzr/
20
21=== modified file 'README.md'
22--- README.md 2015-01-15 09:25:39 +0000
23+++ README.md 2015-02-04 00:15:03 +0000
24@@ -1,7 +1,8 @@
25 # webteam-project-builder
26
27-A script for internal Jenkins deployments at Canonical. Essentially it :
28-
29-Runs the `spec-repo` mojo spec with with `project-repo` python project, kicking off the `make-targets` maketarget.
30-Then tarballs everything and uploads to swift, and appends the bucket location to `location-file`
31-
32+A script for internal Jenkins deployments at Canonical. There are two scripts:
33+
34+```
35+./rebuild-pip-cache.sh {project-name} # Create a cache of built pip dependencies
36+./create-upload-archive.sh {project-name} # Create a new archive of the code and upload it to swift
37+```
38
39=== removed file 'create-archive-and-update-spec.sh'
40--- create-archive-and-update-spec.sh 2014-11-28 17:39:18 +0000
41+++ create-archive-and-update-spec.sh 1970-01-01 00:00:00 +0000
42@@ -1,77 +0,0 @@
43-#!/usr/bin/env bash
44-
45-set -ex
46-
47-# Get arguments
48-# ===
49-# Example:
50-# ./create-archive-and-update-spec.sh \
51-# --spec-repo=lp:~webteam-backend/canonical-mojo-specs/mojo-webteam-assets \
52-# --project-name=assets-manager \
53-# --project-repo=lp:assets-manager \
54-# --make-targets=pip-cache
55-# --location-file=common/scripts/manager-archive-location.cfg
56-
57-PARSED_OPTIONS=$(getopt -n "$0" -o "s:,n:,r:,m:,l:" --long "spec-repo:,project-name:,project-repo:,make-targets:,location-file:" -- "$@")
58-eval set -- "$PARSED_OPTIONS"
59-
60-# extract options and their arguments into variables.
61-while true ; do
62- case "$1" in
63- -s|--spec-repo) spec_repo=$2; shift 2;;
64- -n|--project-name) project_name=$2; shift 2;;
65- -r|--project-repo) project_repo=$2; shift 2;;
66- -m|--make-targets) make_targets=$2; shift 2;;
67- -l|--location-file) location_file=$2; shift 2;;
68- --) shift ; break;;
69- *) echo "Internal error!" ; exit 1;;
70- esac
71-done
72-
73-# Constants
74-project_dir=build/${project_name}
75-archive_filename=${project_name}.tar.gz
76-archive_path=build/${archive_filename}
77-iso_timestamp=$(date --iso-8601=seconds)
78-
79-# Make sure build directory exists
80-mkdir -p build
81-
82-# Checkout project
83-if [ -d ${project_dir} ]; then
84- bzr pull --directory ${project_dir} --overwrite ${project_repo}
85-else
86- bzr branch ${project_repo} ${project_dir}
87-fi
88-
89-# Prepare project
90-make -C ${project_dir} ${make_targets} # Run any necessary make targets
91-
92-# Create archive
93-rm -f ${archive_path}
94-tar -C ${project_dir} --exclude-vcs -czf ${archive_path} .
95-
96-# Upload to swift container
97-swift upload charm-assets ${archive_path} --object-name=${iso_timestamp}/${archive_filename}
98-# Make sure the container is publicly accessible
99-swift post -r .r:* charm-assets
100-# Get the URL
101-container_url=`swift stat -v charm-assets | grep -o 'http.*'`
102-
103-# Checkout spec
104-if [ -d spec ]; then
105- bzr pull --directory spec --overwrite ${spec_repo}
106-else
107- bzr branch ${spec_repo} spec
108-fi
109-
110-cd spec
111-
112-# Update manager-archive-location.sh with the new archive location
113-echo "CODE_ASSETS_URI=${container_url}" > ${location_file}
114-echo "BUILD_LABEL=${iso_timestamp}" >> ${location_file}
115-echo "ARCHIVE_FILENAME=${archive_filename}" >> ${location_file}
116-
117-bzr add ${location_file}
118-bzr commit ${location_file} -m "Jenkins: updating manager's archive-location for release"
119-bzr push ${spec_repo}
120
121=== added file 'create-upload-archive.sh'
122--- create-upload-archive.sh 1970-01-01 00:00:00 +0000
123+++ create-upload-archive.sh 2015-02-04 00:15:03 +0000
124@@ -0,0 +1,93 @@
125+#!/usr/bin/env bash
126+
127+set -ex
128+
129+# Get project name
130+if [ -z "${project_name}" ]; then
131+ if [ -n "${1}" ]; then
132+ project_name=${1}
133+ else
134+ echo "Usage: ./rebuild-pip-cache.sh {project_name}";
135+ exit;
136+ fi
137+fi
138+
139+# Get arguments
140+# ===
141+# Examples:
142+# ./create-archive-and-update-spec.sh assets-manager # project-repository and swift-container will be inferred
143+# ./create-archive-and-update-spec.sh assets-manager --make-targets sass # Optionally run make target
144+# ./create-archive-and-update-spec.sh assets-manager --project-repository lp:assets-manager --pip-cache-repository lp:~webteam-backend/assets-maanager/pip-cache --swift-container assets-manager --make-targets sass
145+
146+PARSED_OPTIONS=$(getopt -n "$0" -o "r:,p:,m:" --long "project-repository:,pip-cache-repository:,make-targets:" -- "$@")
147+eval set -- "$PARSED_OPTIONS"
148+
149+# extract options and their arguments into variables.
150+while true ; do
151+ case "$1" in
152+ -r|--project-repository) project_repository=$2; shift 2;;
153+ -p|--pip-cache-repository) pip_cache_repository=$2; shift 2;;
154+ -m|--make-targets) make_targets=$2; shift 2;;
155+ --) shift; break;;
156+ *) echo "Error: Option parsing failure" ; exit 1;;
157+ esac
158+done
159+
160+# Infer variables from project_name
161+if [ -z "${project_repository}" ]; then project_repository=lp:${project_name}; fi
162+if [ -z "${pip_cache_repository}" ]; then pip_cache_repository=lp:~webteam-backend/${project_name}/pip-cache; fi
163+
164+# Constants
165+archive_filename=${project_name}.tar.gz
166+
167+# Make sure builds directory exists
168+mkdir -p builds
169+cd builds
170+
171+# Checkout project
172+if [ -d ${project_name} ]; then
173+ bzr pull --directory ${project_name} --overwrite ${project_repository}
174+else
175+ bzr branch ${project_repository} ${project_name}
176+fi
177+
178+# Get pip-cache
179+if [ -d ${project_name}/pip-cache} ]; then
180+ bzr pull --directory ${project_name}/pip-cache --overwrite ${pip_cache_repository}
181+else
182+ bzr branch ${pip_cache_repository} ${project_name}/pip-cache
183+fi
184+
185+# Run make targets
186+if [ -n "${make_targets}" ]; then
187+ make -C ${project_name} ${make_targets} # Run any necessary make targets
188+fi
189+
190+# Create archive
191+rm -f ${archive_filename}
192+tar -C ${project_name} --exclude-vcs -czf ${archive_filename} .
193+
194+# Get revision
195+latest_revision=$(bzr revno ${project_name})
196+
197+# Upload to swift container
198+swift upload ${project_name} ${archive_filename} --object-name=${latest_revision}/${archive_filename}
199+# Make sure the container is publicly accessible
200+swift post -r .r:* ${project_name}
201+
202+# Save the latest build label
203+echo ${latest_revision} > latest
204+swift upload ${project_name} latest
205+
206+# Get the URL
207+container_url=`swift stat -v ${project_name} | grep -o 'http.*'`
208+# Replace kelpie with external interface
209+container_url=$(echo ${container_url} | sed "s/http:\/\/kelpie.internal:8080/https:\/\/objectstorage.prodstack.canonical.com/")
210+archive_url="${container_url}/${latest_revision}/${archive_filename}"
211+latest_file_url=${container_url}/latest
212+
213+# ===
214+# Latest revision: ${latest_revision}
215+# URL for 'latest': ${latest_file_url}
216+# URL for archive: ${archive_url}
217+# ===
218
219=== added file 'rebuild-pip-cache.sh'
220--- rebuild-pip-cache.sh 1970-01-01 00:00:00 +0000
221+++ rebuild-pip-cache.sh 2015-02-04 00:15:03 +0000
222@@ -0,0 +1,74 @@
223+#!/usr/bin/env bash
224+
225+set -ex
226+
227+# Get project name
228+if [ -z "${project_name}" ]; then
229+ if [ -n "${1}" ]; then
230+ project_name=${1}
231+ else
232+ echo "Usage: ./rebuild-pip-cache.sh {project_name}";
233+ exit;
234+ fi
235+fi
236+
237+# Get arguments
238+# ===
239+# Example:
240+# ./rebuild-pip-cache.sh assets-mapper # project-repo and pip-cache-repo will be inferred
241+# ./rebuild-pip-cache.sh assets-mapper -r lp:assets-manager -c lp:~webteam-backend/assets-manager/pip-cache
242+# ./rebuild-pip-cache.sh assets-manager --project-repo=lp:assets-manager --pip-cache-repo=lp:~webteam-backend/assets-manager/pip-cache
243+
244+PARSED_OPTIONS=$(getopt -n "$0" -o "r:,p:,:c" --long "project-repo:,pip-cache-repo:,create" -- "$@")
245+eval set -- "$PARSED_OPTIONS"
246+
247+# extract options and their arguments into variables.
248+while true ; do
249+ case "$1" in
250+ -r|--project-repo) project_repo=$2; shift 2;;
251+ -p|--pip-cache-repo) pip_cache_repo=$2; shift 2;;
252+ -c|--create) create=true; shift;;
253+ --) shift; break;;
254+ *) echo "Error: Option parsing failure"; exit 1;;
255+ esac
256+done
257+
258+# Infer variables from project_name
259+if [ -z "${project_repo}" ]; then project_repo=lp:${project_name}; fi
260+if [ -z "${pip_cache_repo}" ]; then pip_cache_repo=lp:~webteam-backend/${project_name}/pip-cache; fi
261+
262+# Create project directory in pip-caches
263+mkdir -p pip-caches/${project_name}
264+cd pip-caches/${project_name}
265+
266+# Get pip-cache
267+if [ -d pip-cache ]; then
268+ bzr pull --directory pip-cache --overwrite ${pip_cache_repo}
269+else
270+ # Try-catch
271+ {
272+ bzr branch ${pip_cache_repo} pip-cache # Create pip-cache
273+ } || {
274+ if [ ! ${create} ]; then
275+ echo "repository ${pip_cache_repo} doesn't exist";
276+ exit
277+ else
278+ # Create blank pip-cache repo
279+ mkdir pip-cache
280+ bzr init pip-cache
281+ fi
282+ }
283+fi
284+
285+# Get project
286+if [ -d code ]; then
287+ bzr pull --directory code --overwrite ${project_repo}
288+else
289+ bzr branch ${project_repo} code
290+fi
291+
292+# Build pip-cache
293+pip install --exists-action=w --download pip-cache/ -r code/requirements/standard.txt
294+bzr add pip-cache/.
295+bzr commit pip-cache/ --unchanged -m 'Requirements auto-updated by webteam-project-builder'
296+bzr push --directory pip-cache ${pip_cache_repo}

Subscribers

People subscribed via source and target branches

to all changes: