Skip to content

Commit 395863e

Browse files
authored
Merge pull request #416 from continuouspipe/feature/spryker-database-connection-and-non-privileged
Allow Spryker database scripts to run with a non-privileged PgSQL user
2 parents b2d0c76 + 6a5e94c commit 395863e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

php/shared/usr/local/share/assets/assets_functions.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ function assets_apply_database_postgres()
155155
DATABASE_ARGS+=("--username=${DATABASE_USER}")
156156
fi
157157

158+
if [ -n "${DATABASE_NAME}" ]; then
159+
DATABASE_ARGS+=("${DATABASE_NAME}")
160+
fi
161+
158162
wait_for_remote_ports "${ASSETS_DATABASE_WAIT_TIMEOUT}" "${DATABASE_HOST}:${DATABASE_PORT}"
159163

160164
local DATABASES

spryker/usr/local/share/spryker/spryker_functions.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ do_spryker_app_permissions() {
4949

5050
do_spryker_config_create() (
5151
set +x
52-
echo "Creating Postgres Credentials file in /root/.pgpass"
52+
local target=~/.pgpass
53+
54+
echo "Creating Postgres Credentials file in "$target
5355
# create .pgpass in home directory for postgres client
54-
echo "$DATABASE_HOST:*:*:$DATABASE_USER:$DATABASE_PASSWORD" > /root/.pgpass
55-
chmod 0600 /root/.pgpass
56+
echo "$DATABASE_HOST:*:*:$DATABASE_USER:$DATABASE_PASSWORD" > $target
57+
chmod 0600 $target
5658
)
5759

5860
do_spryker_build() {
@@ -98,7 +100,7 @@ do_spryker_generate_files() {
98100
do_spryker_install() {
99101
# check if database exists (it is supposed to be created by postgres container)
100102
set +e
101-
psql -U "$DATABASE_USER" -h "$DATABASE_HOST" -lqt | cut -d \| -f 1 | grep -q "$DATABASE_NAME"
103+
psql -U "$DATABASE_USER" -h "$DATABASE_HOST" -lqt "$DATABASE_NAME" | cut -d \| -f 1 | grep -q "$DATABASE_NAME"
102104
DATABASE_EXISTS=$?
103105
set -e
104106

@@ -110,7 +112,7 @@ do_spryker_install() {
110112
# database exists
111113
# check if spryker is installed
112114
set +e
113-
psql -U "$DATABASE_USER" -h "$DATABASE_HOST" -c "SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_catalog = '$DATABASE_NAME' AND table_name = 'spy_locale');" | grep -q f
115+
psql -U "$DATABASE_USER" -h "$DATABASE_HOST" -c "SELECT EXISTS (SELECT * FROM information_schema.tables WHERE table_catalog = '$DATABASE_NAME' AND table_name = 'spy_locale');" "$DATABASE_NAME" | grep -q f
114116
SPRYKER_INSTALLED=$?
115117
set -e
116118

0 commit comments

Comments
 (0)