Skip to content

Commit

Permalink
feat: add read only pguser in build and volume plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonlucas committed Feb 4, 2025
1 parent 9b1140f commit 6e31626
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env_idegeo_local
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ GEONODE_DATABASE_PASSWORD=geonode
GEONODE_GEODATABASE=geonode_data
GEONODE_GEODATABASE_USER=geonode_data
GEONODE_GEODATABASE_PASSWORD=geonode_data
PG_READ_ONLY_USERNAME=read_geonode
PG_READ_ONLY_PASSWORD=read_geonode
GEONODE_DATABASE_SCHEMA=public
GEONODE_GEODATABASE_SCHEMA=public
DATABASE_HOST=db
Expand Down
2 changes: 2 additions & 0 deletions .env_idegeo_prod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ GEONODE_DATABASE_PASSWORD=geonode
GEONODE_GEODATABASE=geonode_data
GEONODE_GEODATABASE_USER=geonode_data
GEONODE_GEODATABASE_PASSWORD=geonode_data
PG_READ_ONLY_USERNAME=read_geonode
PG_READ_ONLY_PASSWORD=read_geonode
GEONODE_DATABASE_SCHEMA=public
GEONODE_GEODATABASE_SCHEMA=public
DATABASE_HOST=db
Expand Down
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ services:
volumes:
- statics:/mnt/volumes/statics
- geoserver-data-dir:/geoserver_data/data
- geoserver-plugins:/usr/local/tomcat/webapps/geoserver/WEB-INF/lib
- backup-restore:/backup_restore
- data:/data
- tmp:/tmp
Expand All @@ -130,7 +131,13 @@ services:
# PostGIS database.
db:
# use geonode official postgis 15 image
image: geonode/postgis:15.3-latest
image: ${COMPOSE_PROJECT_NAME}/postgis:15.3-latest
build:
context: ./docker/postgresql
dockerfile: Dockerfile
args:
- PG_READ_ONLY_USERNAME=${PG_READ_ONLY_USERNAME}
- PG_READ_ONLY_PASSWORD=${PG_READ_ONLY_PASSWORD}
command: postgres -c "max_connections=${POSTGRESQL_MAX_CONNECTIONS}"
container_name: db4${COMPOSE_PROJECT_NAME}
env_file:
Expand All @@ -154,6 +161,8 @@ services:
restart: unless-stopped

volumes:
geoserver-plugins:
name: ${COMPOSE_PROJECT_NAME}-gsplugins
statics:
name: ${COMPOSE_PROJECT_NAME}-statics
nginx-confd:
Expand Down
14 changes: 14 additions & 0 deletions docker/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG PG_READ_ONLY_USERNAME
ARG PG_READ_ONLY_PASSWORD
FROM geonode/postgis:15.3-latest


RUN /bin/sh -c "DO \$\$ \
BEGIN \
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '${PG_READ_ONLY_USERNAME}') THEN \
CREATE ROLE ${PG_READ_ONLY_USERNAME} WITH LOGIN PASSWORD '${PG_READ_ONLY_PASSWORD}'; \
END IF; \
END \
\$\$;" | psql -U postgres

RUN psql -U postgres -c "GRANT pg_read_all_data TO ${PG_READ_ONLY_USERNAME};"

0 comments on commit 6e31626

Please sign in to comment.