Report: Add rls data
[csit.git] / resources / libraries / bash / function / nginx.sh
1 #!/usr/bin/env bash
2
3 # Copyright (c) 2021 Intel 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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 set -exuo pipefail
17
18
19 function gather_nginx () {
20
21     # Ensure stable NGINX archive is downloaded.
22     #
23     # Variables read:
24     # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
25     # - NGINX_VER - Version number of Nginx.
26     set -exuo pipefail
27     pushd "${DOWNLOAD_DIR}" || die "Pushd failed."
28     nginx_repo="http://nginx.org/download/"
29     # Use downloaded packages with specific version
30     echo "Downloading NGINX package of specific version from repo ..."
31     # Downloading NGINX version based on what VPP is using. Currently
32     # it is not easy way to detect from VPP version automatically.
33     nginx_stable_ver="${NGINX_VER}".tar.gz
34
35     if [[ ! -f "${nginx_stable_ver}" ]]; then
36         wget -nv --no-check-certificate \
37         "${nginx_repo}/${nginx_stable_ver}"  || {
38             die "Failed to get NGINX package from: ${nginx_repo}."
39         }
40     fi
41     popd || die "Popd failed."
42 }
43
44
45 function common_dirs () {
46
47     # Set global variables, create some directories (without touching content).
48     # This function assumes running in remote testbed. It might override other
49     # functions if included from common.sh.
50
51     # Arguments:
52     # - ${1} - Version number of Nginx.
53     # Variables set:
54     # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
55     # - CSIT_DIR - Path to CSIT framework.
56     # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
57     # - NGINX_DIR - Path to NGINX framework.
58     # - NGINX_VER - Version number of Nginx.
59     # Functions called:
60     # - die - Print to stderr and exit.
61
62     set -exuo pipefail
63     NGINX_VER="${1}"
64     this_file=$(readlink -e "${BASH_SOURCE[0]}") || {
65         die "Some error during locating of this source file."
66     }
67     BASH_FUNCTION_DIR=$(dirname "${this_file}") || {
68         die "Some error during dirname call."
69     }
70     CSIT_DIR=$(readlink -e "/tmp/openvpp-testing") || {
71         die "Readlink failed."
72     }
73     DOWNLOAD_DIR=$(readlink -f "${CSIT_DIR}/download_dir") || {
74         die "Readlink failed."
75     }
76     mkdir -p "${CSIT_DIR}/${NGINX_VER}" || die "Mkdir failed."
77     NGINX_DIR=$(readlink -e "${CSIT_DIR}/${NGINX_VER}") || {
78         die "Readlink failed."
79     }
80 }
81
82
83
84 function nginx_compile () {
85
86     # Compile NGINX archive.
87     #
88     # Variables read:
89     # - NGINX_DIR - Path to NGINX framework.
90     # - CSIT_DIR - Path to CSIT framework.
91     # - NGINX_INS_PATH - Path to NGINX install path.
92     # Functions called:
93     # - die - Print to stderr and exit.
94
95     set -exuo pipefail
96     NGINX_INS_PATH="${DOWNLOAD_DIR}/${NGINX_VER}"
97     pushd "${NGINX_DIR}" || die "Pushd failed."
98
99     # Set installation prefix.
100     param="--prefix=${NGINX_INS_PATH} "
101     # Set nginx binary pathname.
102     param+="--sbin-path=${NGINX_INS_PATH}/sbin/nginx "
103     # Set nginx.conf pathname.
104     param+="--conf-path=${NGINX_INS_PATH}/conf/nginx.conf "
105     # Enable ngx_http_stub_status_module.
106     param+="--with-http_stub_status_module "
107     # Force PCRE library usage.
108     param+="--with-pcre "
109     # Enable ngx_http_realip_module.
110     param+="--with-http_realip_module "
111     params=(${param})
112     ./configure "${params[@]}" || die "Failed to configure NGINX!"
113     make -j 16;make install || die "Failed to compile NGINX!"
114 }
115
116
117 function nginx_extract () {
118
119     # Extract NGINX framework.
120     #
121     # Variables read:
122     # - NGINX_DIR - Path to NGINX framework.
123     # - CSIT_DIR - Path to CSIT framework.
124     # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
125     # - NGINX_VER - Version number of Nginx.
126     # Functions called:
127     # - die - Print to stderr and exit.
128
129     set -exuo pipefail
130
131     pushd "${CSIT_DIR}" || die "Pushd failed."
132     tar -xvf ${DOWNLOAD_DIR}/${NGINX_VER}.tar.gz --strip=1 \
133           --directory "${NGINX_DIR}" || {
134           die "Failed to extract NGINX!"
135     }
136 }