Skip to content

Commit df31583

Browse files
authored
Merge pull request #3 from cisar2218/master
- MinIO added (replacement for local storage) - Default secret values placed at .env.example file.
2 parents b676c27 + 170c5f6 commit df31583

6 files changed

Lines changed: 122 additions & 20 deletions

File tree

.env.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# S3 Bucket
2+
AWS_ACCESS_KEY_ID=minioadmin
3+
AWS_SECRET_ACCESS_KEY=minioadmin
4+
AWS_STORAGE_BUCKET_NAME=dosportal-media
5+
AWS_S3_ENDPOINT_URL=http://minio:9000
6+
AWS_S3_REGION_NAME=us-east-1
7+
AWS_DEFAULT_ACL=public-read
8+
AWS_S3_CUSTOM_DOMAIN=
9+
AWS_S3_SIGNATURE_VERSION=s3v4
10+
MINIO_ROOT_USER=minioadmin
11+
MINIO_ROOT_PASSWORD=minioadmin
12+
13+
# Django
14+
SECRET_KEY='django-insecure-)&9q7=6szljptu&2a11rq1k-ofhz1s$nxk&t+f=3xk74(vq4jq'
15+
16+
17+
# Postgresql
18+
POSTGRES_DB=dosportal
19+
POSTGRES_USER=dosportal_user
20+
POSTGRES_PASSWORD=dosportal_password
21+
POSTGRES_HOST=10.5.0.5
22+
POSTGRES_PORT=5432

