Merge ~cjwatson/launchpad:publish-db-tarballs-to-swift into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 1c041425d91b9871c8b32ee45a2c43ed92ddc9e7
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:publish-db-tarballs-to-swift
Merge into: launchpad:master
Diff against target: 136 lines (+51/-17)
2 files modified
Makefile (+9/-2)
utilities/publish-to-swift (+42/-15)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+439659@code.launchpad.net

Commit message

Support publishing tarballs of db-devel to Swift

Description of the change

Unlike our other environments, Launchpad's staging environment is built from the `db-stable` branch, which is fed from `db-devel`. To support deploying this using Juju charms, we need to build a separate stream of deployment artifacts from the `db-devel` branch, old versions of which are pruned on a different schedule.

(Discovered while trying to set up auto-upgrades for the new Juju-deployed staging appservers. After this lands, we'll also need a change to lp:ols-jenkaas to actually run the builds.)

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM ๐Ÿ‘๐Ÿผ

review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index 7bd08d1..f60189b 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -88,7 +88,14 @@ PIP_BIN = \
6
7 # Create archives in labelled directories (e.g.
8 # <rev-id>/$(PROJECT_NAME).tar.gz)
9-TARBALL_BUILD_LABEL ?= $(shell git rev-parse HEAD)
10+GIT_BRANCH := $(shell git branch --show-current)
11+TARBALL_REVISION ?= $(shell git rev-parse HEAD)
12+ifeq ($(GIT_BRANCH),db-devel)
13+TARBALL_SUFFIX := db
14+else
15+TARBALL_SUFFIX :=
16+endif
17+TARBALL_BUILD_LABEL := $(TARBALL_REVISION)$(if $(TARBALL_SUFFIX),-$(TARBALL_SUFFIX))
18 TARBALL_FILE_NAME = launchpad.tar.gz
19 TARBALL_BUILD_DIR = dist/$(TARBALL_BUILD_LABEL)
20 TARBALL_BUILD_PATH = $(TARBALL_BUILD_DIR)/$(TARBALL_FILE_NAME)
21@@ -304,7 +311,7 @@ publish-tarball: build-tarball
22 [ ! -e ~/.config/swift/launchpad ] || . ~/.config/swift/launchpad; \
23 utilities/publish-to-swift --debug \
24 $(SWIFT_CONTAINER_NAME) $(SWIFT_OBJECT_PATH) \
25- $(TARBALL_BUILD_PATH)
26+ $(TARBALL_BUILD_PATH) $(TARBALL_SUFFIX)
27
28 # setuptools won't touch files that would have the same contents, but for
29 # Make's sake we need them to get fresh timestamps, so we touch them after
30diff --git a/utilities/publish-to-swift b/utilities/publish-to-swift
31index 93280d8..3d13f8c 100755
32--- a/utilities/publish-to-swift
33+++ b/utilities/publish-to-swift
34@@ -8,6 +8,7 @@
35 import _pythonpath # noqa: F401
36
37 import os
38+import re
39 from argparse import ArgumentParser
40
41 import iso8601
42@@ -76,15 +77,26 @@ def publish_file_to_swift(
43 )
44
45
46-def prune_old_files_from_swift(options, container_name, object_dir):
47+def prune_old_files_from_swift(options, container_name, object_dir, suffix):
48 """Prune files from Swift that we no longer need."""
49- response = requests.head("https://launchpad.net/")
50- response.raise_for_status()
51- production_revision = response.headers["X-VCS-Revision"]
52+ if suffix:
53+ suffix = "-" + suffix
54+ if suffix.endswith("-db"):
55+ response = requests.head("https://staging.launchpad.net/")
56+ if not response.ok:
57+ # Staging is routinely down in order to restore its database
58+ # from a recent production dump, so don't consider this an
59+ # error; just skip pruning if we can't determine its revision.
60+ print("staging.launchpad.net is down; not pruning.")
61+ return
62+ else:
63+ response = requests.head("https://launchpad.net/")
64+ response.raise_for_status()
65+ deployed_revision = response.headers["X-VCS-Revision"]
66
67 with SwiftService(options=options) as swift:
68 objs = {}
69- production_mtime = None
70+ deployed_mtime = None
71 for stats in swift.list(
72 container=container_name,
73 options={"prefix": "{}/".format(object_dir)},
74@@ -92,24 +104,35 @@ def prune_old_files_from_swift(options, container_name, object_dir):
75 if not stats["success"]:
76 raise stats["error"]
77 for item in stats["listing"]:
78+ if not item["name"].startswith("{}/".format(object_dir)):
79+ continue
80+ # Only consider pruning builds that have the given suffix.
81+ # (For example, if we're publishing a build with the suffix
82+ # "-db", then we consider pruning builds with the label
83+ # "<commit>-db" but not plain "<commit>".)
84+ build_label = item["name"].split("/")[1]
85+ if not re.match(r"^.{40}%s$" % re.escape(suffix), build_label):
86+ continue
87 if item.get("subdir") is None:
88 mtime = iso8601.parse_date(item["last_modified"])
89 objs[item["name"]] = mtime
90- if item["name"].startswith(
91- "{}/{}/".format(object_dir, production_revision)
92- ):
93- production_mtime = mtime
94+ if build_label == deployed_revision + suffix:
95+ deployed_mtime = mtime
96
97- if production_mtime is None:
98+ if deployed_mtime is None:
99 print(
100- "No file in {} corresponding to production revision {}; "
101- "not pruning.".format(container_name, production_revision)
102+ "No file in {} corresponding to deployed revision {}; "
103+ "not pruning.".format(container_name, deployed_revision)
104 )
105 return
106
107 for object_name, mtime in sorted(objs.items()):
108- if mtime < production_mtime:
109- print("Pruning {} (older than production)".format(object_name))
110+ if mtime < deployed_mtime:
111+ print(
112+ "Pruning {} (older than deployed revision)".format(
113+ object_name
114+ )
115+ )
116 for r in swift.delete(
117 container=container_name, objects=[object_name]
118 ):
119@@ -122,6 +145,7 @@ def main():
120 parser.add_argument("container_name")
121 parser.add_argument("swift_object_path")
122 parser.add_argument("local_path")
123+ parser.add_argument("suffix", nargs="?", default="")
124 add_default_args(parser)
125 args = parser.parse_args()
126
127@@ -173,7 +197,10 @@ def main():
128 overwrite=overwrite,
129 )
130 prune_old_files_from_swift(
131- options, args.container_name, args.swift_object_path.split("/")[0]
132+ options,
133+ args.container_name,
134+ args.swift_object_path.split("/")[0],
135+ args.suffix,
136 )
137
138

Subscribers

People subscribed via source and target branches

to status/vote changes: