-
Notifications
You must be signed in to change notification settings - Fork 40
/
image_generator.sh
executable file
·143 lines (113 loc) · 4.45 KB
/
image_generator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# This script generates readme for image using image.yml present in each directory
# master jinja2 tempalte exists at common/templates/image_readme.j2
set -x
set -e
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
pip install jinja-cli PyYAML ruamel.yaml
gen_image_readme()
{
local config_name=$1
if [ -n "$config_name" ]; then
readme_path="${SCRIPTPATH}"/../community_images/"${config_name}"/README.md
echo "Target Image Readme: \"${readme_path}\""
# this allows us to merge bitnami tags file into image.yml
python3 "${SCRIPTPATH}"/prepare_image_yml.py \
"${SCRIPTPATH}"/../community_images/"${config_name}"/image.yml \
"${SCRIPTPATH}"/../community_images/"${config_name}"/image.tmp.yml
jinja -d community_images/"${config_name}"/image.tmp.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/image_readme.j2 > "${SCRIPTPATH}"/../community_images/"${config_name}"/README.md
rm -f community_images/"${p}"/image.tmp.yml
else
while IFS="" read -r p || [ -n "$p" ]
do
rm -f community_images/"${p}"/image.tmp.yml
# this allows us to merge bitnami tags file into image.yml
python3 "${SCRIPTPATH}"/prepare_image_yml.py \
"${SCRIPTPATH}"/../community_images/"${p}"/image.yml \
"${SCRIPTPATH}"/../community_images/"${p}"/image.tmp.yml
jinja -d community_images/"${p}"/image.tmp.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/image_readme.j2 > "${SCRIPTPATH}"/../community_images/"${p}"/README.md
rm -f community_images/"${p}"/image.tmp.yml
done < "${SCRIPTPATH}"/../image.lst
fi
}
gen_main_readme()
{
echo "Generating main readme"
rm -f "${SCRIPTPATH}"/../image_list.yml
python3 "${SCRIPTPATH}"/gen_image_list.py "${SCRIPTPATH}"/../image.lst yes
jinja -d "${SCRIPTPATH}"/../image_list.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/main_readme.j2 > "${SCRIPTPATH}"/../README.md
jinja -d "${SCRIPTPATH}"/../image_list.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/monitor.yml.j2 > "${SCRIPTPATH}"/../.github/workflows/monitor.yml
jinja -d "${SCRIPTPATH}"/../image_list.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/readme_updater.yml.j2 > "${SCRIPTPATH}"/../.github/workflows/readme_updater.yml
jinja -d "${SCRIPTPATH}"/../image_list.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/frontrow.csv.j2 > "${SCRIPTPATH}"/../frontrow.csv
jinja -d "${SCRIPTPATH}"/../community_images/common/templates/image_yml_params.yml \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/image_yml_readme.j2 > "${SCRIPTPATH}"/../image_yml.md
rm -f "${SCRIPTPATH}"/../image_list.yml
}
gen_new_image_actions()
{
rm -f "${SCRIPTPATH}"/../image_list.yml
python3 "${SCRIPTPATH}"/gen_image_list.py "${SCRIPTPATH}"/../builder.lst no
jinja -d "${SCRIPTPATH}"/../image_list.yml -D output main_build \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/image_run_v3.yml.j2 > "${SCRIPTPATH}"/../.github/workflows/image_run_v3.yml
jinja -d "${SCRIPTPATH}"/../image_list.yml -D output pull_request \
-f yaml "${SCRIPTPATH}"/../community_images/common/templates/image_run_v3.yml.j2 > "${SCRIPTPATH}"/../.github/workflows/image_run_pr_v3.yml
rm -f "${SCRIPTPATH}"/../image_list.yml
}
del_image_variants()
{
declare -a image_variants=( "airflow_airflow-scheduler_bitnami" "airflow_airflow-worker_bitnami" )
for image_variant in "${image_variants[@]}"; do
rm -f "${SCRIPTPATH}"/../.github/workflows/"${image_variant}".yml
done
}
main() {
python3 "${SCRIPTPATH}"/prepare_bitnami_tags.py
"${SCRIPTPATH}"/prepare_ironbank_tags.sh
gen_main_readme
gen_image_readme
gen_new_image_actions
del_image_variants
}
# Argument handling
usage() {
echo "Usage: $0 [--main-readme] [--image-readme] [--help]"
exit 1
}
if [ $# -eq 0 ]; then
main
exit 0
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
--main-readme)
gen_main_readme
del_image_variants
shift
;;
--image-readme)
if [ -n "$2" ] && [[ $2 != --* ]]; then
CONFIG_NAME=$2
shift 2
else
CONFIG_NAME="" # Set to empty if not provided
shift 1
fi
python3 "${SCRIPTPATH}"/prepare_bitnami_tags.py
gen_image_readme "$CONFIG_NAME"
del_image_variants
;;
--help|-h)
usage
;;
*)
echo "Unknown parameter: $1"
usage
;;
esac
done