2016-10-19 08:32:00 +02:00
#!/bin/bash
set -e
2019-08-21 18:50:54 +02:00
DIR = " $( cd " $( dirname " $0 " ) " && pwd ) "
source $DIR /common.sh
2019-10-18 11:55:29 +02:00
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.
2023-03-28 11:16:17 +02:00
Please set --with-trivy if needs enable Trivy in Harbor.
2023-07-27 04:41:05 +02:00
Please do NOT set --with-chartmuseum, as chartmusuem has been deprecated and removed.
Please do NOT set --with-notary, as notary has been deprecated and removed.'
2016-10-19 08:32:00 +02:00
item = 0
2020-11-09 12:36:17 +01:00
# clair is deprecated
with_clair = $false
2020-02-10 16:46:26 +01:00
# trivy is not enabled by default
with_trivy = $false
2018-07-19 10:47:05 +02:00
2022-06-21 10:55:07 +02:00
# flag to using docker compose v1 or v2, default would using v1 docker-compose
DOCKER_COMPOSE = docker-compose
2016-10-19 08:32:00 +02:00
while [ $# -gt 0 ] ; do
case $1 in
--help)
note " $usage "
exit 0; ;
2020-02-10 16:46:26 +01:00
--with-trivy)
with_trivy = 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-10-23 08:08:15 +02:00
h2 " [Step $item ]: checking if docker is installed ... " ; let item += 1
2016-10-19 08:32:00 +02:00
check_docker
2019-10-23 08:08:15 +02:00
h2 " [Step $item ]: checking docker-compose is installed ... " ; let item += 1
check_dockercompose
2016-10-19 08:32:00 +02:00
2019-11-05 04:22:30 +01:00
if [ -f harbor*.tar.gz ]
then
h2 " [Step $item ]: loading Harbor images ... " ; let item += 1
docker load -i ./harbor*.tar.gz
fi
echo ""
2016-10-19 08:32:00 +02:00
h2 " [Step $item ]: preparing environment ... " ; let item += 1
if [ -n " $host " ]
then
2019-10-23 08:08:15 +02:00
sed " s/^hostname: .*/hostname: $host /g " -i ./harbor.yml
2016-10-19 08:32:00 +02:00
fi
2019-10-23 08:08:15 +02:00
h2 " [Step $item ]: preparing harbor configs ... " ; let item += 1
2017-06-13 11:13:24 +02:00
prepare_para =
2020-02-10 16:46:26 +01:00
if [ $with_trivy ]
then
prepare_para = " ${ prepare_para } --with-trivy "
fi
2018-07-19 10:47:05 +02:00
2017-06-13 11:13:24 +02:00
./prepare $prepare_para
2016-10-19 08:32:00 +02:00
echo ""
2022-06-21 10:55:07 +02:00
if [ -n " $DOCKER_COMPOSE ps -q " ]
then
note "stopping existing Harbor instance ..."
$DOCKER_COMPOSE down -v
2016-10-19 08:32:00 +02:00
fi
echo ""
2019-10-23 08:08:15 +02:00
h2 " [Step $item ]: starting Harbor ... "
2022-06-21 10:55:07 +02:00
$DOCKER_COMPOSE up -d
2016-10-19 08:32:00 +02:00
2019-10-23 08:08:15 +02:00
success $"----Harbor has been installed and started successfully.----"