blob: 7b8fbf6934ea27d7d24a6d0109c89a77f8773456 [file] [log] [blame]
garciadeblas8d8cd992024-05-21 16:04:14 +02001#!/bin/bash
2#######################################################################################
3# Copyright ETSI Contributors and Others.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#######################################################################################
18
19set -e -o pipefail
20
21# Warning!!!: Remember to select the desired kubeconfig profile before launching this script
22
23export HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
24source "${HERE}/library/functions.sh"
25source "${HERE}/library/trap.sh"
26
27
28############################ Clone repos
29m "\n#####################################################################" "${CYAN}"
30m "(1/8) Cloning relevant repos..." "${CYAN}"
31m "#####################################################################\n" "${CYAN}"
32
33# Load Gitea credentials
34source "${CREDENTIALS_DIR}/gitea_environment.rc"
35source "${CREDENTIALS_DIR}/gitea_tokens.rc"
36
37# clone the relevant repos to well-known local folders
38"${HERE}/flux/scripts/clone-relevant-repos.sh"
39
40#####################################################################
41
42
43############################ Flux bootstrap
44m "\n#####################################################################" "${CYAN}"
45m "(2/8) Running Flux bootstrap on the management cluster..." "${CYAN}"
46m "#####################################################################\n" "${CYAN}"
47
48# Bootstrap
49"${HERE}/flux/scripts/mgmt-cluster-bootstrap.sh"
50
51# Pull the latest changes from the `fleet` repo
52git -C "${FLEET_REPO_DIR}" pull origin main
53
54#####################################################################
55
56
57############################ SOPS setup for the management cluster
58m "\n#####################################################################" "${CYAN}"
59m "(3/8) Setting up SOPS in the management cluster..." "${CYAN}"
60m "#####################################################################\n" "${CYAN}"
61
62# Create a new `age` key pair for the management cluster
63"${HERE}/flux/scripts/create-age-keypair.sh" "${AGE_KEY_NAME_MGMT}"
64
65# Add the `age` key pair to the cluster
66"${HERE}/flux/scripts/add-age-key-to-cluster.sh" \
67 "${AGE_KEY_NAME_MGMT}" \
68 "${FLEET_REPO_DIR}/clusters/_management"
69
70#####################################################################
71
72
73############################ Base kustomizations and default cluster profiles
74m "\n#####################################################################" "${CYAN}"
75m "(4/8) Creating base kustomizations and default cluster profiles..." "${CYAN}"
76m "#####################################################################\n" "${CYAN}"
77
78TEMPLATES_DIR="flux/templates/fleet/clusters/_management"
79TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}")
80
81# ARGUMENTS:
82# 1: Cluster folder
83# 2: Project folder
84# 3: Profile name
85# 4: Templates folder
86"${HERE}/flux/scripts/create-new-cluster-folder-structure.sh" \
87 "${FLEET_REPO_DIR}/clusters/_management" \
88 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
89 "_management" \
90 "${TEMPLATES_DIR}" \
91 $(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME_MGMT}.pub")
92
93
94#####################################################################
95
96
97############################ Populate the SW-Catalogs repo folder
98m "\n#####################################################################" "${CYAN}"
99m "(5/8) Populating the SW-Catalogs repo folder..." "${CYAN}"
100m "#####################################################################\n" "${CYAN}"
101
102TEMPLATES_DIR="flux/templates/sw-catalogs"
103TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}")
104# rsync -varhP "${TEMPLATES_DIR}" "${SW_CATALOGS_REPO_DIR}/"
105cp -r "${TEMPLATES_DIR}"/* "${SW_CATALOGS_REPO_DIR}/"
106
107#####################################################################
108
109
110############################ Add all the required operators and CRDs
111m "\n#####################################################################" "${CYAN}"
112m "(6/8) Add all the required operators and CRDs..." "${CYAN}"
113m "#####################################################################\n" "${CYAN}"
114
115# ARGUMENTS:
116# 1: Project folder
117# 2: Profile name
118"${HERE}/mgmt-operators-and-crds/add-operators-and-crds.sh" \
119 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
120 "_management"
121
122#####################################################################
123
124
125############################ Configure for running OSM workflows
126m "\n#####################################################################" "${CYAN}"
127m "(7/8) Configure for running OSM workflows..." "${CYAN}"
128m "#####################################################################\n" "${CYAN}"
129
130# ARGUMENTS:
131# 1: Project folder
132# 2: Profile name
133
134"${HERE}/mgmt-operators-and-crds/configure-workflows.sh" \
135 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
136 "_management" \
137 $(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME_MGMT}.pub")
138
139
140#####################################################################
141
142
143############################ Push changes to Git repos
144m "\n#####################################################################" "${CYAN}"
145m "(8/8) Pushing all changes to Git repos..." "${CYAN}"
146m "#####################################################################\n" "${CYAN}"
147
148# SW Catalogs
149pushd "${SW_CATALOGS_REPO_DIR}" > /dev/null
150# git status
151git add -A
152git commit -m "Sync from sw-catalogs template"
153git push -u origin main
154popd > /dev/null
155
156# Fleet
157pushd "${FLEET_REPO_DIR}" > /dev/null
158# git status
159git add -A
160git commit -m "Full profile structure after bootstrap + SOPS config + operators and CRDs"
161git push -u origin main
162popd > /dev/null
163
164#####################################################################