DOSPORTAL/settings.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
https://docs.djangoproject.com/en/4.2/ref/settings/
1111
"""
1212

13+
import os
1314
from pathlib import Path
1415

1516
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -59,6 +60,7 @@
5960
'markdownx',
6061
'guardian',
6162
'prettyjson',
63+
'storages',
6264
# 'organizations',
6365
]
6466

@@ -171,8 +173,21 @@
171173
STATIC_ROOT = BASE_DIR / 'static'
172174
STATIC_URL = 'static/'
173175

174-
MEDIA_ROOT = BASE_DIR / 'data/media'
175-
MEDIA_URL = 'media/'
176+
177+
# S3 Configuration
178+
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID', 'minioadmin')
179+
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY', 'minioadmin')
180+
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME', 'dosportal-media')
181+
AWS_S3_ENDPOINT_URL = os.getenv('AWS_S3_ENDPOINT_URL', 'http://minio:9000')
182+
AWS_S3_REGION_NAME = os.getenv('AWS_S3_REGION_NAME', 'us-east-1')
183+
AWS_S3_CUSTOM_DOMAIN = os.getenv('AWS_S3_CUSTOM_DOMAIN')
184+
AWS_DEFAULT_ACL = os.getenv('AWS_DEFAULT_ACL', 'public-read')
185+
AWS_S3_SIGNATURE_VERSION = os.getenv('AWS_S3_SIGNATURE_VERSION', 's3v4')
186+
187+
# Use S3 for media files
188+
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
189+
MEDIA_URL = f'{AWS_S3_ENDPOINT_URL}/{AWS_STORAGE_BUCKET_NAME}/'
190+
176191

177192
REST_FRAMEWORK = {
178193
# Use Django's standard `django.contrib.auth` permissions,

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENV PYTHONDONTWRITEBYTECODE=1
44
ENV PYTHONUNBUFFERED=1
55

66
RUN apt-get update
7-
RUN apt-get install -y python3 python3-pip libpq-dev binutils libproj-dev gdal-bin
7+
RUN apt-get install -y python3 python3-pip python3-setuptools libpq-dev binutils libproj-dev gdal-bin
88
#RUN apt-get install -y net-tools
99

1010
WORKDIR /DOSPORTAL

docker-compose.yml

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ networks:
22
inet:
33
driver: bridge
44
ipam:
5-
config:
6-
- subnet: 10.5.0.0/16
7-
gateway: 10.5.0.1
5+
config:
6+
- subnet: 10.5.0.0/16
7+
gateway: 10.5.0.1
88
default:
99
driver: bridge
1010
ipam:
@@ -25,38 +25,39 @@ services:
2525

2626
db_dosportal:
2727
image: postgis/postgis
28+
env_file:
29+
- .env
2830
volumes:
2931
- ./data/dosportal/db_pg:/var/lib/postgresql/data
3032
environment:
31-
- POSTGRES_DB=dosportal
32-
- POSTGRES_USER=dosportal_user
33-
- POSTGRES_PASSWORD=dosportal_password
33+
- POSTGRES_DB=${POSTGRES_DB:-dosportal}
34+
- POSTGRES_USER=${POSTGRES_USER:-dosportal_user}
35+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-dosportal_password}
3436
networks:
3537
inet:
3638
ipv4_address: 10.5.0.5
3739

38-
39-
40-
4140
web:
4241
build:
43-
context: .
44-
network: host
45-
# platform: linux/amd64
46-
# command: python manage.py runserver 0.0.0.0:8000
47-
# entrypoint: python3 manage.py runserver 0.0.0.0:8000
42+
context: .
43+
network: host
44+
# platform: linux/amd64
45+
# command: python manage.py runserver 0.0.0.0:8000
46+
# entrypoint: python3 manage.py runserver 0.0.0.0:8000
47+
env_file:
48+
- .env
4849
volumes:
4950
- .:/DOSPORTAL
5051
ports:
5152
- "8100:8000"
5253
depends_on:
5354
- db_dosportal
5455
- redis
56+
- minio
5557
networks:
5658
inet:
5759
ipv4_address: 10.5.0.6
58-
# default:
59-
60+
# default:
6061

6162
worker:
6263
build: .
@@ -74,9 +75,26 @@ services:
7475
redis:
7576
image: redis
7677
volumes:
77-
- .:/DOSPORTAL
78+
- .:/DOSPORTAL
7879
depends_on:
7980
- db_dosportal
8081
networks:
8182
inet:
8283
ipv4_address: 10.5.0.7
84+
85+
minio:
86+
image: minio/minio
87+
env_file:
88+
- .env
89+
ports:
90+
- "9000:9000"
91+
- "9001:9001"
92+
environment:
93+
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
94+
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
95+
command: server /data --console-address ":9001"
96+
volumes:
97+
- ./data/minio:/data
98+
networks:
99+
inet:
100+
ipv4_address: 10.5.0.9

readme.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,48 @@ DOSPORTAL is designed to be platform-independent, ensuring accessibility from va
7777

7878
For more information or to contribute to the project, please contact support@ust.cz
7979

80+
## Instructions for Contributors
81+
82+
**Prerequirements:** Docker and Docker Compose for local development.
83+
84+
### Secrets Configuration
85+
86+
Create environment file and setup credentials as needed.
87+
88+
```bash
89+
cp .env.example .env
90+
```
91+
92+
### Local Development (Docker Compose)
93+
94+
1. Build images
95+
96+
```bash
97+
sudo docker compose build web worker
98+
```
99+
100+
2. Start services
101+
102+
```bash
103+
sudo docker compose up -d
104+
```
105+
106+
3. Create the media bucket in MinIO
107+
108+
```bash
109+
sudo docker run --rm --net=host \
110+
-e MC_HOST_minio=http://minioadmin:minioadmin@localhost:9000 \
111+
minio/mc mb --ignore-existing minio/dosportal-media
112+
```
113+
114+
Or use the console at http://localhost:9001 (minioadmin/minioadmin).
115+
116+
4. Apply migrations
117+
118+
```bash
119+
sudo docker compose exec web python3 manage.py migrate
120+
```
121+
122+
5. Access services
123+
- DOSPORTAL: http://localhost:8100
124+
- MinIO console: http://localhost:9001

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ martor
1717
markdown
1818
django-filter
1919
django-q
20+
django-storages[s3]
21+
boto3
2022

2123
redis
2224

0 commit comments

Comments
 (0)