blob: f5697b7a5676ba0cccc027651323884ec6e7a4df [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
garciadeblascf603f52025-06-04 11:57:28 +020023HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
24source "${HERE}/../library/functions.sh"
25source "${HERE}/../library/trap.sh"
garciadeblas8d8cd992024-05-21 16:04:14 +020026
garciadeblascf603f52025-06-04 11:57:28 +020027source "${HERE}/00-default-install-options.rc"
28[ ! -f "${OSM_HOME_DIR}/user-install-options.rc" ] || source "${OSM_HOME_DIR}/user-install-options.rc"
29echo "Loading env variables from 20-base-config.rc"
30source "${HERE}/20-base-config.rc"
31source "${CREDENTIALS_DIR}/git_environment.rc"
32
33# TODO: check git config
34# TODO: move this to a parent script that creates the VM
35mkdir -p "${OSM_HOME_DIR}/clusters"
36if [ -n "${KUBECONFIG_MGMT_CLUSTER}" ]; then
37 cp "${KUBECONFIG_MGMT_CLUSTER}" "${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
38else
39 cp "${HOME}/.kube/config" "${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
40fi
41
42export KUBECONFIG="${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
garciadeblas8d8cd992024-05-21 16:04:14 +020043
44############################ Clone repos
45m "\n#####################################################################" "${CYAN}"
46m "(1/8) Cloning relevant repos..." "${CYAN}"
47m "#####################################################################\n" "${CYAN}"
48
garciadeblas8d8cd992024-05-21 16:04:14 +020049# clone the relevant repos to well-known local folders
50"${HERE}/flux/scripts/clone-relevant-repos.sh"
51
52#####################################################################
53
54
55############################ Flux bootstrap
56m "\n#####################################################################" "${CYAN}"
57m "(2/8) Running Flux bootstrap on the management cluster..." "${CYAN}"
58m "#####################################################################\n" "${CYAN}"
59
60# Bootstrap
61"${HERE}/flux/scripts/mgmt-cluster-bootstrap.sh"
62
63# Pull the latest changes from the `fleet` repo
64git -C "${FLEET_REPO_DIR}" pull origin main
65
66#####################################################################
67
68
69############################ SOPS setup for the management cluster
70m "\n#####################################################################" "${CYAN}"
71m "(3/8) Setting up SOPS in the management cluster..." "${CYAN}"
72m "#####################################################################\n" "${CYAN}"
73
74# Create a new `age` key pair for the management cluster
75"${HERE}/flux/scripts/create-age-keypair.sh" "${AGE_KEY_NAME_MGMT}"
76
77# Add the `age` key pair to the cluster
78"${HERE}/flux/scripts/add-age-key-to-cluster.sh" \
79 "${AGE_KEY_NAME_MGMT}" \
80 "${FLEET_REPO_DIR}/clusters/_management"
81
82#####################################################################
83
84
85############################ Base kustomizations and default cluster profiles
86m "\n#####################################################################" "${CYAN}"
87m "(4/8) Creating base kustomizations and default cluster profiles..." "${CYAN}"
88m "#####################################################################\n" "${CYAN}"
89
garciadeblascf603f52025-06-04 11:57:28 +020090TEMPLATES_DIR="${HERE}/flux/templates/fleet/clusters/_management"
garciadeblas8d8cd992024-05-21 16:04:14 +020091TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}")
92
93# ARGUMENTS:
94# 1: Cluster folder
95# 2: Project folder
96# 3: Profile name
97# 4: Templates folder
98"${HERE}/flux/scripts/create-new-cluster-folder-structure.sh" \
99 "${FLEET_REPO_DIR}/clusters/_management" \
100 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
101 "_management" \
102 "${TEMPLATES_DIR}" \
103 $(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME_MGMT}.pub")
104
105
106#####################################################################
107
108
109############################ Populate the SW-Catalogs repo folder
110m "\n#####################################################################" "${CYAN}"
111m "(5/8) Populating the SW-Catalogs repo folder..." "${CYAN}"
112m "#####################################################################\n" "${CYAN}"
113
garciadeblascf603f52025-06-04 11:57:28 +0200114TEMPLATES_DIR="${HERE}/flux/templates/sw-catalogs"
garciadeblas8d8cd992024-05-21 16:04:14 +0200115TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}")
116# rsync -varhP "${TEMPLATES_DIR}" "${SW_CATALOGS_REPO_DIR}/"
117cp -r "${TEMPLATES_DIR}"/* "${SW_CATALOGS_REPO_DIR}/"
garciadeblasb7c82672025-08-05 11:15:03 +0200118if [ -n "${OSM_DOCKER_TAG}" ]; then
119 # Replace the OSM Docker tag in the WF templates
120 find "${SW_CATALOGS_REPO_DIR}/infra-configs/osm-workflows/templates/wf-templates/building-blocks" -type f -name "*.yaml" -exec sed -i "s|opensourcemano/osm-krm-functions:testing-daily|${DOCKER_REGISTRY_URL}${DOCKER_USER}/osm-krm-functions:${OSM_DOCKER_TAG}|g" {} +
121fi
garciadeblas8d8cd992024-05-21 16:04:14 +0200122
123#####################################################################
124
125
126############################ Add all the required operators and CRDs
127m "\n#####################################################################" "${CYAN}"
128m "(6/8) Add all the required operators and CRDs..." "${CYAN}"
129m "#####################################################################\n" "${CYAN}"
130
131# ARGUMENTS:
132# 1: Project folder
133# 2: Profile name
134"${HERE}/mgmt-operators-and-crds/add-operators-and-crds.sh" \
135 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
136 "_management"
137
138#####################################################################
139
140
141############################ Configure for running OSM workflows
142m "\n#####################################################################" "${CYAN}"
143m "(7/8) Configure for running OSM workflows..." "${CYAN}"
144m "#####################################################################\n" "${CYAN}"
145
146# ARGUMENTS:
147# 1: Project folder
148# 2: Profile name
149
150"${HERE}/mgmt-operators-and-crds/configure-workflows.sh" \
151 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
152 "_management" \
153 $(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME_MGMT}.pub")
154
155
156#####################################################################
157
158
159############################ Push changes to Git repos
160m "\n#####################################################################" "${CYAN}"
161m "(8/8) Pushing all changes to Git repos..." "${CYAN}"
162m "#####################################################################\n" "${CYAN}"
163
164# SW Catalogs
165pushd "${SW_CATALOGS_REPO_DIR}" > /dev/null
166# git status
167git add -A
168git commit -m "Sync from sw-catalogs template"
169git push -u origin main
170popd > /dev/null
171
172# Fleet
173pushd "${FLEET_REPO_DIR}" > /dev/null
174# git status
175git add -A
176git commit -m "Full profile structure after bootstrap + SOPS config + operators and CRDs"
177git push -u origin main
178popd > /dev/null
179
180#####################################################################