Skip to content

Commit

Permalink
Merge pull request #2 from fbladilo/allow_miq_config_overrides
Browse files Browse the repository at this point in the history
Allow MIQ PG config overrides to be included
  • Loading branch information
carbonin authored Jul 25, 2017
2 parents 2c50ac5 + 150f6a4 commit 0d179f3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit 0d179f3

Please sign in to comment.