Skip to content

Commit f40f073

Browse files
axonasifsagor999
authored andcommitted
refactor(tool-postgresql): Dockerfile
1 parent 2e51ce8 commit f40f073

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

chunks/tool-postgresql/Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ RUN PGDATA="${PGDATA//\/workspace/$HOME}" \
1818
&& initdb -D $PGDATA \
1919
&& printf '#!/bin/bash\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" start\n' > ~/.pg_ctl/bin/pg_start \
2020
&& printf '#!/bin/bash\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" stop\n' > ~/.pg_ctl/bin/pg_stop \
21-
&& chmod +x ~/.pg_ctl/bin/* \
22-
&& printf '%s\n' '# Auto-start PostgreSQL server' \
23-
'(' \
24-
"mkdir \$PGWORKSPACE 2>/dev/null || exit 0; test -e ${PGDATA%/data} && mv ${PGDATA%/data} /workspace" \
25-
'[[ $(pg_ctl status | grep PID) ]] || pg_start > /dev/null' \
26-
') & disown' > ~/.bashrc.d/200-postgresql-launch
21+
&& chmod +x ~/.pg_ctl/bin/*
2722
ENV PATH="$HOME/.pg_ctl/bin:$PATH"
2823
ENV DATABASE_URL="postgresql://gitpod@localhost"
2924
ENV PGHOSTADDR="127.0.0.1"
3025
ENV PGDATABASE="postgres"
26+
COPY --chown=gitpod:gitpod postgresql-hook.bash $HOME/.bashrc.d/200-postgresql-launch
3127

3228
USER gitpod
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# Auto-start PostgreSQL server
3+
(
4+
if mkdir /tmp/.pgsql_lock 2>/dev/null; then {
5+
target="${PGWORKSPACE}"
6+
source="${target//\/workspace/$HOME}"
7+
8+
if test -e "$source"; then {
9+
10+
if test ! -e "$target"; then {
11+
mv "$source" "$target"
12+
}; fi
13+
14+
if ! [[ "$(pg_ctl status)" =~ PID ]]; then {
15+
pg_start >/dev/null
16+
trap "pg_stop" TERM EXIT
17+
exec {sfd}<> <(:)
18+
until read -r -t 3600 -u $sfd; do continue; done
19+
}; fi
20+
21+
}; fi
22+
}; fi
23+
) &
24+
disown

0 commit comments

Comments
 (0)