3 # Copyright (c) 2023 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function die_on_error () {
21 # Source this fragment if you want to abort on any failure.
24 # - ${CODE_EXIT_STATUS} - Exit status of report generation.
26 # - die - Print to stderr and exit.
30 if [[ "${CODE_EXIT_STATUS}" != "0" ]]; then
31 die "Failed to generate docs!" "${CODE_EXIT_STATUS}"
36 function eb_version_deploy () {
38 # Deploy Elastic Beanstalk CDash content.
41 # - ${CSIT_DIR} - CSIT main directory.
42 # - ${TERRAFORM_OUTPUT_VAL} - Terraform output value.
44 # - ${CODE_EXIT_STATUS} - Exit status of report generation.
45 # - ${TERRAFORM_OUTPUT_VAR} - Register Terraform output variable name.
47 # - eb_version_verify - Build and verify EB version.
48 # - terraform_apply - Apply EB version by Terraform.
49 # - terraform_output - Get the application name string from Terraform.
50 # - die - Print to stderr and exit.
54 eb_version_build_verify || die "Failed to call Elastic Beanstalk verify!"
55 terraform_apply || die "Failed to call Terraform apply!"
57 TERRAFORM_OUTPUT_VAR="application_version"
58 terraform_output || die "Failed to call Terraform output!"
60 #aws --region eu-central-1 elasticbeanstalk update-environment \
61 # --environment-name fdio-csit-dash-env \
62 # --version-label "${TERRAFORM_OUTPUT_VAL}"
66 function eb_version_build_verify () {
68 # Build and verify Elastic Beanstalk CDash integrity.
71 # - ${CSIT_DIR} - CSIT main directory.
73 # - ${TERRAFORM_MODULE_DIR} - Terraform module sub-directory.
75 # - hugo_init_modules - Initialize Hugo modules.
76 # - hugo_build_site - Build static site with Hugo.
77 # - terraform_init - Initialize Terraform modules.
78 # - terraform_validate - Validate Terraform code.
79 # - die - Print to stderr and exit.
83 if ! installed zip; then
84 die "Please install zip!"
87 hugo_init_modules || die "Failed to call Hugo initialize!"
88 hugo_build_site || die "Failed to call Hugo build!"
90 pushd "${CSIT_DIR}"/csit.infra.dash || die "Pushd failed!"
91 pushd app || die "Pushd failed!"
92 find . -type d -name "__pycache__" -exec rm -rf "{}" \;
93 find . -type d -name ".webassets-cache" -exec rm -rf "{}" \;
94 zip -r ../app.zip . || die "Compress failed!"
95 popd || die "Popd failed!"
96 popd || die "Popd failed!"
98 TERRAFORM_MODULE_DIR="terraform-aws-fdio-csit-dash-app-base"
100 export TF_VAR_application_version="${BUILD_ID}"
101 terraform_init || die "Failed to call Terraform init!"
102 terraform_validate || die "Failed to call Terraform validate!"
106 function generate_report () {
108 # Generate report content.
111 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
112 # - ${GERRIT_BRANCH} - Gerrit branch used for release tagging.
114 # - ${CODE_EXIT_STATUS} - Exit status of report generation.
116 # - die - Print to stderr and exit.
120 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
122 # Set default values in config array.
128 # Create working directories.
129 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
131 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
133 all_options=("pal.py")
134 all_options+=("--specification" "specifications/report")
135 all_options+=("--release" "${GERRIT_BRANCH:-master}")
136 all_options+=("--week" $(date "+%V"))
137 all_options+=("--logging" "INFO")
138 all_options+=("--force")
141 python "${all_options[@]}"
142 CODE_EXIT_STATUS="$?"
146 function installed () {
148 # Check if the given utility is installed. Fail if not installed.
151 # - ${1} - Utility to check.
152 # Returns (implicitly):
153 # - 0 - If command is installed.
154 # - 1 - If command is not installed.