Commit | Line | Data |
---|---|---|
68b6e210 KS |
1 | #!/bin/bash |
2 | # shellcheck disable=SC2103 | |
3 | # | |
4 | # Copyright (C) 2021 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
5dd2d236 | 5 | # 2023 Michael Jeanson <mjeanson@efficios.com> |
68b6e210 KS |
6 | # |
7 | # This program is free software: you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation, either version 3 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | set -exu | |
21 | ||
5dd2d236 MJ |
22 | print_header() { |
23 | set +x | |
24 | ||
25 | local message=" $1 " | |
26 | local message_len | |
27 | local padding_len | |
28 | ||
29 | message_len="${#message}" | |
30 | padding_len=$(( (80 - (message_len)) / 2 )) | |
31 | ||
32 | printf '\n'; printf -- '#%.0s' {1..80}; printf '\n' | |
33 | printf -- '-%.0s' {1..80}; printf '\n' | |
34 | printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n' | |
35 | printf -- '-%.0s' {1..80}; printf '\n' | |
36 | printf -- '#%.0s' {1..80}; printf '\n\n' | |
37 | ||
38 | set -x | |
39 | } | |
68b6e210 KS |
40 | |
41 | # Add ssh key for deployment | |
42 | cp "$HOST_PUBLIC_KEYS" ~/.ssh/known_hosts | |
43 | cp "$KEY_FILE_VARIABLE" ~/.ssh/id_rsa | |
44 | ||
5dd2d236 | 45 | export DEBIAN_FRONTEND=noninteractive |
69114bc9 | 46 | apt-get update |
68b6e210 | 47 | |
5dd2d236 MJ |
48 | print_header "Install web tooling dependencies" |
49 | apt-get install -y jekyll npm grunt python3 python3-pip python3-venv linkchecker | |
68b6e210 | 50 | |
5dd2d236 | 51 | print_header "Install babeltrace build dependencies" |
68b6e210 KS |
52 | apt-get install -y asciidoc xmlto libdw-dev libelf-dev elfutils autoconf automake libglib2.0-dev make doxygen flex bison |
53 | ||
5dd2d236 | 54 | print_header "Install NPM stuff" |
68b6e210 KS |
55 | npm install |
56 | ||
5dd2d236 MJ |
57 | print_header "Install Python requirements" |
58 | python3 -m venv build_venv | |
59 | source build_venv/bin/activate | |
68b6e210 KS |
60 | pip install -r requirements.txt |
61 | ||
62 | # Setting TERM avoids spurious warnings when configure is checking TPUT, as | |
63 | # $TERM is not set in the build environment. | |
64 | # As we've already opened a venv, set SKIP_VENV so the python job doesn't | |
65 | # create a second nested virtual environment. | |
5dd2d236 MJ |
66 | print_header "Build website with grunt" |
67 | TERM=dumb SKIP_VENV=1 VERBOSE=1 grunt build:prod --verbose | |
69114bc9 | 68 | |
5dd2d236 | 69 | print_header "Check links" |
69114bc9 KS |
70 | grunt connect:prod watch:prod & |
71 | SERVER_PID="${!}" | |
72 | sleep 10 # While serve:prod starts up | |
5dd2d236 MJ |
73 | |
74 | OUTPUT_DIR="$(mktemp -d)" | |
75 | OUTPUT_FILE="${OUTPUT_DIR}/linkchecker-out.csv" | |
76 | ||
77 | # linkchecker drops privileges to 'nobody' when run as root | |
78 | chown nobody "${OUTPUT_DIR}" | |
79 | ||
69114bc9 KS |
80 | # @Note: Only internal links are checked by default |
81 | if ! linkchecker -q -F "csv/utf-8/${OUTPUT_FILE}" http://localhost:10000/ ; then | |
82 | echo "Linkchecker failed or found broken links" | |
83 | cat "${OUTPUT_FILE}" | |
84 | kill "${SERVER_PID}" | |
5dd2d236 | 85 | rm -rf "${OUTPUT_DIR}" |
69114bc9 KS |
86 | sleep 5 # Let serve:prod stop |
87 | exit 1 | |
88 | else | |
5dd2d236 | 89 | rm -rf "${OUTPUT_DIR}" |
69114bc9 KS |
90 | kill "${SERVER_PID}" |
91 | fi | |
92 | ||
5dd2d236 | 93 | print_header "Deploy website" |
68b6e210 KS |
94 | grunt deploy:prod --verbose |
95 | ||
96 | # In the venv functions generated by the version of python installed on bionic | |
97 | # nodes, the deactivate function checks undefined variables (eg. $1) which causes | |
98 | # the build to fail when `set -u` is in effect. | |
99 | set +u | |
100 | deactivate | |
101 | ||
102 | # EOF |