2016-10-19 08:32:00 +02:00
#!/bin/bash
set +e
set -o noglob
#
# Set Colors
#
bold = $( tput bold)
underline = $( tput sgr 0 1)
reset = $( tput sgr0)
red = $( tput setaf 1)
green = $( tput setaf 76)
white = $( tput setaf 7)
tan = $( tput setaf 202)
blue = $( tput setaf 25)
#
# Headers and Logging
#
underline( ) { printf " ${ underline } ${ bold } %s ${ reset } \n " " $@ "
}
h1( ) { printf " \n ${ underline } ${ bold } ${ blue } %s ${ reset } \n " " $@ "
}
h2( ) { printf " \n ${ underline } ${ bold } ${ white } %s ${ reset } \n " " $@ "
}
debug( ) { printf " ${ white } %s ${ reset } \n " " $@ "
}
info( ) { printf " ${ white } ➜ %s ${ reset } \n " " $@ "
}
success( ) { printf " ${ green } ✔ %s ${ reset } \n " " $@ "
}
error( ) { printf " ${ red } ✖ %s ${ reset } \n " " $@ "
}
warn( ) { printf " ${ tan } ➜ %s ${ reset } \n " " $@ "
}
bold( ) { printf " ${ bold } %s ${ reset } \n " " $@ "
}
note( ) { printf " \n ${ underline } ${ bold } ${ blue } Note: ${ reset } ${ blue } %s ${ reset } \n " " $@ "
}
set -e
set +o noglob
2019-03-18 08:07:19 +01:00
usage = $' Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https.
2018-08-09 08:55:31 +02:00
Please set --with-clair if needs enable Clair in Harbor
Please set --with-chartmuseum if needs enable Chartmuseum in Harbor'
2016-10-19 08:32:00 +02:00
item = 0
2017-03-09 12:02:44 +01:00
# notary is not enabled by default
with_notary = $false
2017-06-13 11:13:24 +02:00
# clair is not enabled by default
with_clair = $false
2018-07-19 10:47:05 +02:00
# chartmuseum is not enabled by default
with_chartmuseum = $false
2016-10-19 08:32:00 +02:00
while [ $# -gt 0 ] ; do
case $1 in
--help)
note " $usage "
exit 0; ;
2017-03-09 12:02:44 +01:00
--with-notary)
2017-06-13 11:13:24 +02:00
with_notary = true; ;
--with-clair)
2017-09-27 06:56:57 +02:00
with_clair = true; ;
2018-07-19 10:47:05 +02:00
--with-chartmuseum)
with_chartmuseum = true; ;
2016-10-19 08:32:00 +02:00
*)
note " $usage "
exit 1; ;
esac
shift || true
done
workdir = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
cd $workdir
2019-03-18 08:07:19 +01:00
# The hostname in harbor.yml has not been modified
if grep '^[[:blank:]]*hostname: reg.mydomain.com' & > /dev/null harbor.yml
2016-10-19 08:32:00 +02:00
then
warn " $usage "
exit 1
fi
function check_docker {
if ! docker --version & > /dev/null
then
2019-05-09 12:24:57 +02:00
error "Need to install docker(17.06.0+) first and run this script again."
2016-10-19 08:32:00 +02:00
exit 1
fi
# docker has been installed and check its version
if [ [ $( docker --version) = ~ ( ( [ 0-9] +) .( [ 0-9] +) .( [ 0-9] +) ) ] ]
then
docker_version = ${ BASH_REMATCH [1] }
docker_version_part1 = ${ BASH_REMATCH [2] }
docker_version_part2 = ${ BASH_REMATCH [3] }
# the version of docker does not meet the requirement
2019-05-09 12:24:57 +02:00
if [ " $docker_version " -lt 17 ] || ( [ " $docker_version " -eq 17 ] && [ " $docker_version_part1 " -lt 6 ] )
2016-10-19 08:32:00 +02:00
then
2019-05-09 12:24:57 +02:00
error "Need to upgrade docker package to 17.06.0+."
2016-10-19 08:32:00 +02:00
exit 1
else
note " docker version: $docker_version "
fi
else
error "Failed to parse docker version."
exit 1
fi
}
function check_dockercompose {
if ! docker-compose --version & > /dev/null
then
2019-05-09 12:24:57 +02:00
error "Need to install docker-compose(1.18.0+) by yourself first and run this script again."
2016-10-19 08:32:00 +02:00
exit 1
fi
# docker-compose has been installed, check its version
if [ [ $( docker-compose --version) = ~ ( ( [ 0-9] +) .( [ 0-9] +) .( [ 0-9] +) ) ] ]
then
docker_compose_version = ${ BASH_REMATCH [1] }
docker_compose_version_part1 = ${ BASH_REMATCH [2] }
docker_compose_version_part2 = ${ BASH_REMATCH [3] }
# the version of docker-compose does not meet the requirement
2019-05-09 12:24:57 +02:00
if [ " $docker_compose_version_part1 " -lt 1 ] || ( [ " $docker_compose_version_part1 " -eq 1 ] && [ " $docker_compose_version_part2 " -lt 18 ] )
2016-10-19 08:32:00 +02:00
then
2019-05-09 12:24:57 +02:00
error "Need to upgrade docker-compose package to 1.18.0+."
2016-10-19 08:32:00 +02:00
exit 1
else
note " docker-compose version: $docker_compose_version "
fi
else
error "Failed to parse docker-compose version."
exit 1
fi
}
h2 " [Step $item ]: checking installation environment ... " ; let item += 1
check_docker
check_dockercompose
2017-04-05 08:48:29 +02:00
if [ -f harbor*.tar.gz ]
2016-10-19 08:32:00 +02:00
then
h2 " [Step $item ]: loading Harbor images ... " ; let item += 1
2017-04-05 08:48:29 +02:00
docker load -i ./harbor*.tar.gz
2016-10-19 08:32:00 +02:00
fi
echo ""
h2 " [Step $item ]: preparing environment ... " ; let item += 1
if [ -n " $host " ]
then
2019-03-22 12:04:40 +01:00
sed " s/^hostname: .*/hostname: $host /g " -i ./harbor.yml
2016-10-19 08:32:00 +02:00
fi
2017-06-13 11:13:24 +02:00
prepare_para =
2018-08-27 12:24:21 +02:00
if [ $with_notary ]
2017-03-09 12:02:44 +01:00
then
2017-06-13 11:13:24 +02:00
prepare_para = " ${ prepare_para } --with-notary "
2017-03-09 12:02:44 +01:00
fi
2017-12-21 09:45:20 +01:00
if [ $with_clair ]
2017-06-13 11:13:24 +02:00
then
prepare_para = " ${ prepare_para } --with-clair "
fi
2018-07-19 10:47:05 +02:00
if [ $with_chartmuseum ]
then
prepare_para = " ${ prepare_para } --with-chartmuseum "
fi
2017-06-13 11:13:24 +02:00
./prepare $prepare_para
2016-10-19 08:32:00 +02:00
echo ""
2018-11-15 04:09:57 +01:00
if [ -n " $( docker-compose ps -q) " ]
2017-03-09 12:02:44 +01:00
then
2017-06-13 11:13:24 +02:00
note "stopping existing Harbor instance ..."
2018-11-15 04:09:57 +01:00
docker-compose down -v
2017-03-09 12:02:44 +01:00
fi
2017-06-13 11:13:24 +02:00
echo ""
h2 " [Step $item ]: starting Harbor ... "
2018-11-15 04:09:57 +01:00
docker-compose up -d
2016-10-19 08:32:00 +02:00
protocol = http
hostname = reg.mydomain.com
2019-04-15 08:32:36 +02:00
if [ -n " $( grep '^[^#]*https:' ./harbor.yml) " ]
2016-10-19 08:32:00 +02:00
then
2019-04-02 14:08:26 +02:00
protocol = https
2016-10-19 08:32:00 +02:00
fi
2019-03-18 08:07:19 +01:00
if [ [ $( grep '^[[:blank:]]*hostname:' ./harbor.yml) = ~ hostname:[ [ :blank:] ] *( .*) ] ]
2016-10-19 08:32:00 +02:00
then
hostname = ${ BASH_REMATCH [1] }
fi
echo ""
success $" ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at ${ protocol } ://${ hostname } .
2018-08-10 08:16:59 +02:00
For more details, please visit https://github.com/goharbor/harbor .
2016-10-19 08:32:00 +02:00
"