Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit f621def

Browse files
authored
Merge pull request #5 from codefresh-io/validator
Validator
2 parents 1fdc52a + deff810 commit f621def

21 files changed

+877
-305
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
assets
44
.kube
55

6+
tmp/
67
# values.yaml
7-
values.yaml
8+
/values.yaml
89

910
# decrypted files
1011
**/*-dec.*

README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,39 @@ Before running `cf-onprem` script it is needed to:
1212
* make configuration changes specific for each customer
1313

1414
There are three files that customize `codefresh` chart deployment:
15-
* `sa-dec.json` contains GCP service account that enables a customer to pull codefresh images
16-
* `values.yaml` contains different parameters for chart customization
17-
* `values-dec.yaml` contains secrets such as `githubClientSecret`, etc.
15+
* `values.yaml.tpl` contains template of values.yaml for different parameters for chart customization
1816

19-
Also to be able to encrypt `*-dec.*` files and decrypt `*-enc.*` files `aws cli` should be configured with permissions to use AWS KMS service and [sops](https://github.com/mozilla/sops/releases) binary installed on your system.
2017

2118
### How to run
2219
1. Clone [onprem](https://github.com/codefresh-io/onprem) repository
2320
```
2421
git clone [email protected]:codefresh-io/onprem.git
2522
cd onprem
2623
```
27-
2. Decrypt `sa-enc.json` and `values-enc.yaml` files
28-
```
29-
./sops.sh -d
30-
```
31-
3. Make configuration changes in `sa-dec.json`, `values.yaml`, `values-dec.yaml` files and customize variables in `env-vars` file
32-
4. Run `cf-onprem` script
33-
5. If it is needed to upload new configuration into remote repository then encrypt `sa-dec.json`, `values-dec.yaml` files
34-
```
35-
./sops.sh -e
36-
```
37-
6. Commit and push changes
38-
```
39-
git push origin master
40-
```
24+
2. cp `values.yaml.tpl` `values.yaml`
25+
26+
3. Edit values.yaml
27+
Mandatory to set `global.appUrl` and `firebaseToken`
28+
29+
##### Running on local volumes
30+
Codefresh can run on local volumes - https://kubernetes.io/docs/concepts/storage/volumes/#local
31+
32+
To create local volumes edit `local-volumes/values.yaml`, set:
33+
- defaultNodeSelector
34+
- mkdirPods.nodes
35+
36+
then run `local-volumes/create-local-pvcs.sh`
37+
edit values.yaml and set the values for `existingPvc`s
38+
39+
4. Validate values and cluster
40+
`./run-validator.sh`
41+
It will validate:
42+
- values.yaml
43+
- ability to launch persistent services on specified storage classes
44+
- ability to launch persistent services on specified existing pvcs
45+
- To do: validating networks, dns, loadbalances, ingress
46+
47+
5. run Intaller:
48+
```
49+
./cf-onprem [ --web-tls-key certs/key.pem --web-tls-cert certs/cert.pem ]
50+
```

cf-onprem

Lines changed: 26 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
#
33

44
#set -x
5-
6-
msg() { echo -e "\e[32mINFO [$(date +%F\ %T)] ---> $1\e[0m"; }
7-
warning() { echo -e "\e[33mWARNING [$(date +%F\ %T)] ---> $1\e[0m"; }
8-
err() { echo -e "\e[31mERR [$(date +%F\ %T)] ---> $1\e[0m" ; exit 1; }
5+
DIR=$(dirname $0)
6+
source ${DIR}/scripts/helpers.sh
97

108
if [ -f "./env-vars" ]; then
119
. ./env-vars
1210
fi
1311

14-
readonly HELM_VERSION="${CF_HELM_VERSION:-2.10.0}"
1512
readonly CHANNEL="${CF_HELM_CHANNEL:-dev}"
1613
readonly CODEFRESH_REPOSITORY=http://charts.codefresh.io/${CHANNEL}
1714

18-
#export KUBECONFIG=./.kube/config
15+
readonly RELEASE=cf
1916

2017
readonly WORKING_DIR="$(dirname "$0")"
2118
readonly SERVICE_ACCOUNT="${WORKING_DIR}/sa.json"
@@ -29,144 +26,6 @@ usage() {
2926
exit 0
3027
}
3128

32-
check() { command -v $1 >/dev/null 2>&1 || err "$1 binary is required!"; }
33-
34-
ver() { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); }
35-
36-
exists() {
37-
if command -v $1 >/dev/null 2>&1; then
38-
msg "$1 binary installed"
39-
else
40-
warning "Please install $1 to proceed"
41-
exit 1
42-
fi
43-
}
44-
45-
run_as_root() {
46-
if [[ $EUID > 0 ]]; then
47-
err "Please run as root/sudo"
48-
exit 1
49-
fi
50-
}
51-
52-
approveContext() {
53-
msg "Your kubectl is configured with the following context: "
54-
kubectl config current-context
55-
read -r -p "Are you sure you want to continue? [y/N] " response
56-
57-
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
58-
then
59-
msg "No problem, continuing with the script..."
60-
else
61-
msg "Exiting..."
62-
exit 0
63-
fi
64-
}
65-
66-
checkHelmInstalled() {
67-
if command -v $1 >/dev/null 2>&1; then
68-
helm_version=$(helm version --client --short | sed 's/.*\: v//' | sed 's/+.*//')
69-
msg "helm is already installed and has version v$helm_version"
70-
[ $(ver $helm_version) -lt $(ver $HELM_VERSION) ] && \
71-
err "You have older helm version than required. Please upgrade to v$HELM_VERSION or newer !"
72-
else
73-
warning "helm is not installed"
74-
if [[ ! "$YES" == 'true' ]]; then
75-
read -p "Do you want to install helm ? [y/n] " yn
76-
case ${yn} in
77-
y|Y)
78-
helmInstall
79-
;;
80-
*)
81-
err "Need helm to deploy Codefresh app ! Exiting..."
82-
#exit 1
83-
;;
84-
esac
85-
else
86-
helmInstall
87-
fi
88-
fi
89-
}
90-
91-
helmInstall() {
92-
msg "Downloading and installing helm..."
93-
<< ////
94-
case "$(uname -s)" in
95-
Linux)
96-
os=linux
97-
;;
98-
Darwin)
99-
os=darwin
100-
;;
101-
*)
102-
;;
103-
esac
104-
////
105-
wget https://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-${os}-amd64.tar.gz -P /tmp/
106-
tar xvf /tmp/helm-v${HELM_VERSION}-${os}-amd64.tar.gz -C /tmp/
107-
chmod +x /tmp/${os}-amd64/helm
108-
sudo mv /tmp/${os}-amd64/helm /usr/local/bin/
109-
rm -rf /tmp/helm-v${HELM_VERSION}-${os}-amd64 /tmp/helm-v${HELM_VERSION}-${os}-amd64.tar.gz
110-
}
111-
112-
checkTillerInstalled() {
113-
status=$(kubectl -nkube-system get pod -l app=helm -l name=tiller -o=go-template --template='{{ range $i, $v := .items }}{{ if eq $v.status.phase "Running" }}{{ $v.status.phase }}{{ end }}{{ end }}')
114-
if [ "$status" == "Running" ]; then
115-
msg "Tiller is installed and running"
116-
helm init -c
117-
helm_version=$(helm version --client --short | sed 's/.*\: v//' | sed 's/+.*//')
118-
tiller_version=$(helm version --server --short | sed 's/.*\: v//' | sed 's/+.*//')
119-
if [[ ! "$YES" == 'true' ]] && [ $(ver $tiller_version) -lt $(ver $helm_version) ]; then
120-
warning "You're running helm v$helm_version but tiller has v$tiller_version."
121-
read -p " Do you want to upgrade tiller to v$helm_version ? [y/n] " yn
122-
case ${yn} in
123-
y|Y)
124-
kubectl create -f ./tiller-rbac-config.yaml > /dev/null 2>&1
125-
helm init --upgrade --service-account tiller --wait
126-
;;
127-
*)
128-
err "You need to upgrade tiller ! Exiting..."
129-
;;
130-
esac
131-
fi
132-
if [[ "$YES" == 'true' ]] && [ $(ver $tiller_version) -lt $(ver $helm_version) ]; then
133-
err "You're running helm v$helm_version but tiller has v$tiller_version . You need to upgrade tiller ! Exiting..."
134-
fi
135-
else
136-
warning "Unable to determine tiller at its default location."
137-
if [[ ! "$YES" == 'true' ]]; then
138-
read -p " Do you want to deploy tiller ? [y/n] " yn
139-
case ${yn} in
140-
y|Y)
141-
kubectl create -f ./tiller-rbac-config.yaml
142-
helm init --service-account tiller --wait
143-
;;
144-
*)
145-
err "Need to deploy tiller ! Exiting..."
146-
exit 1
147-
;;
148-
esac
149-
else
150-
kubectl create -f ./tiller-rbac-config.yaml
151-
helm init --service-account tiller --wait
152-
fi
153-
fi
154-
155-
}
156-
157-
checkTillerStatus() {
158-
while true; do
159-
status=$(kubectl -nkube-system get pod -l app=helm -l name=tiller -o=go-template --template='{{ range $i, $v := .items }}{{ if eq $v.status.phase "Running" }}{{ $v.status.phase }}{{ end }}{{ end }}')
160-
161-
msg "Tiller status = $status"
162-
[ "$status" == "Running" ] && break
163-
164-
msg "Sleeping 5 seconds ..."
165-
sleep 5
166-
167-
done
168-
}
169-
17029
generateWebTlsValuesFile() {
17130

17231
WEBTLSKEY=$(cat ${WebTlsKey} | sed 's/^/ /')
@@ -177,6 +36,11 @@ WEBTLSCERT_CFUI=$(cat ${WebTlsCert} | sed 's/^/ /')
17736

17837
cat <<-EOF >${WEBTLS_VALUES_FILE}
17938
---
39+
ingress:
40+
webTlsSecretName: "star.codefresh.io"
41+
nomios:
42+
ingress:
43+
webTlsSecretName: "star.codefresh.io"
18044
webTLS:
18145
secretName: star.codefresh.io
18246
key: |
@@ -199,7 +63,7 @@ EOF
19963

20064
# run_as_root
20165

202-
while [[ $1 =~ ^(-(y)|--(yes|web-tls-key|web-tls-cert|set)) ]]
66+
while [[ $1 =~ ^(-(y)|--(yes|web-tls-key|web-tls-cert|set|debug)) ]]
20367
do
20468
key=$1
20569
value=$2
@@ -219,6 +83,9 @@ do
21983
SET_VALUES="$SET_VALUES --set $value"
22084
shift
22185
;;
86+
--debug)
87+
SET_DEBUG="--debug"
88+
;;
22289
esac
22390
shift # past argument or value
22491
done
@@ -316,12 +183,21 @@ EOF
316183

