Skip to content

Commit

Permalink
Use postgis/postgis image
Browse files Browse the repository at this point in the history
mdillion/postgis image was discontinued...

docker-entrypoint.sh --help can no longer be used to prepopulate data
docker-library/postgres#636

Use healthcheck to determine if postgres is ready
  • Loading branch information
nathanweeks committed Jul 9, 2020
1 parent 0df3efc commit fe44f63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# lis_gis
Map viewer for and search interface for USDA/GRIN germplasm accessions and traits. See http://legumeinfo.org/germplasm/map for a live demo.
server requirements
* Python 2.7.x
* Python >= 3.5.x
* Django
* PostgreSQL and PostGIS

Expand All @@ -22,16 +22,9 @@ pg_dump --no-owner --no-privileges --schema=<SCHEMA_NAME> --compress=9 > z-SCHEM
```

(The file name can be any name matching the pattern `*.sql.gz`, as long as it lexicographically sorts after the script `postgis.sh`, which must be executed first in /docker-entrypoint-initdb.d/)
Move the .sql.gz file to ./postgres/docker-entrypoint-initdb.d/ before executing `docker-compose up --build`.
The name of the file does not matter, as long as the extension is `*.sql.gz`, `*.sql.xz`, or `*.sql`, and as long as it lexicographically sorts after the `/docker-entrypoint-initdb.d/10_postgis.sh` script from the container image, which must be executed first.

Then modify docker-compose.yml, replacing the name of the file that is bind mounted inside the "db" service container:

```
db:
...
volumes:
- ./docker-entrypoint-initdb.d/z-peanutbase.sql.gz:/docker-entrypoint-initdb.d/z-peanutbase.sql.gz
```

## PostgreSQL setup
Create a database and before loading the schema.sql, create the spatial extension (assuming PostGIS is already available in your PostgrSQL install). Creating the schema will fail unless PostGIS extension is created first.
Expand Down
13 changes: 9 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# development
version: '3.7'
version: '2.3'

services:
web:
Expand All @@ -15,11 +15,16 @@ services:
PGDATABASE: postgres
STATIC_URL: /static/
depends_on:
- db
db:
condition: service_healthy
ports:
- "8000:8000"
command: ["sh", "-c", "sleep 5 && python3 manage.py runserver 0.0.0.0:8000"]

db:
build:
context: postgres
build: postgres
environment:
POSTGRES_PASSWORD: postgres
healthcheck:
test: "pg_isready -U postgres -h 127.0.0.1 || exit 1"
retries: 10
9 changes: 1 addition & 8 deletions postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
# https://github.com/docker-library/postgres/issues/319

FROM mdillon/postgis:11-alpine AS load
FROM postgis/postgis:11-2.5-alpine
COPY ./docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
ENV PGDATA=/pgdata
RUN docker-entrypoint.sh --help

FROM mdillon/postgis:11-alpine
COPY --from=load /pgdata /var/lib/postgresql/data/

0 comments on commit fe44f63

Please sign in to comment.