/
bootstrap-values.sh
65 lines (56 loc) · 2.04 KB
/
bootstrap-values.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
#!/usr/bin/env bash
. bin/common.sh
. bin/chart-common.sh
readonly gitea_enabled=$(yqr_chart charts.gitea.enabled || echo 'true')
readonly cluster_domain=$(yqr_chart cluster.domainSuffix)
if [ "$PWD" != '/home/app/stack' ]; then
# only for devving, since this chart starts with an empty ENV_DIR anyway:
rm -rf $ENV_DIR/.git
rm -rf $ENV_DIR/.vscode
rm -rf $ENV_DIR/*
fi
# init git setup pointing to repo
pushd $ENV_DIR
git init
byor=false
yqr_chart charts.otomi-api.git && byor=true
if [ "$gitea_enabled" != "true" ] && ! $byor; then
echo "Gitea was disabled but no charts.otomi-api.git config was given."
exit 1
fi
if [ "$gitea_enabled" != "true" ]; then
echo "Gitea is disabled. Using external git provider from config."
readonly username=$(yqr_chart charts.otomi-api.git.user)
readonly password=$(yqr_chart charts.otomi-api.git.password)
readonly email=$(yqr_chart charts.otomi-api.git.email || echo "otomi-admin@$cluster_domain")
readonly repo_url=$(yqr_chart charts.otomi-api.git.repoUrl)
readonly branch=$(yqr_chart charts.otomi-api.git.branch || echo 'main')
git config user.name "$username"
git config user.password "$password"
git config user.email "$email"
git remote add origin $repo_url
else
echo "Gitea is enabled."
readonly gitea_url="gitea.$cluster_domain"
readonly gitea_password=$(yqr_chart charts.gitea.adminPassword || yqr_chart otomi.adminPassword)
readonly gitea_user='otomi-admin'
readonly gitea_org='otomi'
readonly gitea_repo='values'
readonly branch='main'
git config user.name 'Otomi Admin'
git config user.email "otomi-admin@$cluster_domain"
git remote add origin "https://$gitea_user:$gitea_password@$gitea_url/$gitea_org/$gitea_repo.git"
echo 'Added gitea as a remote origin'
fi
echo 'Trying to do a git pull...'
set +e
git checkout -b $branch #&>/dev/null
git pull origin $branch #&>/dev/null
set -e
popd
bin/bootstrap.sh
# decrypt before merging if we can
[ -f $ENV_DIR/.sops.yaml ] && crypt dec
# lastly copy the schema file
cp values-schema.yaml $ENV_DIR/
chmod a+w -R $ENV_DIR/env || exit 0