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 arbitrary --user values (mostly) #253

Merged
merged 1 commit into from
Jan 19, 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
2 changes: 1 addition & 1 deletion 9.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgres

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
VOLUME /var/lib/postgresql/data

COPY docker-entrypoint.sh /
Expand Down
2 changes: 1 addition & 1 deletion 9.2/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgres

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
VOLUME /var/lib/postgresql/data

COPY docker-entrypoint.sh /
Expand Down
22 changes: 15 additions & 7 deletions 9.2/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi

if [ "$1" = 'postgres' ]; then
# allow the container to be started with `--user`
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
chmod 700 "$PGDATA"
Expand All @@ -36,11 +37,18 @@ if [ "$1" = 'postgres' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec su-exec postgres "$BASH_SOURCE" "$@"
fi

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :

file_env 'POSTGRES_INITDB_ARGS'
eval "su-exec postgres initdb $POSTGRES_INITDB_ARGS"
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"

# check password first so we can output the warning before postgres
# messes it up
Expand Down Expand Up @@ -68,11 +76,12 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all all $authMethod"; } | su-exec postgres tee -a "$PGDATA/pg_hba.conf" > /dev/null
{ echo; echo "host all all all $authMethod"; } | tee -a "$PGDATA/pg_hba.conf" > /dev/null

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
su-exec postgres pg_ctl -D "$PGDATA" \
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-w start

Expand Down Expand Up @@ -111,14 +120,13 @@ if [ "$1" = 'postgres' ]; then
echo
done

su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop

echo
echo 'PostgreSQL init process complete; ready for start up.'
echo
fi

exec su-exec postgres "$@"
fi

exec "$@"
22 changes: 15 additions & 7 deletions 9.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi

if [ "$1" = 'postgres' ]; then
# allow the container to be started with `--user`
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
chmod 700 "$PGDATA"
Expand All @@ -36,11 +37,18 @@ if [ "$1" = 'postgres' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec gosu postgres "$BASH_SOURCE" "$@"
fi

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :

file_env 'POSTGRES_INITDB_ARGS'
eval "gosu postgres initdb $POSTGRES_INITDB_ARGS"
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"

# check password first so we can output the warning before postgres
# messes it up
Expand Down Expand Up @@ -68,11 +76,12 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all all $authMethod"; } | gosu postgres tee -a "$PGDATA/pg_hba.conf" > /dev/null
{ echo; echo "host all all all $authMethod"; } | tee -a "$PGDATA/pg_hba.conf" > /dev/null

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-w start

Expand Down Expand Up @@ -111,14 +120,13 @@ if [ "$1" = 'postgres' ]; then
echo
done

gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop

echo
echo 'PostgreSQL init process complete; ready for start up.'
echo
fi

exec gosu postgres "$@"
fi

exec "$@"
2 changes: 1 addition & 1 deletion 9.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgres

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
VOLUME /var/lib/postgresql/data

COPY docker-entrypoint.sh /
Expand Down
2 changes: 1 addition & 1 deletion 9.3/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgres

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
VOLUME /var/lib/postgresql/data

COPY docker-entrypoint.sh /
Expand Down
22 changes: 15 additions & 7 deletions 9.3/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi

if [ "$1" = 'postgres' ]; then
# allow the container to be started with `--user`
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
chmod 700 "$PGDATA"
Expand All @@ -36,11 +37,18 @@ if [ "$1" = 'postgres' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec su-exec postgres "$BASH_SOURCE" "$@"
fi

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :

file_env 'POSTGRES_INITDB_ARGS'
eval "su-exec postgres initdb $POSTGRES_INITDB_ARGS"
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"

# check password first so we can output the warning before postgres
# messes it up
Expand Down Expand Up @@ -68,11 +76,12 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all all $authMethod"; } | su-exec postgres tee -a "$PGDATA/pg_hba.conf" > /dev/null
{ echo; echo "host all all all $authMethod"; } | tee -a "$PGDATA/pg_hba.conf" > /dev/null

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
su-exec postgres pg_ctl -D "$PGDATA" \
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-w start

Expand Down Expand Up @@ -111,14 +120,13 @@ if [ "$1" = 'postgres' ]; then
echo
done

su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop

echo
echo 'PostgreSQL init process complete; ready for start up.'
echo
fi

exec su-exec postgres "$@"
fi

exec "$@"
22 changes: 15 additions & 7 deletions 9.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi

if [ "$1" = 'postgres' ]; then
# allow the container to be started with `--user`
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
chmod 700 "$PGDATA"
Expand All @@ -36,11 +37,18 @@ if [ "$1" = 'postgres' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec gosu postgres "$BASH_SOURCE" "$@"
fi

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :

file_env 'POSTGRES_INITDB_ARGS'
eval "gosu postgres initdb $POSTGRES_INITDB_ARGS"
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"

# check password first so we can output the warning before postgres
# messes it up
Expand Down Expand Up @@ -68,11 +76,12 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all all $authMethod"; } | gosu postgres tee -a "$PGDATA/pg_hba.conf" > /dev/null
{ echo; echo "host all all all $authMethod"; } | tee -a "$PGDATA/pg_hba.conf" > /dev/null

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
gosu postgres pg_ctl -D "$PGDATA" \
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-w start

Expand Down Expand Up @@ -111,14 +120,13 @@ if [ "$1" = 'postgres' ]; then
echo
done

gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop

echo
echo 'PostgreSQL init process complete; ready for start up.'
echo
fi

exec gosu postgres "$@"
fi

exec "$@"
2 changes: 1 addition & 1 deletion 9.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgres

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
VOLUME /var/lib/postgresql/data

COPY docker-entrypoint.sh /
Expand Down
2 changes: 1 addition & 1 deletion 9.4/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgres

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
VOLUME /var/lib/postgresql/data

COPY docker-entrypoint.sh /
Expand Down
22 changes: 15 additions & 7 deletions 9.4/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi

if [ "$1" = 'postgres' ]; then
# allow the container to be started with `--user`
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
chmod 700 "$PGDATA"
Expand All @@ -36,11 +37,18 @@ if [ "$1" = 'postgres' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec su-exec postgres "$BASH_SOURCE" "$@"
fi

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :

file_env 'POSTGRES_INITDB_ARGS'
eval "su-exec postgres initdb $POSTGRES_INITDB_ARGS"
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"

# check password first so we can output the warning before postgres
# messes it up
Expand Down Expand Up @@ -68,11 +76,12 @@ if [ "$1" = 'postgres' ]; then
authMethod=trust
fi

{ echo; echo "host all all all $authMethod"; } | su-exec postgres tee -a "$PGDATA/pg_hba.conf" > /dev/null
{ echo; echo "host all all all $authMethod"; } | tee -a "$PGDATA/pg_hba.conf" > /dev/null

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
su-exec postgres pg_ctl -D "$PGDATA" \
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-w start

Expand Down Expand Up @@ -111,14 +120,13 @@ if [ "$1" = 'postgres' ]; then
echo
done

su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop

echo
echo 'PostgreSQL init process complete; ready for start up.'
echo
fi

exec su-exec postgres "$@"
fi

exec "$@"
Loading