-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpatch
executable file
·105 lines (85 loc) · 2.87 KB
/
patch
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
#!/bin/bash
set -e
cd $(dirname $0)/..
if [[ -z ${CHART} ]]; then
# Assume that the chart is the main one found in this repository
CHART="./charts/ui-plugin-server"
fi
if ! [[ -d ${CHART} ]]; then
echo "${CHART} is not a directory"
exit 1
fi
if ! [[ -f ${CHART}/Chart.yaml ]]; then
echo "${CHART} is not a valid Helm chart: could not find Chart.yaml"
exit 1
fi
if ! [[ -f ${CHART}/values.yaml ]]; then
echo "${CHART} does not have default values: could not find values.yaml"
exit 1
fi
if [[ -z ${REGISTRY} ]]; then
# By default, we assume you are using DockerHub
REGISTRY=""
fi
# Remove trailing slash if it exists
REGISTRY=${REGISTRY%/}
if [[ -z ${ORG} ]]; then
# By default, we assume this is a plugin hosted by Rancher
ORG=rancher
fi
if [[ -z ${PACKAGE_JSON} ]]; then
PACKAGE_JSON=plugin/package.json
fi
if ! [[ -f ${PACKAGE_JSON} ]]; then
echo "Could not find package.json at path ${PACKAGE_JSON}"
exit 1
fi
if [[ -z ${REPO} ]]; then
REPO=$(cat ${PACKAGE_JSON} | jq ".name" | tr -d '"')
fi
if [[ -z ${TAG} ]]; then
TAG=$(cat ${PACKAGE_JSON} | jq ".version" | tr -d '"')
fi
DESCRIPTION=$(cat ${PACKAGE_JSON} | jq ".description" | tr -d '"')
ICON=$(cat ${PACKAGE_JSON} | jq ".icon" | tr -d '"')
KEYWORDS=$(cat ${PACKAGE_JSON} | jq ".keywords")
HOME=$(cat ${PACKAGE_JSON} | jq ".homepage" | tr -d '"')
if [[ -z ${ORG} ]] || [[ -z ${REPO} ]] || [[ -z ${TAG} ]]; then
echo "Usage: [CHART=charts/ui-plugin-server] [REGISTRY=""] [ORG=rancher] [REPO=<override-repo>] [TAG=<override-tag>] [PACKAGE_JSON=plugin/package.json] ./scripts/patch <chart>"
exit 1
fi
# Edit Chart information to match plugin using yq
yq -i eval ".name = \"${REPO}\"" $CHART/Chart.yaml
yq -i eval ".appVersion = \"${TAG}\"" $CHART/Chart.yaml
yq -i eval ".version = \"${TAG}\"" $CHART/Chart.yaml
if [[ -n "${DESCRIPTION}" ]]; then
if [[ "${DESCRIPTION}" == "null" ]]; then
yq -i eval "del(.description)" $CHART/Chart.yaml
else
yq -i eval ".description = \"${DESCRIPTION}\"" $CHART/Chart.yaml
fi
fi
if [[ -n "${ICON}" ]]; then
if [[ "${ICON}" == "null" ]]; then
yq -i eval "del(.icon)" $CHART/Chart.yaml
else
yq -i eval ".icon = \"${ICON}\"" $CHART/Chart.yaml
fi
fi
if [[ -n "${KEYWORDS}" ]]; then
if [[ "${KEYWORDS}" == "null" ]]; then
yq -i eval "del(.keywords)" $CHART/Chart.yaml
else
yq -i -I2 eval ".keywords = ${KEYWORDS}" $CHART/Chart.yaml
fi
fi
if [[ -n "${HOME}" ]]; then
if [[ "${HOME}" == "null" ]]; then
yq -i eval "del(.home)" $CHART/Chart.yaml
else
yq -i eval ".home = \"${HOME}\"" $CHART/Chart.yaml
fi
fi
yq -i eval ".global.cattle.systemDefaultRegistry = \"${REGISTRY}\"" $CHART/values.yaml
yq -i eval ".pluginServer.image.repository = \"${ORG}/${REPO}\"" $CHART/values.yaml
yq -i eval ".pluginServer.image.tag = \"${TAG}\"" $CHART/values.yaml