Skip to content

Commit a9fefd7

Browse files
committed
HBASE-24297 release scripts should be able to use a custom git repo
* adds a optional -r [repo] arg * if the passed repo is on the local filesystem, creates a container mount * when cloning a local repo configure git to share objects with the local repo instead of copying * when cloning a local repo in a container configure the clone to have a remote that will work back on the host. closes #1725 Signed-off-by: stack <stack@apache.org> Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
1 parent 8ff8e70 commit a9fefd7

File tree

3 files changed

+102
-9
lines changed

3 files changed

+102
-9
lines changed

dev-support/create-release/do-release-docker.sh

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export PROJECT="${PROJECT:-hbase}"
5353
SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5454
# shellcheck source=SCRIPTDIR/release-util.sh
5555
. "$SELF/release-util.sh"
56+
ORIG_PWD="$(pwd)"
5657

5758
function usage {
5859
local NAME
@@ -71,6 +72,7 @@ Options:
7172
-j [path] path to local JDK installation to use building. By default the script will
7273
use openjdk8 installed in the docker image.
7374
-p [project] project to build, such as 'hbase' or 'hbase-thirdparty'; defaults to $PROJECT env var
75+
-r [repo] git repo to use for remote git operations. defaults to ASF gitbox for project.
7476
-s [step] runs a single step of the process; valid steps are: tag|publish-dist|publish-release.
7577
If none specified, runs tag, then publish-dist, and then publish-release.
7678
'publish-snapshot' is also an allowed, less used, option.
@@ -82,13 +84,15 @@ WORKDIR=
8284
IMGTAG=latest
8385
JAVA=
8486
RELEASE_STEP=
85-
while getopts "d:fhj:p:s:t:" opt; do
87+
GIT_REPO=
88+
while getopts "d:fhj:p:r:s:t:" opt; do
8689
case $opt in
8790
d) WORKDIR="$OPTARG" ;;
8891
f) DRY_RUN=0 ;;
8992
t) IMGTAG="$OPTARG" ;;
9093
j) JAVA="$OPTARG" ;;
9194
p) PROJECT="$OPTARG" ;;
95+
r) GIT_REPO="$OPTARG" ;;
9296
s) RELEASE_STEP="$OPTARG" ;;
9397
h) usage ;;
9498
?) error "Invalid option. Run with -h for help." ;;
@@ -169,11 +173,65 @@ if [ -n "$JAVA" ]; then
169173
JAVA_VOL=(--volume "$JAVA:/opt/hbase-java")
170174
fi
171175

176+
#TODO some debug output would be good here
177+
GIT_REPO_MOUNT=()
178+
if [ -n "${GIT_REPO}" ]; then
179+
case "${GIT_REPO}" in
180+
# skip the easy to identify remote protocols
181+
ssh://*|git://*|http://*|https://*|ftp://*|ftps://*) ;;
182+
# for sure local
183+
/*)
184+
GIT_REPO_MOUNT=(--mount "type=bind,src=${GIT_REPO},dst=/opt/hbase-repo")
185+
echo "HOST_GIT_REPO=${GIT_REPO}" >> "${ENVFILE}"
186+
GIT_REPO="/opt/hbase-repo"
187+
;;
188+
# on the host but normally git wouldn't use the local optimization
189+
file://*)
190+
echo "[INFO] converted file:// git repo to a local path, which changes git to assume --local."
191+
GIT_REPO_MOUNT=(--mount "type=bind,src=${GIT_REPO#file://},dst=/opt/hbase-repo")
192+
echo "HOST_GIT_REPO=${GIT_REPO}" >> "${ENVFILE}"
193+
GIT_REPO="/opt/hbase-repo"
194+
;;
195+
# have to decide if it's a local path or the "scp-ish" remote
196+
*)
197+
declare colon_remove_prefix;
198+
declare slash_remove_prefix;
199+
declare local_path;
200+
colon_remove_prefix="${GIT_REPO#*:}"
201+
slash_remove_prefix="${GIT_REPO#*/}"
202+
if [ "${GIT_REPO}" = "${colon_remove_prefix}" ]; then
203+
# if there was no colon at all, we assume this must be a local path
204+
local_path="no colon at all"
205+
elif [ "${GIT_REPO}" != "${slash_remove_prefix}" ]; then
206+
# if there was a colon and there is no slash, then we assume it must be scp-style host
207+
# and a relative path
208+
209+
if [ "${#colon_remove_prefix}" -lt "${#slash_remove_prefix}" ]; then
210+
# Given the substrings made by removing everything up to the first colon and slash
211+
# we can determine which comes first based on the longer substring length.
212+
# if the slash is first, then we assume the colon is part of a path name and if the colon
213+
# is first then it is the seperator between a scp-style host name and the path.
214+
local_path="slash happened before a colon"
215+
fi
216+
fi
217+
if [ -n "${local_path}" ]; then
218+
# convert to an absolute path
219+
GIT_REPO="$(cd "$(dirname "${ORIG_PWD}/${GIT_REPO}")"; pwd)/$(basename "${ORIG_PWD}/${GIT_REPO}")"
220+
GIT_REPO_MOUNT=(--mount "type=bind,src=${GIT_REPO},dst=/opt/hbase-repo")
221+
echo "HOST_GIT_REPO=${GIT_REPO}" >> "${ENVFILE}"
222+
GIT_REPO="/opt/hbase-repo"
223+
fi
224+
;;
225+
esac
226+
echo "GIT_REPO=${GIT_REPO}" >> "${ENVFILE}"
227+
fi
228+
172229
echo "Building $RELEASE_TAG; output will be at $WORKDIR/output"
173230
cmd=(docker run -ti \
174231
--env-file "$ENVFILE" \
175232
--volume "$WORKDIR:/opt/hbase-rm" \
176233
"${JAVA_VOL[@]}" \
234+
"${GIT_REPO_MOUNT[@]}" \
177235
"hbase-rm:$IMGTAG")
178236
echo "${cmd[*]}"
179237
"${cmd[@]}"

