Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MIQ PG config overrides to be included #2

Merged
merged 3 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM centos/postgresql-95-centos7

MAINTAINER ManageIQ https://github.com/ManageIQ/manageiq-appliance-build

# Include config PG dir
ARG PG_CONF_DIR=/var/lib/pgsql/conf.d

# Switch USER to root to add required repo and packages
USER root

Expand All @@ -22,7 +25,8 @@ LABEL io.openshift.tags="database,postgresql,postgresql95,rh-postgresql95,pglogi
COPY docker-assets/run-postgresql /usr/bin

# Loosen permission bits to avoid problems running container with arbitrary UID
RUN /usr/libexec/fix-permissions /var/lib/pgsql && \
RUN mkdir ${PG_CONF_DIR} && \
/usr/libexec/fix-permissions /var/lib/pgsql && \
/usr/libexec/fix-permissions /var/run/postgresql

# Switch USER back to postgres
Expand Down
20 changes: 20 additions & 0 deletions docker-assets/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ function set_miq_role() {
psql --command "ALTER ROLE \"${POSTGRESQL_USER}\" SUPERUSER LOGIN PASSWORD '${POSTGRESQL_PASSWORD}';"
}

# Include MIQ config overrides if directory present
function include_miq_config() {
# Set and create default dir if POSTGRESQL_CONFIG_DIR is not defined, compatible with older builds
POSTGRESQL_CONFIG_DIR=${POSTGRESQL_CONFIG_DIR:-/var/lib/pgsql/conf.d}

# Check for POSTGRESQL_CONFIG_DIR presence in postgresql.conf, if already there skip.
if [[ $(grep ${POSTGRESQL_CONFIG_DIR} ${PGDATA}/postgresql.conf) && $? -eq 0 ]]; then
echo "${POSTGRESQL_CONFIG_DIR} already exists on ${PGDATA}/postgresql.conf, skipping.."
else
echo "Writing ${POSTGRESQL_CONFIG_DIR} config directory to ${PGDATA}/postgresql.conf"
cat >> "$PGDATA/postgresql.conf" <<EOF
# Begin ManageIQ configuration overrides:
include_dir '${POSTGRESQL_CONFIG_DIR}'
EOF
fi
}

set_pgdata
check_env_vars
generate_passwd_file
Expand All @@ -22,6 +39,9 @@ if [ ! -f "$PGDATA/postgresql.conf" ]; then
NEED_TO_CREATE_USERS=yes
fi

# Include MIQ overrides before first-startup
include_miq_config

pg_ctl -w start -o "-h ''"
if [ "${NEED_TO_CREATE_USERS:-}" == "yes" ]; then
create_users
Expand Down