-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
138 lines (112 loc) · 4.25 KB
/
justfile
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
# Define environment variables (if any)
set dotenv-load := true
# Global ENVs
justfileDir := justfile_directory()
namespace := shell('basename $1', justfileDir)
operatorChartName := "frinx-machine-operators"
# Execution ENVs. Can be overided on startup
values := "local-values.yaml"
exclude := ""
[private]
default:
@echo '{{ \
"\nJustfile for Frinx Machine execution: start Frinx Machine stage locally\n\n" + \
"Default env variables: \n\n" + \
"\tvalues: Add extra value files to helm command\n" + \
"\texclude: Exclude apps from installation process\n\n" + \
"Example of usage: \n\n" + \
"\t just deploy \n" + \
"\t just --set values \"local-values.yaml\" deploy \n" + \
"\t just --set exclude \"frinx-machine-monitoring,frinx-machine\" deploy" \
}}\n'
@just --list
[private]
create-namespace:
kubectl create namespace {{namespace}} || true
[private]
deploy-stage-operators values="":
#!/usr/bin/env bash
set -euo pipefail
VALUES={{values}}
pushd {{justfileDir}}/apps/{{operatorChartName}} > /dev/null
helm dependency update
helm upgrade --install --create-namespace -n {{namespace}} {{operatorChartName}} . --values values.yaml $(for val in {{values}}; do if [ -f $val ]; then echo --values $val; fi ; done)
popd > /dev/null
[private]
uninstall-stage-operators values="":
#!/usr/bin/env bash
set -euo pipefail
pushd {{justfileDir}}/apps/{{operatorChartName}} > /dev/null
helm dependency update
helm template -n {{namespace}} {{operatorChartName}} . ---values values.yaml $(for val in {{values}}; do if [ -f $val ]; then echo --values $val; fi ; done) | kubectl delete -f- || true
popd > /dev/null
# Function to deploy a stage with the ability to exclude apps and specify values files
[private]
deploy-stage exclude values:
#!/usr/bin/env bash
set -euo pipefail
SKIP_CHARTS={{exclude}}
IFS=',' read -r -a EXCLUDE <<< "{{operatorChartName}},${SKIP_CHARTS}"
pushd {{justfileDir}}/apps > /dev/null
APPS=($(ls -d */ | sed 's:/*$::'))
for dir in "${APPS[@]}"; do
if [ -d "$dir" ]; then
pushd "$dir" > /dev/null
BASENAME=$(basename "$PWD")
# Check if the directory name is in the ignore list
if [[ " ${EXCLUDE[@]} " =~ " ${BASENAME} " ]]; then
echo "Skipping directory: $BASENAME"
popd > /dev/null
continue
fi
echo "Processing directory: $BASENAME"
helm dependency update
helm upgrade --install --create-namespace -n {{namespace}} $(basename $PWD) . --values values.yaml $(for val in {{values}}; do if [ -f $val ]; then echo --values $val; fi ; done)
popd > /dev/null
fi
done
popd > /dev/null
# Function to deploy a stage with the ability to exclude apps and specify values files
[private]
uninstall-stage exclude:
#!/usr/bin/env bash
set -euo pipefail
SKIP_CHARTS={{exclude}}
IFS=',' read -r -a EXCLUDE <<< "{{operatorChartName}},${SKIP_CHARTS}"
pushd {{justfileDir}}/apps > /dev/null
APPS=($(ls -d */ | sed 's:/*$::'))
for dir in "${APPS[@]}"; do
if [ -d "$dir" ]; then
pushd "$dir" > /dev/null
BASENAME=$(basename "$PWD")
# Check if the directory name is in the ignore list
if [[ " ${EXCLUDE[@]} " =~ " ${BASENAME} " ]]; then
echo "Skipping directory: $BASENAME"
popd > /dev/null
continue
fi
echo "Processing directory: $BASENAME"
helm uninstall -n {{namespace}} $(basename $PWD) || true
popd > /dev/null
fi
done
popd > /dev/null
# Recipe to deploy apps with optional apps exclusion and values files
deploy:
just create-namespace
just docker-secret
just deploy-stage-operators {{values}}
just deploy-stage "{{exclude}}" "{{values}}"
# Recipe to uninstall apps with optional apps exclusion and values files
uninstall:
just uninstall-stage "{{exclude}}"
just uninstall-stage-operators "{{values}}"
# Recipe to start minikube with max CPUs and 24G memory, instess addon enabled
minikube-start:
minikube start --cpus=max --memory=24G --addons=ingress
# Create docker secret from $HOME/.docker/config.json
docker-secret:
kubectl create secret generic regcred \
--from-file=.dockerconfigjson=$HOME/.docker/config.json \
--type=kubernetes.io/dockerconfigjson \
--namespace={{namespace}} || true