| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 1 | #!/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 | |
| 19 | set -e -o pipefail |
| 20 | |
| 21 | # Warning!!!: Remember to select the desired kubeconfig profile before launching this script |
| 22 | |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 23 | HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")") |
| 24 | source "${HERE}/../library/functions.sh" |
| 25 | source "${HERE}/../library/trap.sh" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 26 | |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 27 | source "${HERE}/00-default-install-options.rc" |
| 28 | [ ! -f "${OSM_HOME_DIR}/user-install-options.rc" ] || source "${OSM_HOME_DIR}/user-install-options.rc" |
| 29 | echo "Loading env variables from 20-base-config.rc" |
| 30 | source "${HERE}/20-base-config.rc" |
| 31 | source "${CREDENTIALS_DIR}/git_environment.rc" |
| 32 | |
| 33 | # TODO: check git config |
| 34 | # TODO: move this to a parent script that creates the VM |
| 35 | mkdir -p "${OSM_HOME_DIR}/clusters" |
| 36 | if [ -n "${KUBECONFIG_MGMT_CLUSTER}" ]; then |
| 37 | cp "${KUBECONFIG_MGMT_CLUSTER}" "${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml" |
| 38 | else |
| 39 | cp "${HOME}/.kube/config" "${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml" |
| 40 | fi |
| 41 | |
| 42 | export KUBECONFIG="${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 43 | |
| 44 | ############################ Clone repos |
| 45 | m "\n#####################################################################" "${CYAN}" |
| 46 | m "(1/8) Cloning relevant repos..." "${CYAN}" |
| 47 | m "#####################################################################\n" "${CYAN}" |
| 48 | |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 49 | # clone the relevant repos to well-known local folders |
| 50 | "${HERE}/flux/scripts/clone-relevant-repos.sh" |
| 51 | |
| 52 | ##################################################################### |
| 53 | |
| 54 | |
| 55 | ############################ Flux bootstrap |
| 56 | m "\n#####################################################################" "${CYAN}" |
| 57 | m "(2/8) Running Flux bootstrap on the management cluster..." "${CYAN}" |
| 58 | m "#####################################################################\n" "${CYAN}" |
| 59 | |
| 60 | # Bootstrap |
| 61 | "${HERE}/flux/scripts/mgmt-cluster-bootstrap.sh" |
| 62 | |
| 63 | # Pull the latest changes from the `fleet` repo |
| 64 | git -C "${FLEET_REPO_DIR}" pull origin main |
| 65 | |
| 66 | ##################################################################### |
| 67 | |
| 68 | |
| 69 | ############################ SOPS setup for the management cluster |
| 70 | m "\n#####################################################################" "${CYAN}" |
| 71 | m "(3/8) Setting up SOPS in the management cluster..." "${CYAN}" |
| 72 | m "#####################################################################\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 |
| 86 | m "\n#####################################################################" "${CYAN}" |
| 87 | m "(4/8) Creating base kustomizations and default cluster profiles..." "${CYAN}" |
| 88 | m "#####################################################################\n" "${CYAN}" |
| 89 | |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 90 | TEMPLATES_DIR="${HERE}/flux/templates/fleet/clusters/_management" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 91 | TEMPLATES_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 |
| 110 | m "\n#####################################################################" "${CYAN}" |
| 111 | m "(5/8) Populating the SW-Catalogs repo folder..." "${CYAN}" |
| 112 | m "#####################################################################\n" "${CYAN}" |
| 113 | |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 114 | TEMPLATES_DIR="${HERE}/flux/templates/sw-catalogs" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 115 | TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}") |
| 116 | # rsync -varhP "${TEMPLATES_DIR}" "${SW_CATALOGS_REPO_DIR}/" |
| 117 | cp -r "${TEMPLATES_DIR}"/* "${SW_CATALOGS_REPO_DIR}/" |
| garciadeblas | b7c8267 | 2025-08-05 11:15:03 +0200 | [diff] [blame^] | 118 | if [ -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" {} + |
| 121 | fi |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 122 | |
| 123 | ##################################################################### |
| 124 | |
| 125 | |
| 126 | ############################ Add all the required operators and CRDs |
| 127 | m "\n#####################################################################" "${CYAN}" |
| 128 | m "(6/8) Add all the required operators and CRDs..." "${CYAN}" |
| 129 | m "#####################################################################\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 |
| 142 | m "\n#####################################################################" "${CYAN}" |
| 143 | m "(7/8) Configure for running OSM workflows..." "${CYAN}" |
| 144 | m "#####################################################################\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 |
| 160 | m "\n#####################################################################" "${CYAN}" |
| 161 | m "(8/8) Pushing all changes to Git repos..." "${CYAN}" |
| 162 | m "#####################################################################\n" "${CYAN}" |
| 163 | |
| 164 | # SW Catalogs |
| 165 | pushd "${SW_CATALOGS_REPO_DIR}" > /dev/null |
| 166 | # git status |
| 167 | git add -A |
| 168 | git commit -m "Sync from sw-catalogs template" |
| 169 | git push -u origin main |
| 170 | popd > /dev/null |
| 171 | |
| 172 | # Fleet |
| 173 | pushd "${FLEET_REPO_DIR}" > /dev/null |
| 174 | # git status |
| 175 | git add -A |
| 176 | git commit -m "Full profile structure after bootstrap + SOPS config + operators and CRDs" |
| 177 | git push -u origin main |
| 178 | popd > /dev/null |
| 179 | |
| 180 | ##################################################################### |