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 | |
| 22 | # NOTES (fdegir): this script only works for |
| 23 | # - infra/engine |
| 24 | # - infra/provisioner/heat |
| 25 | |
| 26 | set -o nounset |
| 27 | set -o errexit |
| 28 | set -o pipefail |
| 29 | |
| 30 | # NOTE (fdegir): we need to remove $WORKSPACE and clone infra/engine repository |
| 31 | # as infra/engine is what drives the deployment |
| 32 | if [[ "$GERRIT_PROJECT" != "infra/engine" ]]; then |
| 33 | cd "$HOME" && /bin/rm -rf "$WORKSPACE" |
| 34 | echo "Info : Cloning infra/engine repository" |
| 35 | git clone -q https://gerrit.nordix.org/infra/engine.git "$WORKSPACE" |
| 36 | cd "$WORKSPACE" |
| 37 | # TODO (fdegir): this is temporarily here to develop the jobs |
| 38 | git fetch "https://gerrit.nordix.org/infra/engine" refs/changes/23/4823/18 && git checkout FETCH_HEAD |
| 39 | fi |
| 40 | |
| 41 | # file to record change metadata |
| 42 | export CHANGE_METADATA_FILE="$WORKSPACE/change.properties" |
| 43 | /bin/rm -f "$CHANGE_METADATA_FILE" |
| 44 | |
| 45 | echo "Info : Generating change metadata" |
| 46 | |
| 47 | # TODO (fdegir): this should match to the branch of the job for {stack}-verify jobs |
| 48 | export STACK_VERSION=master |
| 49 | |
| 50 | # determine the project |
| 51 | # this scripts is used by all engine repos so we need to determine what this change is for |
| 52 | export ENGINE_COMPONENT="${GERRIT_PROJECT//*\//}" |
| 53 | |
| 54 | if [[ "$GERRIT_PROJECT" =~ /stack/ ]]; then |
| 55 | export STACK_TYPE="$ENGINE_COMPONENT" |
| 56 | echo "Info : Setting STACK_TYPE, STACK_VERSION and STACK_REFSPEC" |
| 57 | echo " STACK_TYPE=$STACK_TYPE" |
| 58 | echo " STACK_VERSION=$GERRIT_PATCHSET_REVISION" |
| 59 | echo " STACK_REFSPEC=$GERRIT_REFSPEC" |
| 60 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
| 61 | echo "STACK_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| 62 | echo "STACK_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| 63 | elif [[ "$GERRIT_PROJECT" =~ /installer/ ]]; then |
| 64 | case "${ENGINE_COMPONENT}" in |
| 65 | kolla) |
| 66 | export STACK_TYPE="openstack" |
| 67 | ;; |
| 68 | kubespray) |
| 69 | export STACK_TYPE="kubernetes" |
| 70 | ;; |
| 71 | oom) |
| 72 | export STACK_TYPE="onap" |
| 73 | ;; |
| 74 | *) echo "ERROR : Invalid engine component $ENGINE_COMPONENT"; exit 1;; |
| 75 | esac |
| 76 | |
| 77 | echo "Info : Setting STACK_TYPE, STACK_VERSION and STACK_REFSPEC" |
| 78 | echo " STACK_TYPE=$STACK_TYPE" |
| 79 | echo " STACK_VERSION=$STACK_VERSION" |
| 80 | echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" |
| 81 | echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" |
| 82 | echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
| 83 | echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| 84 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| 85 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| 86 | else |
| 87 | export STACK_TYPE=kubernetes |
| 88 | export STACK_VERSION=$STACK_VERSION |
| 89 | echo "STACK_TYPE=kubernetes" >> "$CHANGE_METADATA_FILE" |
| 90 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| 91 | echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| 92 | fi |
| 93 | |
| 94 | # global vars |
| 95 | export NORDIX_ARM_HTTPS_URL="https://artifactory.nordix.org/artifactory" |
| 96 | export ARTIFACT_ARM_FOLDER="gerrit" |
| 97 | export BUILD_IDENTIFIER=$GERRIT_CHANGE_NUMBER |
| 98 | export INSTALLER_FILE="${STACK_TYPE}-ubuntu1804.bsx" |
| 99 | export BUILD_ARTIFACTS="${STACK_TYPE}-ubuntu1804.bsx" |
| 100 | export NORDIX_ARM_REPO="nordix-${STACK_TYPE}" |
| 101 | export NORDIX_ARTIFACT_URL="$NORDIX_ARM_HTTPS_URL/$NORDIX_ARM_REPO/installer/oss/$ARTIFACT_ARM_FOLDER/$BUILD_IDENTIFIER" |
| 102 | |
| 103 | cat << EOF >> "$CHANGE_METADATA_FILE" |
| 104 | BUILD_IDENTIFIER=$BUILD_IDENTIFIER |
| 105 | BUILD_DATE=$(date '+%Y%m%d%H%M') |
| 106 | BUILT_BY=$BUILD_URL |
| 107 | CI_LOOP=$CI_LOOP |
| 108 | ENGINE_SHA=$(git rev-parse HEAD) |
| 109 | INSTALLER_FILE=${STACK_TYPE}-ubuntu1804.bsx |
| 110 | BUILD_ARTIFACTS=${STACK_TYPE}-ubuntu1804.bsx |
| 111 | NORDIX_ARM_REPO=nordix-${STACK_TYPE} |
| 112 | NORDIX_ARTIFACT_URL=$NORDIX_ARTIFACT_URL |
| 113 | EOF |
| 114 | |
| 115 | echo "Info : Change metadata" |
| 116 | echo "-------------------------------------------------------------------------" |
| 117 | cat "$CHANGE_METADATA_FILE" |
| 118 | echo "-------------------------------------------------------------------------" |
| 119 | |
| 120 | # vim: set ts=2 sw=2 expandtab: |