forked from joist-orm/joist-graphql-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.dockerfile
35 lines (30 loc) · 1.5 KB
/
db.dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
FROM postgres:14.0
ARG APP_DBNAME=sample_app
ARG APP_USERNAME=sample_user
ARG APP_PASSWORD=local
ENV POSTGRES_PASSWORD=admin
# Create the init.sh file. This file is only ran once; if you need to re-run it, use `docker-compose rm db`.
RUN echo "#!/bin/bash" > /init.sh && \
echo "set -e" >> /init.sh && \
echo "psql -v ON_ERROR_STOP=1 --username "\$POSTGRES_USER" --dbname "\$POSTGRES_DB" <<-EOSQL" >> /init.sh && \
echo " CREATE USER \"${APP_USERNAME}\" PASSWORD '${APP_PASSWORD}';" >> /init.sh && \
echo " CREATE DATABASE \"${APP_DBNAME}\";" >> /init.sh && \
echo " GRANT ALL PRIVILEGES ON DATABASE \"${APP_DBNAME}\" TO \"${APP_USERNAME}\";" >> /init.sh && \
echo "EOSQL" >> /init.sh && \
chmod u+x /init.sh && \
mv /init.sh /docker-entrypoint-initdb.d/
# Create the reset.sh file
RUN echo "#!/bin/bash" > /reset.sh && \
echo "set -e" >> /reset.sh && \
echo "psql -v ON_ERROR_STOP=1 --username postgres --dbname postgres <<-EOSQL" >> /reset.sh && \
echo " DROP DATABASE \"${APP_DBNAME}\";" >> /reset.sh && \
echo " CREATE DATABASE \"${APP_DBNAME}\";" >> /reset.sh && \
echo " GRANT ALL PRIVILEGES ON DATABASE \"${APP_DBNAME}\" TO \"${APP_USERNAME}\";" >> /reset.sh && \
echo "EOSQL" >> /reset.sh && \
chmod u+x /reset.sh
# Create the console.sh file
RUN echo "#!/bin/bash" > /console.sh && \
echo "set -e" >> /console.sh && \
echo "psql -v ON_ERROR_STOP=1 --username \"${APP_USERNAME}\" --dbname \"${APP_DBNAME}\"" >> /console.sh && \
chmod u+x /console.sh
CMD ["postgres", "-c", "fsync=off"]