Skip to content

Commit

Permalink
Add support to deploy pgadmin in container with readOnlyRootFilesyste…
Browse files Browse the repository at this point in the history
…m as true.pgadmin-org#7330
  • Loading branch information
yogeshmahajan-1903 committed Dec 2, 2024
1 parent 7f8a5c7 commit c82bc7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 6 additions & 3 deletions pkg/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI_FILE}" ]; then
fi
file_env PGADMIN_DEFAULT_PASSWORD

# TO enable custom path for config_distro, pass config distro path via environment variable.
export CONFIG_DISTRO_FILE_PATH="${CONFIG_DISTRO_FILE:-/pgadmin4/config_distro.py}"

# Populate config_distro.py. This has some default config, as well as anything
# provided by the user through the PGADMIN_CONFIG_* environment variables.
# Only update the file on first launch. The empty file is created during the
# container build so it can have the required ownership.
if [ "$(wc -m /pgadmin4/config_distro.py | awk '{ print $1 }')" = "0" ]; then
cat << EOF > /pgadmin4/config_distro.py
if [ "$(wc -m "${CONFIG_DISTRO_FILE_PATH}" | awk '{ print $1 }')" = "0" ]; then
cat << EOF > "${CONFIG_DISTRO_FILE_PATH}"
CA_FILE = '/etc/ssl/certs/ca-certificates.crt'
LOG_FILE = '/dev/null'
HELP_PATH = '../../docs'
Expand All @@ -61,7 +64,7 @@ EOF
for var in $(env | grep "^PGADMIN_CONFIG_" | cut -d "=" -f 1); do
# shellcheck disable=SC2086
# shellcheck disable=SC2046
echo ${var#PGADMIN_CONFIG_} = $(eval "echo \$$var") >> /pgadmin4/config_distro.py
echo ${var#PGADMIN_CONFIG_} = $(eval "echo \$$var") >> "${CONFIG_DISTRO_FILE_PATH}"
done
fi

Expand Down
19 changes: 16 additions & 3 deletions web/pgadmin/evaluate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import os
import sys
import keyring
import email_validator
import importlib.util

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


# Function to Extract settings from config_local, config_distro etc.
def get_variables_from_module(module_name):
module = globals().get(module_name, None)
Expand All @@ -27,6 +26,17 @@ def get_variables_from_module(module_name):
return variables


# Function to load config_distro at custom path
def import_module_from_path(module_name, file_path):
# Create a module spec
spec = importlib.util.spec_from_file_location(module_name, file_path)
# Create the module based on the spec
module = importlib.util.module_from_spec(spec)
# Execute the module (this loads it)
spec.loader.exec_module(module)
return module


def validate_config_variable(key, value):
boolean_keys = ['SERVER_MODE', 'ENHANCED_COOKIE_PROTECTION',
'SUPPORT_SSH_TUNNEL', 'ALLOW_SAVE_TUNNEL_PASSWORD',
Expand All @@ -47,7 +57,10 @@ def validate_config_variable(key, value):

# Load distribution-specific config overrides
try:
import config_distro
if 'CONFIG_DISTRO_FILE_PATH' in os.environ:
config_distro_path = os.environ['CONFIG_DISTRO_FILE_PATH']
config_distro = import_module_from_path('config_distro',
config_distro_path)
config_distro_settings = get_variables_from_module('config_distro')
custom_config_settings.update(config_distro_settings)
except ImportError:
Expand Down

0 comments on commit c82bc7a

Please sign in to comment.