mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
Extract shared func for checkenv and install scripts
This commit fixes #8622 by extract shared func into common.sh to avoid inconsistency in future. Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
parent
d277e713c6
commit
b9154a858b
2
Makefile
2
Makefile
@ -234,12 +234,14 @@ PACKAGE_OFFLINE_PARA=-zcvf harbor-offline-installer-$(PKGVERSIONTAG).tgz \
|
|||||||
$(HARBORPKG)/$(DOCKERIMGFILE).$(VERSIONTAG).tar.gz \
|
$(HARBORPKG)/$(DOCKERIMGFILE).$(VERSIONTAG).tar.gz \
|
||||||
$(HARBORPKG)/prepare \
|
$(HARBORPKG)/prepare \
|
||||||
$(HARBORPKG)/LICENSE $(HARBORPKG)/install.sh \
|
$(HARBORPKG)/LICENSE $(HARBORPKG)/install.sh \
|
||||||
|
$(HARBORPKG)/common.sh \
|
||||||
$(HARBORPKG)/harbor.yml
|
$(HARBORPKG)/harbor.yml
|
||||||
|
|
||||||
PACKAGE_ONLINE_PARA=-zcvf harbor-online-installer-$(PKGVERSIONTAG).tgz \
|
PACKAGE_ONLINE_PARA=-zcvf harbor-online-installer-$(PKGVERSIONTAG).tgz \
|
||||||
$(HARBORPKG)/prepare \
|
$(HARBORPKG)/prepare \
|
||||||
$(HARBORPKG)/LICENSE \
|
$(HARBORPKG)/LICENSE \
|
||||||
$(HARBORPKG)/install.sh \
|
$(HARBORPKG)/install.sh \
|
||||||
|
$(HARBORPKG)/common.sh \
|
||||||
$(HARBORPKG)/harbor.yml
|
$(HARBORPKG)/harbor.yml
|
||||||
|
|
||||||
DOCKERCOMPOSE_FILE_OPT=-f $(DOCKERCOMPOSEFILEPATH)/$(DOCKERCOMPOSEFILENAME)
|
DOCKERCOMPOSE_FILE_OPT=-f $(DOCKERCOMPOSEFILEPATH)/$(DOCKERCOMPOSEFILENAME)
|
||||||
|
131
make/checkenv.sh
131
make/checkenv.sh
@ -1,50 +1,6 @@
|
|||||||
#/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#docker version: 1.11.2
|
|
||||||
#docker-compose version: 1.7.1
|
|
||||||
#Harbor version: 0.4.5+
|
|
||||||
set +e
|
|
||||||
set -o noglob
|
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 -e
|
||||||
|
|
||||||
usage=$'Checking environment for harbor build and install. Include golang, docker and docker-compose.'
|
usage=$'Checking environment for harbor build and install. Include golang, docker and docker-compose.'
|
||||||
@ -61,89 +17,8 @@ while [ $# -gt 0 ]; do
|
|||||||
shift || true
|
shift || true
|
||||||
done
|
done
|
||||||
|
|
||||||
function check_golang {
|
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
if ! go version &> /dev/null
|
source $DIR/common.sh
|
||||||
then
|
|
||||||
warn "No golang package in your enviroment. You should use golang docker image build binary."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# docker has been installed and check its version
|
|
||||||
if [[ $(go version) =~ (([0-9]+)\.([0-9]+)([\.0-9]*)) ]]
|
|
||||||
then
|
|
||||||
golang_version=${BASH_REMATCH[1]}
|
|
||||||
golang_version_part1=${BASH_REMATCH[2]}
|
|
||||||
golang_version_part2=${BASH_REMATCH[3]}
|
|
||||||
|
|
||||||
# the version of golang does not meet the requirement
|
|
||||||
if [ "$golang_version_part1" -lt 1 ] || ([ "$golang_version_part1" -eq 1 ] && [ "$golang_version_part2" -lt 6 ])
|
|
||||||
then
|
|
||||||
warn "Better to upgrade golang package to 1.6.0+ or use golang docker image build binary."
|
|
||||||
return
|
|
||||||
else
|
|
||||||
note "golang version: $golang_version"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Failed to parse golang version."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_docker {
|
|
||||||
if ! docker --version &> /dev/null
|
|
||||||
then
|
|
||||||
error "Need to install docker(1.10.0+) first and run this script again."
|
|
||||||
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
|
|
||||||
if [ "$docker_version_part1" -lt 1 ] || ([ "$docker_version_part1" -eq 1 ] && [ "$docker_version_part2" -lt 10 ])
|
|
||||||
then
|
|
||||||
error "Need to upgrade docker package to 1.10.0+."
|
|
||||||
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
|
|
||||||
error "Need to install docker-compose(1.7.1+) by yourself first and run this script again."
|
|
||||||
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
|
|
||||||
if [ "$docker_compose_version_part1" -lt 1 ] || ([ "$docker_compose_version_part1" -eq 1 ] && [ "$docker_compose_version_part2" -lt 6 ])
|
|
||||||
then
|
|
||||||
error "Need to upgrade docker-compose package to 1.7.1+."
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
note "docker-compose version: $docker_compose_version"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
error "Failed to parse docker-compose version."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_golang
|
check_golang
|
||||||
check_docker
|
check_docker
|
||||||
|
132
make/common.sh
Normal file
132
make/common.sh
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#docker version: 17.06.0+
|
||||||
|
#docker-compose version: 1.18.0+
|
||||||
|
#golang version: 1.12.0+
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
function check_golang {
|
||||||
|
if ! go version &> /dev/null
|
||||||
|
then
|
||||||
|
warn "No golang package in your enviroment. You should use golang docker image build binary."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# docker has been installed and check its version
|
||||||
|
if [[ $(go version) =~ (([0-9]+)\.([0-9]+)([\.0-9]*)) ]]
|
||||||
|
then
|
||||||
|
golang_version=${BASH_REMATCH[1]}
|
||||||
|
golang_version_part1=${BASH_REMATCH[2]}
|
||||||
|
golang_version_part2=${BASH_REMATCH[3]}
|
||||||
|
|
||||||
|
# the version of golang does not meet the requirement
|
||||||
|
if [ "$golang_version_part1" -lt 1 ] || ([ "$golang_version_part1" -eq 1 ] && [ "$golang_version_part2" -lt 12 ])
|
||||||
|
then
|
||||||
|
warn "Better to upgrade golang package to 1.12.0+ or use golang docker image build binary."
|
||||||
|
return
|
||||||
|
else
|
||||||
|
note "golang version: $golang_version"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Failed to parse golang version."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_docker {
|
||||||
|
if ! docker --version &> /dev/null
|
||||||
|
then
|
||||||
|
error "Need to install docker(17.06.0+) first and run this script again."
|
||||||
|
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
|
||||||
|
if [ "$docker_version_part1" -lt 17 ] || ([ "$docker_version_part1" -eq 17 ] && [ "$docker_version_part2" -lt 6 ])
|
||||||
|
then
|
||||||
|
error "Need to upgrade docker package to 17.06.0+."
|
||||||
|
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
|
||||||
|
error "Need to install docker-compose(1.18.0+) by yourself first and run this script again."
|
||||||
|
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
|
||||||
|
if [ "$docker_compose_version_part1" -lt 1 ] || ([ "$docker_compose_version_part1" -eq 1 ] && [ "$docker_compose_version_part2" -lt 18 ])
|
||||||
|
then
|
||||||
|
error "Need to upgrade docker-compose package to 1.18.0+."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
note "docker-compose version: $docker_compose_version"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "Failed to parse docker-compose version."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
101
make/install.sh
101
make/install.sh
@ -1,50 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/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 -e
|
||||||
set +o noglob
|
set +o noglob
|
||||||
|
|
||||||
|
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
source $DIR/common.sh
|
||||||
|
|
||||||
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.
|
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.
|
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.
|
||||||
Please set --with-clair if needs enable Clair in Harbor
|
Please set --with-clair if needs enable Clair in Harbor
|
||||||
@ -86,62 +47,6 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function check_docker {
|
|
||||||
if ! docker --version &> /dev/null
|
|
||||||
then
|
|
||||||
error "Need to install docker(17.06.0+) first and run this script again."
|
|
||||||
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
|
|
||||||
if [ "$docker_version_part1" -lt 17 ] || ([ "$docker_version_part1" -eq 17 ] && [ "$docker_version_part2" -lt 6 ])
|
|
||||||
then
|
|
||||||
error "Need to upgrade docker package to 17.06.0+."
|
|
||||||
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
|
|
||||||
error "Need to install docker-compose(1.18.0+) by yourself first and run this script again."
|
|
||||||
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
|
|
||||||
if [ "$docker_compose_version_part1" -lt 1 ] || ([ "$docker_compose_version_part1" -eq 1 ] && [ "$docker_compose_version_part2" -lt 18 ])
|
|
||||||
then
|
|
||||||
error "Need to upgrade docker-compose package to 1.18.0+."
|
|
||||||
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
|
h2 "[Step $item]: checking installation environment ..."; let item+=1
|
||||||
check_docker
|
check_docker
|
||||||
check_dockercompose
|
check_dockercompose
|
||||||
|
Loading…
Reference in New Issue
Block a user