Skip to content

Commit 7537e5c

Browse files
Add support to deploy pgadmin in container with readOnlyRootFilesystem as true.#7330
1 parent c0a6ff3 commit 7537e5c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

pkg/docker/entrypoint.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI_FILE}" ]; then
3636
fi
3737
file_env PGADMIN_DEFAULT_PASSWORD
3838

39+
# TO enable custom path for config_distro, pass config distro path via environment variable.
40+
export CONFIG_DISTRO_FILE_PATH="${CONFIG_DISTRO_FILE:-/pgadmin4/config_distro.py}"
41+
3942
# Populate config_distro.py. This has some default config, as well as anything
4043
# provided by the user through the PGADMIN_CONFIG_* environment variables.
4144
# Only update the file on first launch. The empty file is created during the
4245
# container build so it can have the required ownership.
43-
if [ "$(wc -m /pgadmin4/config_distro.py | awk '{ print $1 }')" = "0" ]; then
44-
cat << EOF > /pgadmin4/config_distro.py
46+
if [ "$(wc -m "${CONFIG_DISTRO_FILE_PATH}" | awk '{ print $1 }')" = "0" ]; then
47+
cat << EOF > "${CONFIG_DISTRO_FILE_PATH}"
4548
CA_FILE = '/etc/ssl/certs/ca-certificates.crt'
4649
LOG_FILE = '/dev/null'
4750
HELP_PATH = '../../docs'
@@ -61,7 +64,7 @@ EOF
6164
for var in $(env | grep "^PGADMIN_CONFIG_" | cut -d "=" -f 1); do
6265
# shellcheck disable=SC2086
6366
# shellcheck disable=SC2046
64-
echo ${var#PGADMIN_CONFIG_} = $(eval "echo \$$var") >> /pgadmin4/config_distro.py
67+
echo ${var#PGADMIN_CONFIG_} = $(eval "echo \$$var") >> "${CONFIG_DISTRO_FILE_PATH}"
6568
done
6669
fi
6770

web/pgadmin/evaluate_config.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
import os
1111
import sys
1212
import keyring
13-
import email_validator
13+
import importlib.util
1414

1515
# User configs loaded from config_local, config_distro etc.
1616
custom_config_settings = {}
1717

18-
1918
# Function to Extract settings from config_local, config_distro etc.
2019
def get_variables_from_module(module_name):
2120
module = globals().get(module_name, None)
@@ -27,6 +26,17 @@ def get_variables_from_module(module_name):
2726
return variables
2827

2928

29+
# Function to load config_distro at custom path
30+
def import_module_from_path(module_name, file_path):
31+
# Create a module spec
32+
spec = importlib.util.spec_from_file_location(module_name, file_path)
33+
# Create the module based on the spec
34+
module = importlib.util.module_from_spec(spec)
35+
# Execute the module (this loads it)
36+
spec.loader.exec_module(module)
37+
return module
38+
39+
3040
def validate_config_variable(key, value):
3141
boolean_keys = ['SERVER_MODE', 'ENHANCED_COOKIE_PROTECTION',
3242
'SUPPORT_SSH_TUNNEL', 'ALLOW_SAVE_TUNNEL_PASSWORD',
@@ -47,7 +57,10 @@ def validate_config_variable(key, value):
4757

4858
# Load distribution-specific config overrides
4959
try:
50-
import config_distro
60+
if 'CONFIG_DISTRO_FILE_PATH' in os.environ:
61+
config_distro_path = os.environ['CONFIG_DISTRO_FILE_PATH']
62+
config_distro = import_module_from_path('config_distro',
63+
config_distro_path)
5164
config_distro_settings = get_variables_from_module('config_distro')
5265
custom_config_settings.update(config_distro_settings)
5366
except ImportError:

0 commit comments

Comments
 (0)