Skip to content

Commit 26ec25b

Browse files
authored
Merge pull request element-hq#5090 from vector-im/dbkr/deploy_config_glob
Make --config accept globs
2 parents 9b9073f + b4ea938 commit 26ec25b

2 files changed

Lines changed: 24 additions & 22 deletions

File tree

‎scripts/deploy.py‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sys
1515
import tarfile
1616
import shutil
17+
import glob
1718

1819
try:
1920
# python3
@@ -66,7 +67,7 @@ def __init__(self):
6667
self.bundles_path = None
6768
self.should_clean = False
6869
# filename -> symlink path e.g 'config.localhost.json' => '../localhost/config.json'
69-
self.config_locations = {}
70+
self.symlink_paths = {}
7071
self.verify_signature = True
7172

7273
def deploy(self, tarball, extract_path):
@@ -98,11 +99,11 @@ def deploy(self, tarball, extract_path):
9899

99100
print ("Extracted into: %s" % extracted_dir)
100101

101-
if self.config_locations:
102-
for config_filename, config_loc in self.config_locations.iteritems():
102+
if self.symlink_paths:
103+
for link_path, file_path in self.symlink_paths.iteritems():
103104
create_relative_symlink(
104-
target=config_loc,
105-
linkname=os.path.join(extracted_dir, config_filename)
105+
target=file_path,
106+
linkname=os.path.join(extracted_dir, link_path)
106107
)
107108

108109
if self.bundles_path:
@@ -165,9 +166,10 @@ def download_file(self, url):
165166
)
166167
)
167168
parser.add_argument(
168-
"--config", nargs='?', default='./config.json', help=(
169-
"Write a symlink at config.json in the extracted tarball to this \
170-
location. (Default: '%(default)s')"
169+
"--include", nargs='*', default='./config*.json', help=(
170+
"Symlink these files into the root of the deployed tarball. \
171+
Useful for config files and home pages. Supports glob syntax. \
172+
(Default: '%(default)s')"
171173
)
172174
)
173175
parser.add_argument(
@@ -182,8 +184,8 @@ def download_file(self, url):
182184
deployer.packages_path = args.packages_dir
183185
deployer.bundles_path = args.bundles_dir
184186
deployer.should_clean = args.clean
185-
deployer.config_locations = {
186-
"config.json": args.config,
187-
}
187+
188+
for include in args.include:
189+
deployer.symlink_paths.update({ os.path.basename(pth): pth for pth in glob.iglob(include) })
188190

189191
deployer.deploy(args.tarball, args.extract_path)

‎scripts/redeploy.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import time
1616
import traceback
1717
from urlparse import urljoin
18+
import glob
1819

1920
from flask import Flask, jsonify, request, abort
2021

@@ -188,15 +189,12 @@ def deploy_tarball(tar_gz_url, build_dir):
188189
)
189190
)
190191

191-
def _raise(ex):
192-
raise ex
193-
194-
# --config config.json=../../config.json --config config.localhost.json=./localhost.json
192+
# --include ../../config.json ./localhost.json homepages/*
195193
parser.add_argument(
196-
"--config", action="append", dest="configs",
197-
type=lambda kv: kv.split("=", 1) if "=" in kv else _raise(Exception("Missing =")), help=(
198-
"A list of configs to symlink into the extracted tarball. \
199-
For example, --config config.json=../config.json config2.json=../test/config.json"
194+
"--include", nargs='*', default='./config*.json', help=(
195+
"Symlink these files into the root of the deployed tarball. \
196+
Useful for config files and home pages. Supports glob syntax. \
197+
(Default: '%(default)s')"
200198
)
201199
)
202200
parser.add_argument(
@@ -220,7 +218,9 @@ def _raise(ex):
220218
deployer = Deployer()
221219
deployer.bundles_path = args.bundles_dir
222220
deployer.should_clean = args.clean
223-
deployer.config_locations = dict(args.configs) if args.configs else {}
221+
222+
for include in args.include:
223+
deployer.symlink_paths.update({ os.path.basename(pth): pth for pth in glob.iglob(include) })
224224

225225

226226
# we don't pgp-sign jenkins artifacts; instead we rely on HTTPS access to
@@ -234,13 +234,13 @@ def _raise(ex):
234234
deploy_tarball(args.tarball_uri, build_dir)
235235
else:
236236
print(
237-
"Listening on port %s. Extracting to %s%s. Symlinking to %s. Jenkins URL: %s. Config locations: %s" %
237+
"Listening on port %s. Extracting to %s%s. Symlinking to %s. Jenkins URL: %s. Include patterns: %s" %
238238
(args.port,
239239
arg_extract_path,
240240
" (clean after)" if deployer.should_clean else "",
241241
arg_symlink,
242242
arg_jenkins_url,
243-
deployer.config_locations,
243+
deployer.symlink_paths,
244244
)
245245
)
246246
app.run(host="0.0.0.0", port=args.port, debug=True)

0 commit comments

Comments
 (0)