Added a bunch of new gitlab features.
This commit is contained in:
parent
3abe8af874
commit
cd969ada4f
119
broker.sh
119
broker.sh
@ -266,7 +266,7 @@ print_env () {
|
||||
pr_vars stage_root target_root
|
||||
pr_vars data_file
|
||||
pr_vars dealer dealermail
|
||||
pr_vars github_url github_owner github_token
|
||||
pr_vars gitlab_url gitlab_ssh_port gitlab_http_port gitlab_owner
|
||||
}
|
||||
|
||||
# Takes a json array and prints it as a flat string.
|
||||
@ -551,11 +551,25 @@ cluster_info () {
|
||||
}
|
||||
|
||||
######################################################################
|
||||
# Downloading releases/clones from git repos.
|
||||
# Git operations
|
||||
|
||||
github_url="$(echo $githubenv_json|jq -r '.base_url')"
|
||||
github_owner="$(echo $githubenv_json|jq -r '.repo_owner')"
|
||||
github_token="$(echo $githubenv_json|jq -r '.access_token')"
|
||||
# new gitlab
|
||||
gitlab_http_port="45080"
|
||||
gitlab_ssh_port="45022"
|
||||
gitlab_read_token="uYoP-1HRpvMx3MWoRDHF"
|
||||
|
||||
# old gitlab (overwriting new)
|
||||
gitlab_http_port="45000"
|
||||
gitlab_ssh_port="45002"
|
||||
gitlab_read_token="JF1ymVmbfe1cp4z8eKKb"
|
||||
#master token overwrite
|
||||
#gitlab_read_token="G3Z9G5HeiTp74zFfeUnN"
|
||||
gitlab_token="$gitlab_read_token"
|
||||
|
||||
gitlab_owner="$dealer"
|
||||
gitlab_url="gitlab.adamo.network"
|
||||
gitlab_http_url="http://${gitlab_url}:${gitlab_http_port}"
|
||||
gitlab_ssh_url="ssh://git@${gitlab_url}:${gitlab_ssh_port}"
|
||||
|
||||
git_identify_global () {
|
||||
git config --global user.name "${dealer}"
|
||||
@ -577,14 +591,93 @@ git_update_self () {
|
||||
cd ${owd}
|
||||
}
|
||||
|
||||
# $1: directory
|
||||
# $2: gitlab namespace path (this better exist!)
|
||||
gitlab_create_project_from_repo () {
|
||||
owd=`pwd`
|
||||
if [[ -x $1 ]]; then
|
||||
cd $1
|
||||
else
|
||||
return 2
|
||||
fi
|
||||
shift
|
||||
local path=$(echo "$1"|sed 's/caes/adamo/')
|
||||
local name="$(git rev-parse --show-toplevel | xargs basename)"
|
||||
local branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
if [[ $path ]]; then
|
||||
local uri="${gitlab_ssh_url}/$path"
|
||||
else
|
||||
local uri="${gitlab_ssh_url}"
|
||||
fi
|
||||
echo git push --set-upstream ${uri}/${name}.git $branch
|
||||
cd $owd
|
||||
return 0
|
||||
}
|
||||
|
||||
gitlab_create_projects_for_all_in_dir () {
|
||||
local root=$1
|
||||
for gitdir in `find $root -type d -a -name '.git'`; do
|
||||
local dir=$(dirname $gitdir)
|
||||
local path=$(echo $dir|sed "s|${root}/||")
|
||||
gitlab_create_project_from_repo $dir $path
|
||||
done
|
||||
}
|
||||
|
||||
gitlab_clone_all_projects () {
|
||||
for repo_path in $(gitlab_list_project_paths); do
|
||||
local dest="gitlab_scrape/$(dirname $repo_path)"
|
||||
local name="$(basename $repo_path)"
|
||||
local repo_url="${gitlab_ssh_url}/${repo_path}.git"
|
||||
pr_vars repo_path dest name
|
||||
if [[ $TESTING_MODE ]]; then
|
||||
echo mkdir -p $dest
|
||||
echo git clone ${repo_url} $dest/$name
|
||||
else
|
||||
mkdir -p $dest
|
||||
git clone ${repo_url} $dest/$name
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
gitlab_list_projects () {
|
||||
gitlab_api_get_projects|
|
||||
jq -r '.[] | .["name"]'
|
||||
}
|
||||
|
||||
gitlab_list_project_paths () {
|
||||
gitlab_api_get_projects|
|
||||
jq -r '.[] | .["path_with_namespace"]'
|
||||
}
|
||||
|
||||
gitlab_count_projects () {
|
||||
gitlab_list_projects|wc -l
|
||||
}
|
||||
|
||||
gitlab_api_get_projects () {
|
||||
gitlab_api_request "api/v4/projects" "per_page=100"
|
||||
}
|
||||
|
||||
gitlab_api_request () {
|
||||
local path="$1"
|
||||
local opts="$2"
|
||||
local uri="${gitlab_http_url}/${path}"
|
||||
local header="Authorization: Bearer $gitlab_read_token"
|
||||
#pr_vars path uri header opts
|
||||
if [[ $opts ]]; then
|
||||
curl -s -H "$header" "${uri}?${opts}"
|
||||
else
|
||||
curl -s -H "$header" "${uri}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prints json object of repo release.
|
||||
get_release_data () {
|
||||
local repo="${1}"
|
||||
local release="${2}"
|
||||
local owner_path="${github_url}/repos/${github_owner}"
|
||||
local owner_path="${gitlab_url}/repos/${gitlab_owner}"
|
||||
local repo_path="${owner_path}/${repo}/releases/${release}"
|
||||
curl -s \
|
||||
-H "Authorization: token ${github_token}"\
|
||||
-H "Authorization: token ${gitlab_token}"\
|
||||
"${repo_path}"
|
||||
#|jq -r
|
||||
}
|
||||
@ -602,7 +695,7 @@ get_release () {
|
||||
pr_vars repo release tarball_url release_data
|
||||
else
|
||||
curl -s \
|
||||
-H "Authorization: token ${github_token}" \
|
||||
-H "Authorization: token ${gitlab_token}" \
|
||||
-L -o "${1}.tar" $tarball_url
|
||||
fi
|
||||
}
|
||||
@ -618,11 +711,11 @@ get_clone () {
|
||||
pr_vars repo branch
|
||||
return 0
|
||||
else
|
||||
github_root="${github_token}@gitlab.adamonet"
|
||||
github_root="${gitlab_token}@gitlab.adamonet"
|
||||
git clone \
|
||||
--single-branch \
|
||||
--branch $branch \
|
||||
"https://${github_root}/${github_owner}/${repo}.git"
|
||||
"https://${github_root}/${gitlab_owner}/${repo}.git"
|
||||
return
|
||||
fi
|
||||
}
|
||||
@ -953,11 +1046,11 @@ stage_release () {
|
||||
fi
|
||||
else
|
||||
get_release ${deal_repo} ${deal_tag}
|
||||
rm -rf "${github_owner}-${deal_repo}-*"
|
||||
rm -rf "${gitlab_owner}-${deal_repo}-*"
|
||||
tar xf "${deal_repo}.tar"
|
||||
cp -R $(echo ${github_owner}-${deal_repo}-*/*)\
|
||||
cp -R $(echo ${gitlab_owner}-${deal_repo}-*/*)\
|
||||
"${stage_path}/"
|
||||
rm -rf "$(echo ${github_owner}-${deal_repo}-*)"
|
||||
rm -rf "$(echo ${gitlab_owner}-${deal_repo}-*)"
|
||||
rm "${deal_repo}.tar"
|
||||
fi
|
||||
return 0
|
||||
|
@ -44,15 +44,15 @@
|
||||
],
|
||||
[
|
||||
"--publish",
|
||||
"443:443",
|
||||
"45000:45000",
|
||||
"2222:22"
|
||||
"45443:45443",
|
||||
"45080:45080",
|
||||
"45022:22"
|
||||
],
|
||||
["--restart","always"],
|
||||
["--hostname","gitlab.adamo.network"],
|
||||
[
|
||||
"-e",
|
||||
"GITLAB_OMNIBUS_CONFIG=\"external_url 'http://gitlab.adamo.network:45000'; gitlab_rails['gitlab_shell_ssh_port'] = 45022\""
|
||||
"GITLAB_OMNIBUS_CONFIG=\"external_url 'http://gitlab.adamo.network:45080'; gitlab_rails['gitlab_shell_ssh_port'] = 45022\""
|
||||
]
|
||||
]
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user