-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-oracledb.sh
executable file
Β·211 lines (186 loc) Β· 6.65 KB
/
setup-oracledb.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
# Since: January, 2023
# Author: aalmiray, gvenzl
#
# Copyright 2023-2024 Andres Almiray, Gerald Venzl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ORADATA="/opt/oracle/oradata"
DEFAULT_CONTAINER_NAME="oracledb"
HEALTH_MAX_RETRIES=0
HEALTH_INTERVAL=0
CONTAINER_RUNTIME=""
CONTAINER_ARGS=""
CONTAINER_IMAGE=""
CONTAINER_NAME=""
VALIDATION="OK"
FASTSTART=""
###############################################################################
echo "::group::π Verifying inputs"
# CONTAINER_RUNTIME
# If the setup container runtime is set, verify the runtime is available
if [ -n "${SETUP_CONTAINER_RUNTIME}" ]; then
# Container runtime exists
if type "${SETUP_CONTAINER_RUNTIME}" > /dev/null; then
CONTAINER_RUNTIME="${SETUP_CONTAINER_RUNTIME}"
echo "β
container runtime set to ${CONTAINER_RUNTIME}"
fi
fi
# If container runtime is empty (either doesn't exist, or wasn't passed on), find default
if [ -z "${CONTAINER_RUNTIME}" ]; then
if type podman > /dev/null; then
CONTAINER_RUNTIME="podman"
echo "βοΈοΈ container runtime set to ${CONTAINER_RUNTIME} (default)"
elif type docker > /dev/null; then
CONTAINER_RUNTIME="docker"
echo "βοΈοΈ container runtime set to ${CONTAINER_RUNTIME} (default)"
else
echo "β container runtime not available."
VALIDATION=""
fi
fi
# TAG
if [ -z "${SETUP_TAG}" ]; then
SETUP_TAG="latest"
fi
echo "β
tag set to ${SETUP_TAG}"
CONTAINER_IMAGE="gvenzl/oracle-free:${SETUP_TAG}"
# PORT
if [ -z "${SETUP_PORT}"]; then
echo "βοΈοΈ container host port set to 1521 (default)"
SETUP_PORT=1521
fi;
echo "β
port set to ${SETUP_PORT}"
CONTAINER_ARGS="-p 1521:${SETUP_PORT}"
# CONTAINER_NAME
if [ -n "${SETUP_CONTAINER_NAME}" ]; then
echo "β
container name set to ${SETUP_CONTAINER_NAME}"
CONTAINER_NAME=${SETUP_CONTAINER_NAME}
else
echo "βοΈοΈ container name set to ${DEFAULT_CONTAINER_NAME} (default)"
CONTAINER_NAME=${DEFAULT_CONTAINER_NAME}
fi
CONTAINER_ARGS="${CONTAINER_ARGS} --name ${CONTAINER_NAME}"
# HEALTH_MAX_RETRIES
if [ -n "${SETUP_HEALTH_MAX_RETRIES}" ]; then
echo "β
health max retries set to ${SETUP_HEALTH_MAX_RETRIES}"
HEALTH_MAX_RETRIES=$SETUP_HEALTH_MAX_RETRIES
else
# Set default if scripts is invoked outside the GH Action (otherwise this is set in action.yml)
echo "βοΈοΈ health max retries set to 60 (default)"
HEALTH_MAX_RETRIES=60
fi
# HEALTH_INTERVAL
if [ -n "${SETUP_HEALTH_INTERVAL}" ]; then
echo "β
health interval set to ${SETUP_HEALTH_INTERVAL}"
HEALTH_INTERVAL=${SETUP_HEALTH_INTERVAL}
else
# Set default if scripts is invoked outside the GH Action (otherwise this is set in action.yml)
echo "βοΈοΈ health interval set to 3 (default)"
HEALTH_INTERVAL=3
fi
# VOLUME
if [ -n "${SETUP_VOLUME}" ]; then
# skip volume if tag ends with 'faststart'
FASTSTART=$(echo "${SETUP_TAG}" | grep -Eq "^.*faststart$" && echo "true" || echo "false")
if [ "${FASTSTART}" = "true" ]; then
echo "β οΈ Volume ${SETUP_VOLUME} skipped because tag is ${SETUP_TAG}"
else
echo "β
volume set to ${SETUP_VOLUME} mapped to ${ORADATA}"
CONTAINER_ARGS="${CONTAINER_ARGS} -v ${SETUP_VOLUME}:${ORADATA}"
chmod 777 "${SETUP_VOLUME}"
fi
fi
# PASSWORD
if [ -z "${SETUP_ORACLE_PASSWORD}" ]; then
echo "β οΈ Oracle password will be randomly generated"
CONTAINER_ARGS="${CONTAINER_ARGS} -e ORACLE_RANDOM_PASSWORD=true"
else
echo "β
ORACLE_PASSWORD explicitly set"
CONTAINER_ARGS="${CONTAINER_ARGS} -e ORACLE_PASSWORD=${SETUP_ORACLE_PASSWORD}"
fi
# DATABASE
if [ -n "${SETUP_ORACLE_DATABASE}" ]; then
echo "β
database name set to ${SETUP_ORACLE_DATABASE}"
CONTAINER_ARGS="${CONTAINER_ARGS} -e ORACLE_DATABASE=${SETUP_ORACLE_DATABASE}"
fi
# APP_USER
if [ -n "${SETUP_APP_USER}" ]; then
echo "β
APP_USER explicitly set"
CONTAINER_ARGS="${CONTAINER_ARGS} -e APP_USER=${SETUP_APP_USER}"
else
echo "β APP_USER is not set"
VALIDATION=""
fi
# APP_USER_PASSWORD
if [ -n "${SETUP_APP_USER_PASSWORD}" ]; then
echo "β
APP_USER_PASSWORD explicitly set"
CONTAINER_ARGS="${CONTAINER_ARGS} -e APP_USER_PASSWORD=${SETUP_APP_USER_PASSWORD}"
else
echo "β APP_USER_PASSWORD is not set"
VALIDATION=""
fi
# SETUP_SCRIPTS
if [ -n "${SETUP_SETUP_SCRIPTS}" ]; then
echo "β
setup scripts from ${SETUP_SETUP_SCRIPTS}"
CONTAINER_ARGS="${CONTAINER_ARGS} -v ${SETUP_SETUP_SCRIPTS}:/container-entrypoint-initdb.d"
fi
# STARTUP_SCRIPTS
if [ -n "${SETUP_STARTUP_SCRIPTS}" ]; then
echo "β
startup scripts from ${SETUP_STARTUP_SCRIPTS}"
CONTAINER_ARGS="${CONTAINER_ARGS} -v ${SETUP_STARTUP_SCRIPTS}:/container-entrypoint-startdb.d"
fi
if [ -n "${VALIDATION}" ]; then
echo "β
All inputs are valid"
else
echo "β Validation failed"
fi
echo "::endgroup::"
###############################################################################
if [ -z "${VALIDATION}" ]; then
exit 1;
fi
###############################################################################
echo "::group::π³ Running Container"
CMD="${CONTAINER_RUNTIME} run -d ${CONTAINER_ARGS} ${CONTAINER_IMAGE}"
echo "${CMD}"
# Run Docker container
eval "${CMD}"
echo "::endgroup::"
###############################################################################
###############################################################################
echo "::group::β° Waiting for database to be ready"
DB_IS_UP=""
EXIT_VALUE=0
for ((COUNTER=1; COUNTER <= HEALTH_MAX_RETRIES; COUNTER++))
do
echo " - try #${COUNTER} of ${HEALTH_MAX_RETRIES}"
sleep "${HEALTH_INTERVAL}"
DB_IS_UP=$("${CONTAINER_RUNTIME}" exec "${CONTAINER_NAME}" healthcheck.sh && echo "yes" || echo "no")
if [ "${DB_IS_UP}" = "yes" ]; then
break
fi
done
echo "::endgroup::"
# Start a new group so that database readiness or failure is visible in actions.
if [ "${DB_IS_UP}" = "yes" ]; then
echo "::group::β
Database is ready!"
else
echo "::group::β Database failed to start on time."
echo "π Container logs:"
"${CONTAINER_RUNTIME}" logs "${CONTAINER_NAME}"
EXIT_VALUE=1
fi
echo "::endgroup::"
###############################################################################
exit ${EXIT_VALUE}