Skip to content

Commit 4129c9b

Browse files
committed
Allow --symlink
1 parent e22d36f commit 4129c9b

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

‎deploy/redeploy.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env python
22
from __future__ import print_function
3-
import json, requests, tarfile, argparse, os
3+
import json, requests, tarfile, argparse, os, errno
44
from urlparse import urljoin
55
from flask import Flask, jsonify, request, abort
66
app = Flask(__name__)
77

8-
arg_jenkins_url, arg_listen_port, arg_extract_path, arg_should_clean = None, None, None, None
8+
arg_jenkins_url, arg_listen_port, arg_extract_path, arg_should_clean, arg_symlink = (
9+
None, None, None, None, None
10+
)
911

1012
def download_file(url):
1113
local_filename = url.split('/')[-1]
@@ -20,6 +22,17 @@ def untar_to(tarball, dest):
2022
with tarfile.open(tarball) as tar:
2123
tar.extractall(dest)
2224

25+
def create_symlink(source, linkname):
26+
try:
27+
os.symlink(source, linkname)
28+
except OSError, e:
29+
if e.errno == errno.EEXIST:
30+
# atomic modification
31+
os.symlink(source, linkname + ".tmp")
32+
os.rename(linkname + ".tmp", linkname)
33+
else:
34+
raise e
35+
2336
@app.route("/", methods=["POST"])
2437
def on_receive_jenkins_poke():
2538
# {
@@ -107,6 +120,7 @@ def on_receive_jenkins_poke():
107120
with open(os.path.join(untar_location, "vector/version"), "w") as stamp_file:
108121
stamp_file.write(name_str)
109122

123+
create_symlink(source=os.path.join(untar_location, "vector"), linkname=arg_symlink)
110124

111125
return jsonify({})
112126

@@ -133,6 +147,13 @@ def on_receive_jenkins_poke():
133147
"Remove .tar.gz files after they have been downloaded and extracted."
134148
)
135149
)
150+
parser.add_argument(
151+
"-s", "--symlink", dest="symlink", default="./latest", help=(
152+
"Write a symlink to this location pointing to the extracted tarball. \
153+
New builds will keep overwriting this symlink. The symlink will point \
154+
to the /vector directory INSIDE the tarball."
155+
)
156+
)
136157
args = parser.parse_args()
137158
if args.jenkins.endswith("/"): # important for urljoin
138159
arg_jenkins_url = args.jenkins
@@ -141,10 +162,10 @@ def on_receive_jenkins_poke():
141162
arg_extract_path = args.extract
142163
arg_listen_port = args.port
143164
arg_should_clean = args.clean
165+
arg_symlink = args.symlink
144166
print(
145-
"Listening on port %s. Extracting to %s%s. Jenkins URL: %s" %
167+
"Listening on port %s. Extracting to %s%s. Symlinking to %s. Jenkins URL: %s" %
146168
(arg_listen_port, arg_extract_path,
147-
" (clean after)" if arg_should_clean else "", arg_jenkins_url)
148-
169+
" (clean after)" if arg_should_clean else "", arg_symlink, arg_jenkins_url)
149170
)
150171
app.run(debug=True)

0 commit comments

Comments
 (0)