Wizzard working out of docker
This commit is contained in:
parent
81b6097351
commit
c35290ae2d
|
@ -2,8 +2,7 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
volume_prefix=cloner
|
dir_prefix=cloner
|
||||||
mirror_image="valicek1/repo-cloner-mirror"
|
|
||||||
|
|
||||||
function die(){
|
function die(){
|
||||||
echo $@ 1>&2
|
echo $@ 1>&2
|
||||||
|
@ -15,11 +14,7 @@ function checkProjectName(){
|
||||||
name=$1
|
name=$1
|
||||||
# should not be empty
|
# should not be empty
|
||||||
[ -n "$read_project_name" ] || die "Empty project name is not allowed"
|
[ -n "$read_project_name" ] || die "Empty project name is not allowed"
|
||||||
set +e
|
if [ -d /data/$dir_prefix-$name ]
|
||||||
docker volume inspect $volume_prefix-$1 > /dev/null 2>&1
|
|
||||||
exists=$?
|
|
||||||
set -e
|
|
||||||
if [ $exists -eq 0 ]
|
|
||||||
then
|
then
|
||||||
die "Target volume for project '$name' exists - please try again!"
|
die "Target volume for project '$name' exists - please try again!"
|
||||||
fi
|
fi
|
||||||
|
@ -94,19 +89,7 @@ function reuseSSHKey(){
|
||||||
rm $scratch
|
rm $scratch
|
||||||
echo "Checking key..."
|
echo "Checking key..."
|
||||||
chmod 0600 $keyfile
|
chmod 0600 $keyfile
|
||||||
ssh-keygen -y -f $keyfile -P ""
|
ssh-keygen -y -f $keyfile -P "" || true # will fail in the end, so script will continue and clean up the mess
|
||||||
}
|
|
||||||
|
|
||||||
function createVolume(){
|
|
||||||
# create volume $1
|
|
||||||
local volname=$1
|
|
||||||
|
|
||||||
echo "Creating docker volume $volname"
|
|
||||||
docker volume create $volname > /dev/null
|
|
||||||
|
|
||||||
echo "Populating volume with stuff..."
|
|
||||||
local filler="cloner-creator-filler-$(hostname)"
|
|
||||||
tar c /data | docker run -v $volname:/data -i --name $filler --rm busybox:latest tar -C / -x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# start reading vars
|
# start reading vars
|
||||||
|
@ -146,9 +129,10 @@ else
|
||||||
read_submodule_limit=N
|
read_submodule_limit=N
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
root=/data/$dir_prefix-$read_project_name
|
||||||
# start generating config
|
# start generating config
|
||||||
mkdir -p /data/config
|
mkdir -p $root/config
|
||||||
createConfigFile /data/config/cloner.cfg
|
createConfigFile $root/config/cloner.cfg
|
||||||
|
|
||||||
# use ssh config?
|
# use ssh config?
|
||||||
echo -n "Would you like to use SSH auth? ([C]reate new key/[U]se existing key/[N]o) [C/u/n]: "
|
echo -n "Would you like to use SSH auth? ([C]reate new key/[U]se existing key/[N]o) [C/u/n]: "
|
||||||
|
@ -158,37 +142,34 @@ read read_ssh
|
||||||
|
|
||||||
# ssh resolutions?
|
# ssh resolutions?
|
||||||
# create dir if needed
|
# create dir if needed
|
||||||
[[ "$read_ssh" =~ ^[nN]$ ]] || mkdir -p /data/config/auth/ssh
|
[[ "$read_ssh" =~ ^[nN]$ ]] || mkdir -p $root/config/auth/ssh
|
||||||
|
|
||||||
# generate new key
|
# generate new key
|
||||||
if [[ "$read_ssh" =~ ^[Cc]$ ]]
|
if [[ "$read_ssh" =~ ^[Cc]$ ]]
|
||||||
then
|
then
|
||||||
# create key
|
# create key
|
||||||
generateSSHKey /data/config/auth/ssh "cloner-deploy-key-$read_project_name"
|
generateSSHKey $root/config/auth/ssh "cloner-deploy-key-$read_project_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# use existing key
|
# use existing key
|
||||||
if [[ "$read_ssh" =~ ^[Uu]$ ]]
|
if [[ "$read_ssh" =~ ^[Uu]$ ]]
|
||||||
then
|
then
|
||||||
# load key
|
# load key
|
||||||
reuseSSHKey /data/config/auth/ssh/id_rsa
|
reuseSSHKey $root/config/auth/ssh/id_rsa
|
||||||
fi
|
fi
|
||||||
|
|
||||||
volume_name=$volume_prefix-$read_project_name
|
|
||||||
createVolume $volume_name
|
|
||||||
|
|
||||||
echo "First run - initialization of repos..."
|
echo "First run - initialization of repos..."
|
||||||
if ! docker run -it -v $volume_name:/data --name cloner-runner-$read_project_name --rm $mirror_image
|
if ! env BASE=$root run-checker
|
||||||
then
|
then
|
||||||
echo -n "First run failed - remove image? [Y/n]"
|
echo -n "First run failed - remove directory? [Y/n]"
|
||||||
read read_cleanup
|
read read_cleanup
|
||||||
[ -n "$read_cleanup" ] || read_cleanup=Y
|
[ -n "$read_cleanup" ] || read_cleanup=Y
|
||||||
if [[ "$read_cleanup" =~ ^[Yy]$ ]]
|
if [[ "$read_cleanup" =~ ^[Yy]$ ]]
|
||||||
then
|
then
|
||||||
docker volume rm $volume_name
|
rm -Rf $root
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Setup has finished!"
|
echo "Setup has finished!"
|
||||||
|
touch $root/.enabled
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user