Skip to content

Commit f42c45c

Browse files
committed
Updates dependencies and configures Docker
Updates Ubuntu, Django, and PostGIS versions to leverage the latest features and security patches. Configures the Docker environment to align with the updated dependencies. Includes installing necessary GDAL libraries in the Dockerfile. The application is now served using `python manage.py runserver` instead of gunicorn, and nginx handles static files and proxying.
1 parent a08856b commit f42c45c

File tree

8 files changed

+56
-39
lines changed

8 files changed

+56
-39
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
services:
2222
db:
23-
image: postgis/postgis:14-3.3
23+
image: postgis/postgis:17-3.5
2424
env:
2525
POSTGRES_USER: optimap
2626
POSTGRES_PASSWORD: optimap
@@ -76,7 +76,7 @@ jobs:
7676

7777
services:
7878
db:
79-
image: postgis/postgis:14-3.3
79+
image: postgis/postgis:17-3.5
8080
env:
8181
POSTGRES_USER: optimap
8282
POSTGRES_PASSWORD: optimap

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG UBUNTU_VERSION=20.04
1+
ARG UBUNTU_VERSION=22.04
22

33
FROM ubuntu:${UBUNTU_VERSION}
44

@@ -15,12 +15,13 @@ ENV DEBIAN_FRONTEND="noninteractive" TZ="Europe/Berlin"
1515
# install Python
1616
RUN apt-get update && \
1717
apt-get install -y -qq python-is-python3 && \
18-
apt-get install -y -qq python3-pip
18+
apt-get install -y -qq python3-pip tzdata
1919

2020
# install GDAL from UbuntuGIS
2121
RUN apt-get update && \
2222
apt-get install -y -qq software-properties-common && \
2323
add-apt-repository ppa:ubuntugis/ppa && \
24+
apt-get install -y -qq gdal-bin libgdal-dev
2425

2526
RUN pip install gdal=="$(gdal-config --version).*"
2627

@@ -32,7 +33,7 @@ COPY requirements.txt /tmp/requirements.txt
3233

3334
RUN set -ex && \
3435
pip install --upgrade pip && \
35-
pip install -r /tmp/requirements.txt && \
36+
pip install --no-cache-dir -r /tmp/requirements.txt && \
3637
rm -rf /root/.cache/
3738

3839
COPY . /code/
@@ -41,5 +42,5 @@ RUN python manage.py collectstatic --noinput
4142

4243
EXPOSE 8000
4344

44-
# replace demo.wsgi with <project_name>.wsgi
45-
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "optimap.wsgi"]
45+
#CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "optimap.wsgi"]
46+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000" ]

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,22 @@ After starting the containers, apply database migrations:
4141

4242
```bash
4343
# run migrations, in the directory where docker-compose is to resolve the name "web"
44-
docker-compose run web python manage.py makemigrations
45-
docker-compose run web python manage.py migrate
44+
docker-compose run app python manage.py makemigrations # should not detect and changes, otherwise your local config might be outdated
45+
docker-compose run app python manage.py migrate
4646
```
4747

48-
Now open a browser at <http://localhost:8001/>.
48+
Now open a browser at <http://localhost:80/>.
4949

5050
#### Services Overview
5151

5252
- db: Runs a PostgreSQL database with PostGIS extensions. Data is persisted in a Docker volume named db_data.
53-
- app: Python-based app serving HTTP requests.
54-
- web: Our primary Django web application.
53+
- app: Our primary Django web application.
5554
- webserver: An Nginx server for serving static files and test files.
5655

5756
#### Ports
5857

5958
- 5434: Database (PostgreSQL/PostGIS)
60-
- 8002: App (Python HTTP server)
61-
- 8001: Web application (Django server)
59+
- 8000: App (Django server)
6260
- 8080: Webserver (Nginx)
6361

6462
## Development

docker-compose.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
version: "3.9"
2-
31
services:
42
db:
5-
image: postgis/postgis:15-3.4
6-
container_name: project_db
3+
image: postgis/postgis:17-3.5
74
environment:
85
POSTGRES_DB: optimap
96
POSTGRES_USER: optimap
@@ -13,33 +10,30 @@ services:
1310
volumes:
1411
- db_data:/var/lib/postgresql/data
1512

16-
web:
13+
app:
1714
build:
1815
context: .
1916
dockerfile: Dockerfile
20-
container_name: project_web
2117
environment:
2218
DATABASE_URL: postgis://optimap:optimap@db:5432/optimap?sslmode=disable
2319
OPTIMAP_CACHE: "dummy"
2420
OPTIMAP_DEBUG: "True"
2521
volumes:
26-
- .:/code
27-
- ./fixtures:/fixtures # Mount fixture/test data
22+
- ".:/code:ro"
23+
- "./fixtures:/fixtures:ro"
2824
ports:
29-
- "8001:8000"
25+
- "8000:8000"
3026
depends_on:
3127
- db
32-
command: python manage.py runserver 0.0.0.0:8000
3328

3429
webserver:
35-
image: nginx:1.24-alpine
36-
container_name: project_webserver
30+
image: nginx:1.27-alpine
3731
volumes:
38-
- ./test_files:/usr/share/nginx/html:ro
32+
- "./etc/nginx.conf:/etc/nginx/nginx.conf:ro"
3933
ports:
40-
- "8080:80"
34+
- "80:80"
4135
depends_on:
42-
- web
36+
- app
4337

4438
volumes:
4539
db_data:

etc/nginx.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
worker_processes 1;
3+
4+
events {
5+
worker_connections 1024;
6+
}
7+
8+
http {
9+
include /etc/nginx/mime.types;
10+
default_type application/octet-stream;
11+
sendfile on;
12+
keepalive_timeout 65;
13+
gzip on;
14+
15+
upstream optimap {
16+
server app:8000;
17+
}
18+
19+
server {
20+
listen 80;
21+
server_name localhost;
22+
23+
location / {
24+
proxy_pass http://optimap;
25+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
26+
proxy_set_header Host $host;
27+
proxy_redirect off;
28+
}
29+
}
30+
31+
}

optimap/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ OPTIMAP_DEBUG=False
33
OPTIMAP_CACHE=default
44
OPTIMAP_CACHE_SECONDS=3600
55

6+
CSRF_COOKIE_SECURE=False
7+
68
OPTIMAP_BASE_URL=...
79

810
OPTIMAP_DB_HOST=localhost

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ blessed==1.20.0
55
beautifulsoup4==4.12.3
66
certifi==2024.12.14
77
charset-normalizer==3.4.1
8-
Django==5.1.7
8+
Django==5.1.9
99
django-environ==0.11.2
1010
django-filter==24.3
1111
django-leaflet==0.31.0

test_files/index.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)