-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall-artifactory.sh
executable file
·141 lines (113 loc) · 4.77 KB
/
install-artifactory.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
#!/bin/bash
set +e
echo "$0" | grep "\(/install.sh$\)\|\(/uninstall.sh$\)" >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo -e "\nERROR! This script cannot be run stand-alone.\n"
exit 1
fi
set -e
echo -e "\n###############"
echo -e "# Artifactory #"
echo -e "###############\n"
install() {
# Values to interpolate
alpine_image_version=${ALPINE_IMAGE_VERSION:-3.8}
busybox_image_version=${BUSYBOX_IMAGE_VERSION:-1.30.1 }
artifactory_image_version=${ARTIFACTORY_IMAGE_VERSION:-6.8.7}
artifactory_nginx_image_version=${ARTIFACTORY_NGINX_IMAGE_VERSION:-6.8.7}
artifactory_chart_version=${ARTIFACTORY_CHART_VERSION:-7.12.13}
pgsql_instance_name=artifactory-db
postgresql_pvc_size=${POSTGRESQL_VOLUME_SIZE:-50Gi}
db_user=artifactory
db_password=artifactory
db_name=artifactory
artifactory_pvc_size=${ARTIFACTORY_PVC_SIZE:-20Gi}
# Artifactory Install Paths
postgresql_install_config=${install_config}/config/artifactory-db
mkdir -p ${postgresql_install_config}
artifactory_config=${script_dir}/config/artifactory
artifactory_install_config=${install_config}/config/artifactory
mkdir -p ${artifactory_install_config}
# Interpolate k8s and helm resource declaration files for postgresql chart
eval "echo \"$(cat ${postgresql_config}/sc-${iaas}.yml)\"" \
> ${postgresql_install_config}/sc.yml
eval "echo \"$(cat ${postgresql_config}/pvc.yml)\"" \
> ${postgresql_install_config}/pvc.yml
eval "echo \"$(cat ${postgresql_config}/chart-values.yml)\"" \
> ${postgresql_install_config}/chart-values.yml
# Create k8s and helm resources for artifactory postgresql db
kubectl get storageclass $pgsql_instance_name >/dev/null 2>&1 || \
kubectl create --filename ${postgresql_install_config}/sc.yml
kubectl get persistentvolumeclaim $pgsql_instance_name --namespace ${environment} >/dev/null 2>&1 || \
kubectl create --filename ${postgresql_install_config}/pvc.yml
if [[ -z `echo -e "$helm_deployments" | awk "/^${pgsql_instance_name}\s+/{ print \$1 }"` ]]; then
echo -e "Installing postgresql helm chart fot '$pgsql_instance_name'..."
helm install \
--values ${postgresql_install_config}/chart-values.yml \
--name $pgsql_instance_name \
--namespace $environment \
--version $postgresql_chart_version \
releng/postgresql
else
echo -e "Upgrading postgresql helm chart for '$pgsql_instance_name'..."
helm upgrade \
--values ${postgresql_install_config}/chart-values.yml \
--version $postgresql_chart_version \
$pgsql_instance_name releng/postgresql
fi
service_info=$(kubectl get service ${pgsql_instance_name}-postgresql --namespace ${environment} | tail -1)
pgsql_host=$(echo $service_info | awk '{ print $3 }')
pgsql_port=$(echo $service_info | awk '{ print substr($5,0,index($5,"/")-1) }')
# Interpolate k8s and helm resource declaration files for artifactory chart
eval "echo \"$(cat ${artifactory_config}/sc-${iaas}.yml)\"" \
> ${artifactory_install_config}/sc.yml
eval "echo \"$(cat ${artifactory_config}/pvc.yml)\"" \
> ${artifactory_install_config}/pvc.yml
eval "echo \"$(cat ${artifactory_config}/chart-values.yml)\"" \
> ${artifactory_install_config}/chart-values.yml
# Create k8s and helm resources for artifactory
kubectl get storageclass artifactory >/dev/null 2>&1 || \
kubectl create --filename ${artifactory_install_config}/sc.yml
kubectl get persistentvolumeclaim artifactory --namespace ${environment} >/dev/null 2>&1 || \
kubectl create --filename ${artifactory_install_config}/pvc.yml
if [[ -z `echo -e "$helm_deployments" | awk '/^artifactory\s+/{ print $1 }'` ]]; then
echo -e "Installing artifactory helm chart..."
helm install \
--values ${artifactory_install_config}/chart-values.yml \
--name artifactory \
--namespace $environment \
--version $artifactory_chart_version \
releng/artifactory
else
echo -e "Upgrading artifactory helm chart..."
helm upgrade \
--values ${artifactory_install_config}/chart-values.yml \
--version $artifactory_chart_version \
artifactory releng/artifactory
fi
}
uninstall() {
set +e
# Delete k8s and helm resources of artifactory postgresql
echo -e "\nDeleting artifactory db helm chart..."
helm delete --purge artifactory-db
kubectl delete persistentvolumeclaim artifactory-db --namespace $environment
kubectl delete storageclass artifactory-db
# Delete k8s and helm resources of artifactory
echo -e "\nDeleting artifactory helm chart..."
helm delete --purge artifactory
kubectl delete persistentvolumeclaim artifactory --namespace $environment
kubectl delete storageclass artifactory
set -e
}
case "$1" in
install)
install
;;
uninstall)
uninstall
;;
*)
echo "ERROR! Invalid invocation of install script."
exit 1
esac