Skip to content

Commit

Permalink
working postgres pod that self-inits with userdb schema on first run
Browse files Browse the repository at this point in the history
  • Loading branch information
lrvick committed Nov 29, 2020
1 parent 1cc2978 commit 3906212
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 2 additions & 4 deletions images/postgres/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ RUN mkdir -p \
&& cp /lib64/ld-linux-x86-64.so.2 ~/rootfs/lib64 \
&& cp /bin/sh ~/rootfs/bin \
&& cp -a ~/out/. ~/rootfs/ \
&& chmod -R 700 ~/rootfs/data/ \
&& echo "listen_addresses='*'" > ~/rootfs/config/postgresql.conf \
&& echo "data_directory='/data'" >> ~/rootfs/config/postgresql.conf
&& chmod -R 700 ~/rootfs/data/

FROM scratch
COPY --from=build --chown=100:100 /home/build/rootfs /
STOPSIGNAL SIGQUIT
EXPOSE 5432
USER 100:100
ENV PGDATA=/config
ENV PGDATA=/data
ENV PATH=/bin
ENTRYPOINT ["/bin/postgres"]
20 changes: 9 additions & 11 deletions pods/userdb/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,24 @@ spec:
command: ["/bin/sh", "-c"]
args:
- set -e;
[ -z "$(ls -A /data )" ] || exit 0;
[ -f "/data/PG_VERSION" ] && exit 0;
initdb /data;
postgres &
until pg_isready >/dev/null 2>&1; do true; done;
echo 'create database userdb;' > /tmp/createdb.sql;
postgres --single -Ej "postgres" < /tmp/createdb.sql;
postgres --single -Ej "userdb" < /schema/bundle.sql;
securityContext:
runAsUser: 100
runAsGroup: 100
psql -d "postgres" < /tmp/createdb.sql;
psql -d "userdb" < /schema/bundle.sql;
containers:
- name: postgres
image: registry.localhost:5000/postgres
ports:
- name: tcp
containerPort: 5432
volumeMounts:
- mountPath: /data
name: userdb-data
volumeMounts:
- mountPath: /schema
name: userdb-schema
- name: userdb-data
mountPath: /data
- name: userdb-schema
mountPath: /schema
env:
- name: PGPASSWORD
valueFrom:
Expand Down

0 comments on commit 3906212

Please sign in to comment.