-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsetup-git.sh
executable file
·94 lines (80 loc) · 4.15 KB
/
setup-git.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
#!/usr/bin/env bash
set -euo pipefail
set -x
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo $SCRIPTDIR
ROOTDIR=$SCRIPTDIR
[[ -n "${DEBUG:-}" ]] && set -x
GITOPS_DIR=${GITOPS_DIR:-$SCRIPTDIR/environment/gitops-repos}
echo $GITOPS_DIR
PROJECT_CONTECXT_PREFIX=${PROJECT_CONTECXT_PREFIX:-eks-fleet-workshop-gitops}
# Clone and initialize the gitops repositories
gitops_workload_url="$(aws secretsmanager get-secret-value --secret-id ${PROJECT_CONTECXT_PREFIX}-workloads --query SecretString --output text | jq -r .url)"
GIT_USER="$(aws secretsmanager get-secret-value --secret-id ${PROJECT_CONTECXT_PREFIX}-workloads --query SecretString --output text | jq -r .username)"
GIT_PASS="$(aws secretsmanager get-secret-value --secret-id ${PROJECT_CONTECXT_PREFIX}-workloads --query SecretString --output text | jq -r .password)"
gitops_platform_url="$(aws secretsmanager get-secret-value --secret-id ${PROJECT_CONTECXT_PREFIX}-platform --query SecretString --output text | jq -r .url)"
gitops_addons_url="$(aws secretsmanager get-secret-value --secret-id ${PROJECT_CONTECXT_PREFIX}-addons --query SecretString --output text | jq -r .url)"
gitops_fleet_url="$(aws secretsmanager get-secret-value --secret-id ${PROJECT_CONTECXT_PREFIX}-fleet --query SecretString --output text | jq -r .url)"
# if IDE_URL is set then setup
if [[ -n "${IDE_URL:-}" ]]; then
echo "IDE_URL is set"
GIT_CREDS="$HOME/.git-credentials"
# Setup for HTTPs Gitea
GITEA_URL=${IDE_URL}/gitea
cat > $GIT_CREDS << EOT
${GITEA_URL/#https:\/\//https:\/\/"$GIT_USER":"$GIT_PASS"@}
EOT
git config --global credential.helper 'store'
git config --global init.defaultBranch main
else
gitops_workload_url=${gitops_workload_url/#https:\/\//https:\/\/"$GIT_USER":"$GIT_PASS"@}
gitops_platform_url=${gitops_platform_url/#https:\/\//https:\/\/"$GIT_USER":"$GIT_PASS"@}
gitops_addons_url=${gitops_addons_url/#https:\/\//https:\/\/"$GIT_USER":"$GIT_PASS"@}
gitops_fleet_url=${gitops_fleet_url/#https:\/\//https:\/\/"$GIT_USER":"$GIT_PASS"@}
fi
# Reset directory
rm -rf ${GITOPS_DIR}
mkdir -p ${GITOPS_DIR}
#git clone ${gitops_workload_url} ${GITOPS_DIR}/apps
git init ${GITOPS_DIR}/apps
git -C ${GITOPS_DIR}/apps remote add origin ${gitops_workload_url}
cp -r ${ROOTDIR}/gitops/apps/* ${GITOPS_DIR}/apps
mkdir -p ${GITOPS_DIR}/apps/backend
touch ${GITOPS_DIR}/apps/backend/.keep
mkdir -p ${GITOPS_DIR}/apps/frontend
touch ${GITOPS_DIR}/apps/frontend/.keep
# Deploy the app for this workshop
# TODO: review with the team
cp -r ${ROOTDIR}/gitops/apps/* ${GITOPS_DIR}/apps/
git -C ${GITOPS_DIR}/apps add . || true
git -C ${GITOPS_DIR}/apps commit -m "initial commit" || true
git -C ${GITOPS_DIR}/apps push -u origin main -f || true
# populate platform repository
#git clone ${gitops_platform_url} ${GITOPS_DIR}/platform
git init ${GITOPS_DIR}/platform
git -C ${GITOPS_DIR}/platform remote add origin ${gitops_platform_url}
mkdir -p ${GITOPS_DIR}/platform/charts
cp -r ${ROOTDIR}/gitops/platform/charts/* ${GITOPS_DIR}/platform/charts/
mkdir -p ${GITOPS_DIR}/platform/bootstrap
cp -r ${ROOTDIR}/gitops/platform/bootstrap/* ${GITOPS_DIR}/platform/bootstrap/
# Deploy the namespaces for this workshop
# TODO: review with the team
mkdir -p ${GITOPS_DIR}/platform/teams
cp -r ${ROOTDIR}/gitops/platform/teams/* ${GITOPS_DIR}/platform/teams/
git -C ${GITOPS_DIR}/platform add . || true
git -C ${GITOPS_DIR}/platform commit -m "initial commit" || true
git -C ${GITOPS_DIR}/platform push -u origin main -f || true
#git clone ${gitops_addons_url} ${GITOPS_DIR}/addons
git init ${GITOPS_DIR}/addons
git -C ${GITOPS_DIR}/addons remote add origin ${gitops_addons_url}
cp -r ${ROOTDIR}/gitops/addons/* ${GITOPS_DIR}/addons/
git -C ${GITOPS_DIR}/addons add . || true
git -C ${GITOPS_DIR}/addons commit -m "initial commit" || true
git -C ${GITOPS_DIR}/addons push -u origin main -f || true
#git clone ${gitops_fleet_url} ${GITOPS_DIR}/fleet
git init ${GITOPS_DIR}/fleet
git -C ${GITOPS_DIR}/fleet remote add origin ${gitops_fleet_url}
cp -r ${ROOTDIR}/gitops/fleet/* ${GITOPS_DIR}/fleet/
git -C ${GITOPS_DIR}/fleet add . || true
git -C ${GITOPS_DIR}/fleet commit -m "initial commit" || true
git -C ${GITOPS_DIR}/fleet push -u origin main -f || true