317184
[ -n "${WebTlsKey}" ] && [ -f "${WebTlsKey}" ] && [ -n "${WebTlsCert}" ] && [ -f "${WebTlsCert}" ] && [ -f "${WEBTLS_VALUES_FILE}" ] && WEBTLS_VALUES="--values ${WEBTLS_VALUES_FILE}"
318185

319-
cf_status=$(helm ls -q cf)
186+
cf_status=$(helm status $RELEASE 2>/dev/null | awk -F': ' '$1 == "STATUS" {print $2}')
187+
188+
if [[ -z "${cf_status}" ]]; then
189+
SEEDJOBS="--set global.seedJobs=true"
190+
CERTJOBS="--set global.certsJobs=true"
191+
IN_INSTALLER="true" ${DIR}/run-validator.sh
192+
if [[ $? != 0 ]]; then
193+
echo "Validation failed"
194+
exit 1
195+
fi
196+
fi
320197

321-
[ -z "${cf_status}" ] && SEEDJOBS="--set global.seedJobs=true" && CERTJOBS="--set global.certsJobs=true"
322198

323199
msg "Installing/Updating Codefresh..."
324-
helm upgrade cf codefresh-onprem-${CHANNEL}/codefresh \
200+
helm upgrade ${RELEASE} codefresh-onprem-${CHANNEL}/codefresh \
325201
--install \
326202
--namespace codefresh \
327203
--values "${VALUES_FILE}" \
@@ -331,5 +207,6 @@ helm upgrade cf codefresh-onprem-${CHANNEL}/codefresh \
331207
--set cfapi.redeploy=true \
332208
${SEEDJOBS} \
333209
${CERTJOBS} \
334-
${SET_VALUES}
210+
${SET_VALUES} \
211+
${SET_DEBUG}
335212
# ${MTU_VALUE}

