Skip to content

Commit b3b700a

Browse files
committed
Uninstall unused postgresql-client on startup
Unused clients are determinate by checking ~/.postgresqlrc Uninstall logs like the following will appear in the docker log: - Uninstalling unused version(s) of client: postgresql-client-12
1 parent 260f548 commit b3b700a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

assets/runtime/functions

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,36 @@ gitlab_generate_postgresqlrc() {
220220
echo "${DB_CLIENT_VERSION_PACKAGE_NAME} ${DB_HOST}:${DB_PORT} ${DB_NAME}" | exec_as_git tee "${GITLAB_USER_POSTGRESQLRC}"
221221
}
222222

223+
gitlab_uninstall_unused_database_client() {
224+
if [[ -f "/home/${GITLAB_USER}/.postgresqlrc" ]]; then
225+
# refer /home/${GITLAB_USER}/.postgresqlrc and pick up versions in use
226+
# .postgresqlrc contains following information per line
227+
# database_major_version host:port database_name
228+
# - ignore lines starts with # by specifying pattern /^[^#]/
229+
# - first field is the version number in use.
230+
# - cocnat whole lines into single string. convert newline to \|
231+
# this is escaped regex "OR"
232+
# now we got the following regex that can be used as an option to grep:
233+
# \|-12\|-13
234+
DB_CLIENT_VERSIONS_IN_USE="$(awk '/^[^#]/ {printf("\|-%s",$1)}' "/home/${GITLAB_USER}/.postgresqlrc")"
235+
236+
# we also need to keep postgresql-client-common package to switch based on ~/.postgresqlrc
237+
REGEX_DB_CLIENT_VERSIONS_IN_USE="-common${DB_CLIENT_VERSIONS_IN_USE}"
238+
239+
# remove unused client using regex above
240+
UNUSED_DB_CLIENTS=$(apt-cache pkgnames postgresql-client | grep -v -e "${REGEX_DB_CLIENT_VERSIONS_IN_USE}" | tr '\n' ' ')
241+
echo "- Uninstalling unused client(s): ${UNUSED_DB_CLIENTS}"
242+
DEBIAN_FRONTEND=noninteractive apt-get -qq remove -- ${UNUSED_DB_CLIENTS} >/dev/null
243+
fi
244+
}
245+
223246
gitlab_configure_database() {
224247
echo -n "Configuring gitlab::database"
225248

226249
gitlab_finalize_database_parameters
227250
gitlab_check_database_connection
228251
gitlab_generate_postgresqlrc
252+
gitlab_uninstall_unused_database_client
229253

230254
update_template ${GITLAB_DATABASE_CONFIG} \
231255
DB_ENCODING \

0 commit comments

Comments
 (0)