-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
464e663
commit f2411bd
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ARG BASE_VERSION=8.5 | ||
FROM dpage/pgadmin4:${BASE_VERSION} | ||
|
||
ENV PGADMIN_DEFAULT_EMAIL="[email protected]" | ||
ENV PGADMIN_DEFAULT_PASSWORD="admin" | ||
ENV PGADMIN_CONFIG_SERVER_MODE="False" | ||
ENV PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED="False" | ||
|
||
ENV POSTGRES_HOST="postgres" | ||
ENV POSTGRES_PORT="5432" | ||
ENV POSTGRES_DB="*" | ||
|
||
USER root | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh && \ | ||
touch /pgadmin4/servers.json && \ | ||
chown pgadmin:root /pgadmin4/servers.json | ||
USER pgadmin | ||
|
||
ENTRYPOINT /entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
## Create /var/lib/pgadmin/pgpass | ||
# 1st database | ||
echo "$POSTGRES_HOST:$POSTGRES_PORT:postgres:$POSTGRES_USER:$POSTGRES_PASSWORD" | tee -a "/var/lib/pgadmin/pgpass" >/dev/null | ||
echo "$POSTGRES_HOST:$POSTGRES_PORT:$POSTGRES_DB:$POSTGRES_USER:$POSTGRES_PASSWORD" | tee -a "/var/lib/pgadmin/pgpass" >/dev/null | ||
POSTGRES_HOST_1=$POSTGRES_HOST | ||
POSTGRES_PORT_1=$POSTGRES_PORT | ||
POSTGRES_DB_1=$POSTGRES_DB | ||
POSTGRES_USER_1=$POSTGRES_USER | ||
POSTGRES_PASSWORD_1=$POSTGRES_PASSWORD | ||
|
||
## Create servers.json | ||
tee /pgadmin4/servers.json >/dev/null <<EOF | ||
{ | ||
"Servers": { | ||
"1": { | ||
"Name": "$POSTGRES_HOST_1", | ||
"Group": "Servers", | ||
"Host": "$POSTGRES_HOST_1", | ||
"Port": $POSTGRES_PORT_1, | ||
"MaintenanceDB": "postgres", | ||
"Username": "$POSTGRES_USER_1", | ||
"SSLMode": "prefer", | ||
"PassFile": "/var/lib/pgadmin/pgpass" | ||
} | ||
EOF | ||
|
||
# if there are more than 1 database then | ||
# loop through environment variables and create password files | ||
COUNT=2 | ||
while [ ! -z "$(eval echo \"\$POSTGRES_HOST_$COUNT\")" ]; do | ||
POSTGRES_HOST="$(eval echo \"\$POSTGRES_HOST_$COUNT\")" | ||
POSTGRES_PORT="$(eval echo \"\$POSTGRES_PORT_$COUNT\")" | ||
|
||
# Set default for the postgres port | ||
if [ -z "$POSTGRES_PORT" ]; then | ||
POSTGRES_PORT="5432" | ||
fi | ||
|
||
# if POSTGRES_DB, default is "*" | ||
POSTGRES_DB="$(eval echo \"\$POSTGRES_DB_$COUNT\")" | ||
if [ -z "$POSTGRES_DB" ]; then | ||
POSTGRES_DB="*" | ||
fi | ||
POSTGRES_USER="$(eval echo \"\$POSTGRES_USER_$COUNT\")" | ||
POSTGRES_PASSWORD="$(eval echo \"\$POSTGRES_PASSWORD_$COUNT\")" | ||
echo "$POSTGRES_HOST:$POSTGRES_PORT:postgres:$POSTGRES_USER:$POSTGRES_PASSWORD" | tee -a "/var/lib/pgadmin/pgpass_$COUNT" >/dev/null | ||
echo "$POSTGRES_HOST:$POSTGRES_PORT:$POSTGRES_DB:$POSTGRES_USER:$POSTGRES_PASSWORD" | tee -a "/var/lib/pgadmin/pgpass_$COUNT" >/dev/null | ||
|
||
tee -a /pgadmin4/servers.json >/dev/null <<EOF | ||
,"$COUNT": { | ||
"Name": "$POSTGRES_HOST", | ||
"Group": "Servers", | ||
"Host": "$POSTGRES_HOST", | ||
"Port": $POSTGRES_PORT, | ||
"MaintenanceDB": "postgres", | ||
"Username": "$POSTGRES_USER", | ||
"SSLMode": "prefer", | ||
"PassFile": "/var/lib/pgadmin/pgpass_$COUNT" | ||
} | ||
EOF | ||
|
||
COUNT=$((COUNT + 1)) | ||
done | ||
|
||
# close servers.json | ||
tee -a /pgadmin4/servers.json >/dev/null <<EOF | ||
} | ||
} | ||
EOF | ||
|
||
chmod 600 $(ls /var/lib/pgadmin/pgpass*) | ||
chown pgadmin:root $(ls /var/lib/pgadmin/pgpass*) | ||
chown pgadmin:root /pgadmin4/servers.json | ||
|
||
exec /entrypoint.sh "$@" |