-
Notifications
You must be signed in to change notification settings - Fork 710
/
Copy pathsetup-harbor.sh
executable file
·149 lines (137 loc) · 4.21 KB
/
setup-harbor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
# Copyright 2020-2022 the Kubeapps contributors.
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
# Constants
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
RESET='\033[0m'
GREEN='\033[38;5;2m'
RED='\033[38;5;1m'
YELLOW='\033[38;5;3m'
# Load Libraries
# shellcheck disable=SC1090
. "${ROOT_DIR}/script/libtest.sh"
# shellcheck disable=SC1090
. "${ROOT_DIR}/script/liblog.sh"
# Axiliar functions
print_menu() {
local script
script=$(basename "${BASH_SOURCE[0]}")
log "${RED}NAME${RESET}"
log " $(basename -s .sh "${BASH_SOURCE[0]}")"
log ""
log "${RED}SYNOPSIS${RESET}"
log " $script [${YELLOW}-dh${RESET}] [${YELLOW}-n ${GREEN}\"namespace\"${RESET}] [${YELLOW}--disable-clair] [${YELLOW}--disable-notary]"
log ""
log "${RED}DESCRIPTION${RESET}"
log " Script to setup Harbor on your K8s cluster."
log ""
log " The options are as follow:"
log ""
log " ${YELLOW}-n, --namespace ${GREEN}[namespace]${RESET} Namespace to use for Harbor."
log " ${YELLOW}--disable-chartmuseum${RESET} Disable ChartMuseum."
log " ${YELLOW}--disable-clair${RESET} Disable Clair."
log " ${YELLOW}--disable-notary${RESET} Disable Notary."
log " ${YELLOW}-h, --help${RESET} Print this help menu."
log " ${YELLOW}-u, --dry-run${RESET} Enable \"dry run\" mode."
log ""
log "${RED}EXAMPLES${RESET}"
log " $script --help"
log " $script --namespace \"harbor\""
log " $script --namespace \"harbor\" --disable-clair"
log ""
}
namespace="harbor"
disable_chartmuseum=0
disable_clair=0
disable_notary=0
help_menu=0
dry_run=0
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h | --help)
help_menu=1
;;
-u | --dry-run)
dry_run=1
;;
--disable-chartmuseum)
disable_chartmuseum=1
;;
--disable-clair)
disable_clair=1
;;
--disable-notary)
disable_notary=1
;;
-n | --namespace)
shift
namespace="${1:?missing namespace}"
;;
*)
error "Invalid command line flag $1" >&2
exit 1
;;
esac
shift
done
if [[ "$help_menu" -eq 1 ]]; then
print_menu
exit 0
fi
# Harbor values
values="$(
cat <<EOF
service:
tls:
enabled: false
chartmuseum:
enabled: $([[ "$disable_chartmuseum" -eq 0 ]] && echo "true" || echo "false")
clair:
enabled: $([[ "$disable_clair" -eq 0 ]] && echo "true" || echo "false")
notary:
enabled: $([[ "$disable_notary" -eq 0 ]] && echo "true" || echo "false")
EOF
)"
if [[ "$dry_run" -eq 1 ]]; then
info "DRY RUN mode enabled!"
info "Namespace: $namespace"
info "Generated values.yaml:"
printf '#####\n\n%s\n\n#####\n' "$values"
exit 0
fi
# Install Harbor
info "Using the values.yaml below:"
printf '#####\n\n%s\n\n#####\n' "$values"
info "Installing Harbor in namespace '$namespace'..."
silence kubectl create ns "$namespace"
silence helm install harbor \
--namespace "$namespace" \
-f <(echo "$values") \
oci://registry-1.docker.io/bitnamicharts/harbor
# Wait for Harbor components
info "Waiting for Harbor components to be ready..."
deployments=(
"harbor-core"
"harbor-jobservice"
"harbor-nginx"
"harbor-portal"
"harbor-registry"
)
[[ "$disable_chartmuseum" -eq 0 ]] && deployments=("harbor-chartmuseum" "${deployments[@]}")
[[ "$disable_clair" -eq 0 ]] && deployments=("harbor-clair" "${deployments[@]}")
[[ "$disable_notary" -eq 0 ]] && deployments=("harbor-notary-server" "harbor-notary-signer" "${deployments[@]}")
for dep in "${deployments[@]}"; do
k8s_wait_for_deployment "$namespace" "$dep"
info "Deployment ${dep} ready!"
done
echo
info "Use this command for port-forwarding to Harbor:"
info "kubectl port-forward --namespace $namespace svc/harbor 8888:80 >/dev/null 2>&1 &"
info "Harbor URL: http://127.0.0.1:8888/"
info "Harbor credentials"
info " - username: admin"
info " - Password: $(kubectl get secret harbor-core-envvars --namespace "$namespace" -o jsonpath="{.data.HARBOR_ADMIN_PASSWORD}" | base64 --decode)"
echo