File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ ENV POSTGRES_PASSWORD postgres
1111ENV POSTGRES_USER postgres
1212ENV JDBC_DATABASE_PORT 5060
1313ENV POSTGRES_DB db
14+ ENV READ_ONLY false
1415
1516# install dependencies (git)
1617RUN apt-get update \
@@ -22,8 +23,12 @@ RUN apt-get update \
2223EXPOSE 5060
2324
2425COPY clone-data-repo.sh clone-data-repo.sh
26+ COPY create-read-only-user.sh create-read-only-user.sh
27+
2528
2629# if ssh key is set, clone data repo with the sql scripts for initalization and start postgres afterwards
2730CMD chmod 700 clone-data-repo.sh \
2831 && ./clone-data-repo.sh \
32+ && chmod 700 create-read-only-user.sh \
33+ && ./create-read-only-user.sh \
2934 && su postgres -c "/usr/local/bin/docker-entrypoint.sh postgres -p ${JDBC_DATABASE_PORT}"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ if [ " $READ_ONLY " = true ] ; then
3+
4+ echo " Create SQL script for read-only-user"
5+
6+ user_name=" $POSTGRES_USER "
7+ user_name+=" _read"
8+ cat > ./99-read-only-user.sql << EOL
9+ CREATE ROLE readaccess;
10+ GRANT CONNECT ON DATABASE $POSTGRES_DB TO readaccess;
11+ GRANT USAGE ON SCHEMA public TO readaccess;
12+ GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
13+ CREATE USER $user_name WITH PASSWORD '$POSTGRES_PASSWORD ';
14+ GRANT readaccess TO $user_name ;
15+ EOL
16+
17+ mv ./99-read-only-user.sql /docker-entrypoint-initdb.d/
18+
19+ fi
You can’t perform that action at this time.
0 commit comments