3 # Copyright (c) 2024 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 # - ${TERRAFORM_MODULE_DIR} - Terraform module sub-directory.
73 # - terraform_init - Initialize Terraform modules.
74 # - terraform_validate - Validate Terraform code.
75 # - die - Print to stderr and exit.
79 eb_version_create_release || die "Failed to create release!"
81 TERRAFORM_MODULE_DIR="terraform-aws-fdio-csit-dash-app-base"
83 export TF_VAR_application_version="${BUILD_ID}"
84 terraform_init || die "Failed to call Terraform init!"
85 terraform_validate || die "Failed to call Terraform validate!"
89 function eb_version_create_release () {
91 # Create release of Elastic Beanstalk CDash.
94 # - ${CSIT_DIR} - CSIT main directory.
96 # - hugo_init_modules - Initialize Hugo modules.
97 # - hugo_build_site - Build static site with Hugo.
98 # - die - Print to stderr and exit.
102 if ! installed zip; then
103 die "Please install zip!"
106 hugo_init_modules || die "Failed to call Hugo initialize!"
107 hugo_build_site || die "Failed to call Hugo build!"
109 pushd "${CSIT_DIR}"/csit.infra.dash || die "Pushd failed!"
110 pushd app || die "Pushd failed!"
111 find . -type d -name "__pycache__" -exec rm -rf "{}" \;
112 find . -type d -name ".webassets-cache" -exec rm -rf "{}" \;
113 zip -r ../app.zip . || die "Compress failed!"
114 popd || die "Popd failed!"
115 popd || die "Popd failed!"
119 function installed () {
121 # Check if the given utility is installed. Fail if not installed.
124 # - ${1} - Utility to check.
125 # Returns (implicitly):
126 # - 0 - If command is installed.
127 # - 1 - If command is not installed.