env-vars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export CF_HELM_CHANNEL=
1+
export CF_HELM_CHANNEL=test
22
export CF_HELM_VERSION=

local-volumes/Chart.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: "v1"
2+
name: local-volumes
3+
version: 1.0.0
4+
kubeVersion: "1.10.0 - 2.0.0"
5+
description: Creates local volumes for Codefresh onprem installation
6+
keywords:
7+
- codefresh
8+
- onprem
9+
- local-volumes
10+
home: https://codefresh.io/
11+
sources:
12+
- https://github.com/codefresh-io/onprem
13+
maintainers:
14+
- name: Codefresh Authors
15+
16+
engine: gotpl
17+
icon: https://codefresh.io/docs/assets/brand/codefresh-social-logo.png
18+
appVersion: v2.0.10
19+
tillerVersion: ">2.9.0"

local-volumes/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Local Volumes helm chart
2+
Creates Loval volumes and pvcs, makes directories on the nodes
3+
4+
Copy from template and edit values.yaml
5+
Set
6+
```
7+
cp values.yaml.tmpl values.yaml
8+
vi values.yaml
9+
10+
./create-local-pvcs.sh
11+
```

local-volumes/create-local-pvcs.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
#
3+
4+
DIR=$(dirname $0)
5+
RELEASE=cf-local-volumes
6+
CHART=$(realpath ${DIR}/../local-volumes)
7+
NAMESPACE=${NAMESPACE:-codefresh}
8+
HELM_TIMEOUT=60
9+
10+
source ${DIR}/../scripts/helpers.sh
11+
12+
approveContext
13+
14+
RELEASE_STATUS=$(helm status $RELEASE 2>/dev/null | awk -F': ' '$1 == "STATUS" {print $2}')
15+
if [[ -n "${RELEASE_STATUS}" ]]; then
16+
echo "There is a previous run of $RELEASE with status $RELEASE_STATUS
17+
Run: helm status cf-local-volumes; to check the status of the release
18+
Or run: helm del --purge cf-local-volumes; to delete it
19+
20+
"
21+
exit 1
22+
fi
23+
24+
VALUES_FILE=${DIR}/values.yaml
25+
26+
HELM=${HELM:-helm}
27+
28+
HELM_COMMAND="$HELM --namespace $NAMESPACE install -n $RELEASE $CHART $@"
29+
30+
echo "Running ${RELEASE} helm release
31+
$HELM_COMMAND
32+
"
33+
34+
eval $HELM_COMMAND &
35+
HELM_PID=$!
36+
37+
wait $HELM_PID
38+
HELM_EXIT_STATUS=$?
39+
40+
if [[ "${HELM_EXIT_STATUS}" == 0 ]]; then
41+
echo "Local Volumes chart has been submitted. Run the command below to insect the status
42+
kubectl --namespace $NAMESPACE get pods,pvc,pv,svc -l app=${RELEASE}
43+
"
44+
else
45+
echo "
46+
Local Volumes chart submission FAILED."
47+
fi
48+
49+
exit $HELM_EXIT_STATUS

0 commit comments

Comments
 (0)