dev-support/create-release/release-build.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ if [[ "$1" == "tag" ]]; then
111111
set -o pipefail
112112
set -x # detailed logging during action
113113
check_get_passwords ASF_PASSWORD
114-
check_needed_vars PROJECT ASF_USERNAME ASF_PASSWORD RELEASE_VERSION RELEASE_TAG NEXT_VERSION \
115-
GIT_EMAIL GIT_NAME GIT_BRANCH
116-
ASF_REPO="gitbox.apache.org/repos/asf/${PROJECT}.git"
117-
encoded_username="$(python -c "import urllib; print urllib.quote('''$ASF_USERNAME''')")"
118-
encoded_password="$(python -c "import urllib; print urllib.quote('''$ASF_PASSWORD''')")"
119-
git clone "https://$encoded_username:$encoded_password@$ASF_REPO" -b "$GIT_BRANCH" "${PROJECT}"
114+
check_needed_vars PROJECT RELEASE_VERSION RELEASE_TAG NEXT_VERSION GIT_EMAIL GIT_NAME GIT_BRANCH
115+
if [ -z "${GIT_REPO}" ]; then
116+
check_needed_vars ASF_USERNAME ASF_PASSWORD
117+
fi
118+
git_clone_overwrite
120119

121120
# 'update_releasenotes' searches the project's Jira for issues where 'Fix Version' matches specified
122121
# $jira_fix_version. For most projects this is same as ${RELEASE_VERSION}. However, all the 'hbase-*'
@@ -186,8 +185,7 @@ fi
186185
if is_dry_run && [[ "${TAG_SAME_DRY_RUN:-}" == "true" && -d "${PROJECT}.tag" ]]; then
187186
ln -s "${PROJECT}.tag" "${PROJECT}"
188187
else
189-
ASF_REPO="${ASF_REPO:-https://gitbox.apache.org/repos/asf/${PROJECT}.git}"
190-
git clone "$ASF_REPO" "${PROJECT}"
188+
git_clone_overwrite
191189
fi
192190
cd "${PROJECT}"
193191
git checkout "$GIT_REF"

dev-support/create-release/release-util.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,43 @@ function configure_maven {
398398
EOF
399399
}
400400

401+
# clone of the repo, deleting anything that exists in the working directory named after the project.
402+
# optionally with auth details for pushing.
403+
function git_clone_overwrite {
404+
local asf_repo
405+
if [ -z "${PROJECT}" ] || [ "${PROJECT}" != "${PROJECT#/}" ]; then
406+
error "Project name must be defined and not start with a '/'. PROJECT='${PROJECT}'"
407+
fi
408+
rm -rf "${PROJECT}"
409+
410+
if [[ -z "${GIT_REPO}" ]]; then
411+
asf_repo="gitbox.apache.org/repos/asf/${PROJECT}.git"
412+
echo "[INFO] clone will be of the gitbox repo for ${PROJECT}."
413+
if [ -n "${ASF_USERNAME}" ] && [ -n "${ASF_PASSWORD}" ]; then
414+
# Ugly!
415+
encoded_username=$(python -c "import urllib; print urllib.quote('''$ASF_USERNAME''')")
416+
encoded_password=$(python -c "import urllib; print urllib.quote('''$ASF_PASSWORD''')")
417+
GIT_REPO="https://$encoded_username:$encoded_password@${asf_repo}"
418+
else
419+
GIT_REPO="https://${asf_repo}"
420+
fi
421+
else
422+
echo "[INFO] clone will be of provided git repo."
423+
fi
424+
# N.B. we use the shared flag because the clone is short lived and if a local repo repo was
425+
# given this will let us refer to objects there directly instead of hardlinks or copying.
426+
# The option is silently ignored for non-local repositories. see the note on git help clone
427+
# for the --shared option for details.
428+
git clone --shared -b "${GIT_BRANCH}" -- "${GIT_REPO}" "${PROJECT}"
429+
# If this was a host local git repo then add in an alternates and remote that will
430+
# work back on the host if the RM needs to do any post-processing steps, i.e. pushing the git tag
431+
# for more info see 'git help remote' and 'git help repository-layout'.
432+
if [ -n "$HOST_GIT_REPO" ]; then
433+
echo "${HOST_GIT_REPO}/objects" >> "${PROJECT}/.git/objects/info/alternates"
434+
(cd "${PROJECT}"; git remote add host "${HOST_GIT_REPO}")
435+
fi
436+
}
437+
401438
# Writes report into cwd!
402439
function generate_api_report {
403440
local project="$1"

0 commit comments

Comments
 (0)