| #!/bin/bash |
| |
| # ============LICENSE_START======================================================= |
| # Copyright (C) 2019 The Nordix Foundation. All rights reserved. |
| # ================================================================================ |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # SPDX-License-Identifier: Apache-2.0 |
| # ============LICENSE_END========================================================= |
| |
| |
| set -o nounset |
| set -o errexit |
| set -o pipefail |
| |
| # NOTE (fdegir): we need to remove $WORKSPACE and clone infra/engine repository |
| # as infra/engine is what drives the deployment |
| if [[ "$GERRIT_PROJECT" != "infra/engine" ]]; then |
| cd "$HOME" && /bin/rm -rf "$WORKSPACE" |
| echo "Info : Cloning infra/engine repository" |
| git clone -q https://gerrit.nordix.org/infra/engine.git "$WORKSPACE" |
| cd "$WORKSPACE" |
| fi |
| |
| # file to record change metadata |
| export CHANGE_METADATA_FILE="$WORKSPACE/change.properties" |
| /bin/rm -f "$CHANGE_METADATA_FILE" |
| |
| echo "Info : Generating change metadata" |
| |
| # determine the project |
| # this scripts is used by all engine repos so we need to determine what this change is for |
| export ENGINE_COMPONENT="${GERRIT_PROJECT//*\//}" |
| |
| echo "Info : Setting STACK_TYPE and STACK_VERSION" |
| if [[ "$GERRIT_PROJECT" =~ /stack/ ]]; then |
| # set vars |
| export STACK_TYPE="$ENGINE_COMPONENT" |
| export STACK_VERSION="$GERRIT_PATCHSET_REVISION" |
| export STACK_REFSPEC="$GERRIT_REFSPEC" |
| |
| # log info to console |
| echo " STACK_TYPE=$STACK_TYPE" |
| echo " STACK_VERSION=$GERRIT_PATCHSET_REVISION" |
| echo " STACK_REFSPEC=$GERRIT_REFSPEC" |
| |
| # record vars to properties file |
| echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
| echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| echo "STACK_REFSPEC=$STACK_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| elif [[ "$GERRIT_PROJECT" =~ /installer/ ]]; then |
| # set vars |
| case "${ENGINE_COMPONENT}" in |
| kolla) |
| export STACK_TYPE="openstack" |
| ;; |
| kubespray) |
| export STACK_TYPE="kubernetes" |
| ;; |
| oom) |
| export STACK_TYPE="onap" |
| ;; |
| *) echo "ERROR : Invalid engine component $ENGINE_COMPONENT"; exit 1;; |
| esac |
| export STACK_VERSION="$GERRIT_BRANCH" |
| |
| # log info to console |
| echo " STACK_TYPE=$STACK_TYPE" |
| echo " STACK_VERSION=$STACK_VERSION" |
| echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" |
| echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" |
| |
| # record vars to properties file |
| echo "STACK_TYPE=$STACK_TYPE" >> "$CHANGE_METADATA_FILE" |
| echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| else |
| # set vars |
| export STACK_TYPE=kubernetes |
| export STACK_VERSION=$GERRIT_BRANCH |
| |
| # log info to console |
| echo " STACK_TYPE=$STACK_TYPE" |
| echo " STACK_VERSION=$STACK_VERSION" |
| echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" |
| echo " NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" |
| |
| # record vars to properties file |
| echo "STACK_TYPE=kubernetes" >> "$CHANGE_METADATA_FILE" |
| echo "STACK_VERSION=$STACK_VERSION" >> "$CHANGE_METADATA_FILE" |
| echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_VERSION=$GERRIT_PATCHSET_REVISION" >> "$CHANGE_METADATA_FILE" |
| echo "NORDIX_$(echo $ENGINE_COMPONENT | tr a-z A-Z)_REFSPEC=$GERRIT_REFSPEC" >> "$CHANGE_METADATA_FILE" |
| fi |
| |
| # global vars |
| export NORDIX_ARM_HTTPS_URL="https://artifactory.nordix.org/artifactory" |
| export ARTIFACT_ARM_FOLDER="gerrit" |
| export BUILD_IDENTIFIER=$GERRIT_CHANGE_NUMBER |
| export INSTALLER_FILE="${STACK_TYPE}-${DISTRO}.bsx" |
| export BUILD_ARTIFACTS="${STACK_TYPE}-${DISTRO}.bsx" |
| export NORDIX_ARM_REPO="nordix-${STACK_TYPE}" |
| export NORDIX_ARTIFACT_URL="$NORDIX_ARM_HTTPS_URL/$NORDIX_ARM_REPO/installer/oss/$ARTIFACT_ARM_FOLDER/$BUILD_IDENTIFIER" |
| |
| cat << EOF >> "$CHANGE_METADATA_FILE" |
| BUILD_IDENTIFIER=$BUILD_IDENTIFIER |
| BUILD_DATE=$(date '+%Y%m%d%H%M') |
| BUILT_BY=$BUILD_URL |
| DISTRO=$DISTRO |
| CI_LOOP=$CI_LOOP |
| ENGINE_SHA=$(git rev-parse HEAD) |
| INSTALLER_FILE=${STACK_TYPE}-ubuntu1804.bsx |
| BUILD_ARTIFACTS=${STACK_TYPE}-ubuntu1804.bsx |
| NORDIX_ARM_REPO=nordix-${STACK_TYPE} |
| NORDIX_ARTIFACT_URL=$NORDIX_ARTIFACT_URL |
| EOF |
| |
| echo "Info : Change metadata" |
| echo "-------------------------------------------------------------------------" |
| cat "$CHANGE_METADATA_FILE" |
| echo "-------------------------------------------------------------------------" |
| |
| # vim: set ts=2 sw=2 expandtab: |