Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START======================================================= |
| 4 | # Copyright (C) 2019 The Nordix Foundation. All rights reserved. |
| 5 | # ================================================================================ |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END========================================================= |
| 20 | |
| 21 | |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 22 | set -o nounset |
| 23 | set -o errexit |
| 24 | set -o pipefail |
| 25 | |
| 26 | # NOTE (fdegir): we need to remove $WORKSPACE and clone infra/engine repository |
| 27 | # as infra/engine is what drives the deployment |
| 28 | if [[ "$GERRIT_PROJECT" != "infra/engine" ]]; then |
| 29 | cd "$HOME" && /bin/rm -rf "$WORKSPACE" |
| 30 | echo "Info : Cloning infra/engine repository" |
| 31 | git clone -q https://gerrit.nordix.org/infra/engine.git "$WORKSPACE" |
| 32 | cd "$WORKSPACE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 33 | fi |
| 34 | |
| 35 | # file to record change metadata |
| 36 | export CHANGE_METADATA_FILE="$WORKSPACE/change.properties" |
| 37 | /bin/rm -f "$CHANGE_METADATA_FILE" |
| 38 | |
| 39 | echo "Info : Generating change metadata" |
| 40 | |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 41 | # determine the project |
| 42 | # this scripts is used by all engine repos so we need to determine what this change is for |
| 43 | export ENGINE_COMPONENT="${GERRIT_PROJECT//*\//}" |
| 44 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 45 | echo "Info : Setting STACK_TYPE and STACK_VERSION" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 46 | if [[ "$GERRIT_PROJECT" =~ /stack/ ]]; then |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 47 | # set vars |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 48 | export STACK_TYPE="$ENGINE_COMPONENT" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 49 | export STACK_VERSION="$GERRIT_PATCHSET_REVISION" |
| 50 | export STACK_REFSPEC="$GERRIT_REFSPEC" |
| 51 | |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 52 | case "${STACK_TYPE}" in |
| 53 | openstack) |
| 54 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
| 55 | ;; |
| 56 | kubernetes) |
| 57 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
| 58 | ;; |
| 59 | onap) |
| 60 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
| 61 | ;; |
| 62 | ironic) |
| 63 | export DEPLOY_SCENARIO="ubuntu1804" |
| 64 | ;; |
| 65 | *) echo "ERROR : Invalid stack $ENGINE_COMPONENT"; exit 1;; |
| 66 | esac |
| 67 | |
| 68 | export STACK_VERSION="$GERRIT_BRANCH" |
| 69 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 70 | # log info to console |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 71 | echo " STACK_TYPE=$STACK_TYPE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 72 | echo " DEPLOY_SCENARIO=$DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 73 | echo " STACK_VERSION=$GERRIT_PATCHSET_REVISION" |
| 74 | echo " STACK_REFSPEC=$GERRIT_REFSPEC" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 75 | |
| 76 | # record vars to properties file |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 77 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 78 | echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 79 | echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| 80 | echo "STACK_REFSPEC=$STACK_REFSPEC" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 81 | elif [[ "$GERRIT_PROJECT" =~ /installer/ ]]; then |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 82 | # set vars |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 83 | case "${ENGINE_COMPONENT}" in |
| 84 | kolla) |
| 85 | export STACK_TYPE="openstack" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 86 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 87 | ;; |
| 88 | kubespray) |
| 89 | export STACK_TYPE="kubernetes" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 90 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 91 | ;; |
| 92 | oom) |
| 93 | export STACK_TYPE="onap" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 94 | echo "Info : Deploy scenario is overriden by job to $DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 95 | ;; |
| 96 | *) echo "ERROR : Invalid engine component $ENGINE_COMPONENT"; exit 1;; |
| 97 | esac |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 98 | export STACK_VERSION="$GERRIT_BRANCH" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 99 | |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 100 | # log info to console |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 101 | echo " STACK_TYPE=$STACK_TYPE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 102 | echo " DEPLOY_SCENARIO=$DEPLOY_SCENARIO" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 103 | echo " STACK_VERSION=$STACK_VERSION" |
| 104 | echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" |
| 105 | echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 106 | |
| 107 | # record vars to properties file |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 108 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 109 | echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 110 | echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| 111 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| 112 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| 113 | else |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 114 | # set vars |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 115 | export STACK_TYPE=kubernetes |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 116 | export STACK_VERSION=$GERRIT_BRANCH |
| 117 | |
| 118 | # log info to console |
| 119 | echo " STACK_TYPE=$STACK_TYPE" |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 120 | echo " DEPLOY_SCENARIO=$DEPLOY_SCENARIO" |
Fatih Degirmenci | 9f2d4dc | 2020-06-23 17:09:37 +0000 | [diff] [blame] | 121 | echo " STACK_VERSION=$STACK_VERSION" |
| 122 | echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" |
| 123 | echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" |
| 124 | |
| 125 | # record vars to properties file |
Fatih Degirmenci | 5db1c8f | 2020-07-02 07:59:51 +0000 | [diff] [blame] | 126 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
| 127 | echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | b112baf | 2020-06-23 09:32:32 +0000 | [diff] [blame] | 128 | echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 129 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| 130 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| 131 | fi |
| 132 | |
| 133 | # global vars |
| 134 | export NORDIX_ARM_HTTPS_URL="https://artifactory.nordix.org/artifactory" |
| 135 | export ARTIFACT_ARM_FOLDER="gerrit" |
| 136 | export BUILD_IDENTIFIER=$GERRIT_CHANGE_NUMBER |
Fatih Degirmenci | de51df0 | 2020-06-29 19:33:25 +0000 | [diff] [blame] | 137 | export INSTALLER_FILE="${STACK_TYPE}-${DISTRO}.bsx" |
| 138 | export BUILD_ARTIFACTS="${STACK_TYPE}-${DISTRO}.bsx" |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 139 | export NORDIX_ARM_REPO="nordix-${STACK_TYPE}" |
| 140 | export NORDIX_ARTIFACT_URL="$NORDIX_ARM_HTTPS_URL/$NORDIX_ARM_REPO/installer/oss/$ARTIFACT_ARM_FOLDER/$BUILD_IDENTIFIER" |
| 141 | |
| 142 | cat << EOF >> "$CHANGE_METADATA_FILE" |
| 143 | BUILD_IDENTIFIER=$BUILD_IDENTIFIER |
| 144 | BUILD_DATE=$(date '+%Y%m%d%H%M') |
| 145 | BUILT_BY=$BUILD_URL |
Fatih Degirmenci | de51df0 | 2020-06-29 19:33:25 +0000 | [diff] [blame] | 146 | DISTRO=$DISTRO |
Fatih Degirmenci | 459c348 | 2020-06-15 21:15:43 +0000 | [diff] [blame] | 147 | CI_LOOP=$CI_LOOP |
| 148 | ENGINE_SHA=$(git rev-parse HEAD) |
| 149 | INSTALLER_FILE=${STACK_TYPE}-ubuntu1804.bsx |
| 150 | BUILD_ARTIFACTS=${STACK_TYPE}-ubuntu1804.bsx |
| 151 | NORDIX_ARM_REPO=nordix-${STACK_TYPE} |
| 152 | NORDIX_ARTIFACT_URL=$NORDIX_ARTIFACT_URL |
| 153 | EOF |
| 154 | |
| 155 | echo "Info : Change metadata" |
| 156 | echo "-------------------------------------------------------------------------" |
| 157 | cat "$CHANGE_METADATA_FILE" |
| 158 | echo "-------------------------------------------------------------------------" |
| 159 | |
| 160 | # vim: set ts=2 sw=2 expandtab: |