-
Notifications
You must be signed in to change notification settings - Fork 36
/
server_config_gen.sh
executable file
·108 lines (90 loc) · 2.49 KB
/
server_config_gen.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
#!/bin/bash
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
export GIT_COMMIT=$(git rev-parse HEAD)
NPM_INFO="undefined"
PATTERNFLY_DEPS="undefined"
export USES_CADDY=true
SERVER_NAME=${SERVER_NAME:-$APP_NAME}
generate_caddy_config() {
local ROUTE_PATH=${ROUTE_PATH:-"/apps/${APP_NAME}"}
# The spacing on the bash format here makes the closing bracket
# look odd, but it's fine.
echo "{
{\$CADDY_TLS_MODE}
auto_https disable_redirects
servers {
metrics
}
}
:9000 {
metrics /metrics
}
:8000 {
{\$CADDY_TLS_CERT}
log
# Handle main app route
@app_match {
path ${ROUTE_PATH}*
}
handle @app_match {
uri strip_prefix ${ROUTE_PATH}
file_server * {
root /srv/${OUTPUT_DIR}
browse
}
}
handle / {
redir /apps/chrome/index.html permanent
}
}
"
}
generate_docker_ignore() {
cat << EOF
node_modules
.git
EOF
}
# FIXME: How's this any different from the "build_app_info.sh script??"
generate_app_info() {
if [[ -f package-lock.json ]] || [[ -f yarn.lock ]]; then
LINES=$(npm list --silent --depth=0 --production | grep @patternfly -i | sed -E "s/^(.{0})(.{4})/\1/" | tr "\n" "," | sed -E "s/,/\",\"/g")
PATTERNFLY_DEPS="[\"${LINES%???}\"]"
LINES=$(npm list --silent --depth=0 --production | grep @redhat-cloud-services -i | sed -E "s/^(.{0})(.{4})/\1/" | tr "\n" "," | sed -E "s/,/\",\"/g")
RH_CLOUD_SERVICES_DEPS="[\"${LINES%???}\"]"
else
PATTERNFLY_DEPS="[]"
RH_CLOUD_SERVICES_DEPS="[]"
fi
echo -n "{
\"app_name\": \"$APP_NAME\",
\"src_hash\": \"$GIT_COMMIT\",
\"patternfly_dependencies\": $PATTERNFLY_DEPS,
\"rh_cloud_services_dependencies\": $RH_CLOUD_SERVICES_DEPS
}"
}
# Now we check for a Caddyfile and if it's correct to generate
if [[ -f Caddyfile ]]; then
echo "Caddy config already exists, skipping generation"
else
generate_caddy_config > Caddyfile;
fi
if [[ -f .dockerignore ]]; then
echo "Docker ignore already exists, skipping generation"
else
generate_docker_ignore > .dockerignore
fi
if [[ -n "${APP_BUILD_DIR:-}" && -d $APP_BUILD_DIR ]]; then
OUTPUT_DIR="$APP_BUILD_DIR"
fi
if [[ -f "${OUTPUT_DIR}/app.info.deps.json" ]]; then
echo "app.info.deps.json already exists, skipping generation"
else
echo $NPM_INFO > "${OUTPUT_DIR}/app.info.deps.json"
fi
if [[ -f "${OUTPUT_DIR}/app.info.json" ]]; then
echo "app.info.json already exists, skipping generation"
else
generate_app_info > "${OUTPUT_DIR}/app.info.json"
fi