| 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 | |
| 23 | export HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")") |
| 24 | source "${HERE}/library/functions.sh" |
| 25 | source "${HERE}/library/trap.sh" |
| 26 | |
| 27 | |
| 28 | ############################ Clone repos |
| 29 | m "\n#####################################################################" "${CYAN}" |
| 30 | m "(1/8) Cloning relevant repos..." "${CYAN}" |
| 31 | m "#####################################################################\n" "${CYAN}" |
| 32 | |
| 33 | # Load Gitea credentials |
| 34 | source "${CREDENTIALS_DIR}/gitea_environment.rc" |
| 35 | source "${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 |
| 44 | m "\n#####################################################################" "${CYAN}" |
| 45 | m "(2/8) Running Flux bootstrap on the management cluster..." "${CYAN}" |
| 46 | m "#####################################################################\n" "${CYAN}" |
| 47 | |
| 48 | # Bootstrap |
| 49 | "${HERE}/flux/scripts/mgmt-cluster-bootstrap.sh" |
| 50 | |
| 51 | # Pull the latest changes from the `fleet` repo |
| 52 | git -C "${FLEET_REPO_DIR}" pull origin main |
| 53 | |
| 54 | ##################################################################### |
| 55 | |
| 56 | |
| 57 | ############################ SOPS setup for the management cluster |
| 58 | m "\n#####################################################################" "${CYAN}" |
| 59 | m "(3/8) Setting up SOPS in the management cluster..." "${CYAN}" |
| 60 | m "#####################################################################\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 |
| 74 | m "\n#####################################################################" "${CYAN}" |
| 75 | m "(4/8) Creating base kustomizations and default cluster profiles..." "${CYAN}" |
| 76 | m "#####################################################################\n" "${CYAN}" |
| 77 | |
| 78 | TEMPLATES_DIR="flux/templates/fleet/clusters/_management" |
| 79 | TEMPLATES_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 |
| 98 | m "\n#####################################################################" "${CYAN}" |
| 99 | m "(5/8) Populating the SW-Catalogs repo folder..." "${CYAN}" |
| 100 | m "#####################################################################\n" "${CYAN}" |
| 101 | |
| 102 | TEMPLATES_DIR="flux/templates/sw-catalogs" |
| 103 | TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}") |
| 104 | # rsync -varhP "${TEMPLATES_DIR}" "${SW_CATALOGS_REPO_DIR}/" |
| 105 | cp -r "${TEMPLATES_DIR}"/* "${SW_CATALOGS_REPO_DIR}/" |
| 106 | |
| 107 | ##################################################################### |
| 108 | |
| 109 | |
| 110 | ############################ Add all the required operators and CRDs |
| 111 | m "\n#####################################################################" "${CYAN}" |
| 112 | m "(6/8) Add all the required operators and CRDs..." "${CYAN}" |
| 113 | m "#####################################################################\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 |
| 126 | m "\n#####################################################################" "${CYAN}" |
| 127 | m "(7/8) Configure for running OSM workflows..." "${CYAN}" |
| 128 | m "#####################################################################\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 |
| 144 | m "\n#####################################################################" "${CYAN}" |
| 145 | m "(8/8) Pushing all changes to Git repos..." "${CYAN}" |
| 146 | m "#####################################################################\n" "${CYAN}" |
| 147 | |
| 148 | # SW Catalogs |
| 149 | pushd "${SW_CATALOGS_REPO_DIR}" > /dev/null |
| 150 | # git status |
| 151 | git add -A |
| 152 | git commit -m "Sync from sw-catalogs template" |
| 153 | git push -u origin main |
| 154 | popd > /dev/null |
| 155 | |
| 156 | # Fleet |
| 157 | pushd "${FLEET_REPO_DIR}" > /dev/null |
| 158 | # git status |
| 159 | git add -A |
| 160 | git commit -m "Full profile structure after bootstrap + SOPS config + operators and CRDs" |
| 161 | git push -u origin main |
| 162 | popd > /dev/null |
| 163 | |
| 164 | ##################################################################### |