Skip to content

Commit bdb2733

Browse files
author
Obada Haddad
committed
remove database access when not needed, put some volumes in read only in docker-compose.yml, make minio console work
1 parent 46cb7f7 commit bdb2733

7 files changed

Lines changed: 172 additions & 133 deletions

File tree

.env_circleci

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ SUBMISSIONS_API_URL=http://django:8000/api
4141
# Nginx settings
4242
# -----------------------------------------------------------------------------
4343
HTTPS=False
44-
RATE_LIMIT=10000
44+
RATE_LIMIT=100
4545
DOMAIN_NAME=localhost
46+
DATABASE_ACCESS=True

.env_sample

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
SECRET_KEY=change-this-secret
1+
# Use openssl rand -hex 32 to generate this secret key, or generate it however you want and copy it here
2+
SECRET_KEY=
23

34
# For local setup and debug
45
DEBUG=False
56

7+
# -----------------------------------------------------------------------------
68
# Database
9+
# -----------------------------------------------------------------------------
710
DB_HOST=db
811
DB_NAME=postgres
912
DB_USERNAME=postgres
1013
DB_PASSWORD=postgres
1114
DB_PORT=5432
1215

16+
# -----------------------------------------------------------------------------
17+
# Django
18+
# -----------------------------------------------------------------------------
1319
DJANGO_SETTINGS_MODULE=settings.develop
14-
ALLOWED_HOSTS=localhost,example.com
20+
ALLOWED_HOSTS=localhost,
1521
SUBMISSIONS_API_URL=http://django:8000/api
1622
MAX_EXECUTION_TIME_LIMIT=600 # time limit for the default queue (in seconds)
1723

@@ -21,24 +27,29 @@ MAX_EXECUTION_TIME_LIMIT=600 # time limit for the default queue (in seconds)
2127
HTTPS=False
2228
RATE_LIMIT=5
2329
DOMAIN_NAME=localhost
24-
25-
26-
# SSL style domain definition
2730
TLS_EMAIL=your@email.com
28-
# DOMAIN_NAME=example.com:443
2931

32+
# -----------------------------------------------------------------------------
33+
# RabbitMQ
34+
# -----------------------------------------------------------------------------
3035
RABBITMQ_HOST=rabbit
3136
RABBITMQ_DEFAULT_USER=rabbit-username
3237
RABBITMQ_DEFAULT_PASS=rabbit-password-you-should-change
3338
RABBITMQ_MANAGEMENT_PORT=15672
3439
RABBITMQ_PORT=5672
3540
WORKER_CONNECTION_TIMEOUT=100000000 # milliseconds
3641

37-
FLOWER_PUBLIC_PORT=5555
3842

43+
# -----------------------------------------------------------------------------
44+
# Flower
45+
# -----------------------------------------------------------------------------
46+
FLOWER_PUBLIC_PORT=5555
3947
FLOWER_BASIC_AUTH=root:password-you-should-change
4048

41-
SELENIUM_HOSTNAME=selenium
49+
50+
# -----------------------------------------------------------------------------
51+
# Email Settings
52+
# -----------------------------------------------------------------------------
4253

4354
# Uncomment to enable email settings
4455
#EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
@@ -76,21 +87,6 @@ AWS_QUERYSTRING_AUTH=False
7687
#WORKER_BUNDLE_URL_REWRITE=http://localhost:9000|http://minio:9000
7788

7889

79-
# -----------------------------------------------------------------------------
80-
# Limit for re-running submission
81-
# This is used to limit users to rerun submissions
82-
# on default queue when number of submissions are < RERUN_SUBMISSION_LIMIT
83-
# -----------------------------------------------------------------------------
84-
RERUN_SUBMISSION_LIMIT=30
85-
86-
87-
# -----------------------------------------------------------------------------
88-
# Enable or disbale regular email sign-in an sign-up
89-
# -----------------------------------------------------------------------------
90-
ENABLE_SIGN_UP=True
91-
ENABLE_SIGN_IN=True
92-
93-
9490
# # S3 storage example
9591
# STORAGE_TYPE=s3
9692
# AWS_ACCESS_KEY_ID=12312312312312312331223
@@ -113,6 +109,20 @@ ENABLE_SIGN_IN=True
113109
# GS_PRIVATE_BUCKET_NAME=private
114110
# GOOGLE_APPLICATION_CREDENTIALS=/app/certs/google-storage-api.json
115111

112+
# -----------------------------------------------------------------------------
113+
# Limit for re-running submission
114+
# This is used to limit users to rerun submissions
115+
# on default queue when number of submissions are < RERUN_SUBMISSION_LIMIT
116+
# -----------------------------------------------------------------------------
117+
RERUN_SUBMISSION_LIMIT=30
118+
119+
120+
# -----------------------------------------------------------------------------
121+
# Enable or disbale regular email sign-in an sign-up
122+
# -----------------------------------------------------------------------------
123+
ENABLE_SIGN_UP=True
124+
ENABLE_SIGN_IN=True
125+
116126

117127
# -----------------------------------------------------------------------------
118128
# Logging (Serialized outputs the logs in JSON format)

docker-compose.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ services:
33
# Web Services
44
#----------------------------------------------------------------------------------------------------
55
nginx:
6-
image: nginx:latest
6+
image: nginx:alpine
77
env_file: .env
88
environment:
99
- NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
1010
command: ["nginx", "-g", "daemon off;"]
1111
volumes:
12-
- ./src/staticfiles:/var/www/django/static
13-
- ./maintenance_mode/:/srv
12+
- ./src/staticfiles:/var/www/django/static:ro
13+
- ./maintenance_mode/:/srv:ro
14+
- ./nginx/:/etc/nginx/templates/:ro
1415
- ./nginx/certs/:/var/cache/nginx/acme-letsencrypt
15-
- ./nginx/:/etc/nginx/templates/
1616
- ./var/log/nginx/:/var/log/nginx
1717
restart: unless-stopped
1818
ports:
@@ -22,14 +22,8 @@ services:
2222
- 5432:5432
2323
- ${RABBITMQ_MANAGEMENT_PORT:-15672}:15672
2424
- ${RABBITMQ_PORT}:5672
25-
- ${MINIO_PORT}:9000
25+
- ${MINIO_PORT:-9000}:9000
2626
- ${FLOWER_PUBLIC_PORT:-5555}:5555
27-
depends_on:
28-
- django
29-
- minio
30-
- rabbit
31-
- site_worker
32-
- db
3327
networks:
3428
- frontend
3529
- backend
@@ -65,6 +59,7 @@ services:
6559
max-file: "5"
6660
networks:
6761
- backend
62+
- frontend
6863

6964

7065
#----------------------------------------------------------------------------------------------------
@@ -81,7 +76,7 @@ services:
8176
- 9001
8277
env_file: .env
8378
environment:
84-
MINIO_BROWSER_REDIRECT_URL: "http://localhost/console"
79+
MINIO_BROWSER_REDIRECT_URL: "http://${DOMAIN_NAME}/console"
8580
healthcheck:
8681
test: ["CMD", "curl", "-I", "http://minio:9000/minio/health/live"]
8782
interval: 5s
@@ -150,7 +145,7 @@ services:
150145
volumes:
151146
- ./var/postgres:/var/lib/postgresql/18/:delegated
152147
- ./backups:/app/backups
153-
- ./my-postgres.conf:/etc/postgresql/postgresql.conf
148+
- ./my-postgres.conf:/etc/postgresql/postgresql.conf:ro
154149
restart: unless-stopped
155150
logging:
156151
options:
@@ -260,7 +255,7 @@ services:
260255
- django
261256
- rabbit
262257
volumes:
263-
- ./compute_worker:/app
258+
- ./compute_worker:/app:ro
264259
- ${HOST_DIRECTORY:-/tmp/codabench}:/codabench
265260
# Actual connection back to docker parent to run things
266261
- /var/run/docker.sock:/var/run/docker.sock
@@ -278,6 +273,7 @@ services:
278273
max-file: "5"
279274
networks:
280275
- backend
276+
- frontend
281277

282278
networks:
283279
frontend:

nginx/extra/anti_scrapper.conf.template

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
limit_req_status 429;
33
limit_req zone=scraperlimit burst=25 nodelay;
44

5-
location /robots.txt {
6-
autoindex off;
7-
alias /etc/nginx/templates/robots.txt;
8-
}
9-
105
# Deny access to bots
116
# Block user agents that tend to be scrapers and badly behaved bots
127
if ($bad_bot = 1) {

nginx/http/minio.conf.template

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,37 @@ server {
1010
proxy_request_buffering off;
1111

1212
location / {
13+
include extra/anti_scrapper.conf;
14+
1315
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
1416
proxy_http_version 1.1;
1517
proxy_set_header Connection "";
1618
chunked_transfer_encoding off;
1719

1820
proxy_pass http://minio:9000;
1921
}
22+
23+
# MinIO console
24+
location /console/ {
25+
include extra/anti_scrapper.conf;
26+
27+
rewrite ^/console/(.*)$ /$1 break;
28+
proxy_set_header Host $http_host;
29+
proxy_set_header X-Real-IP $remote_addr;
30+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31+
proxy_set_header X-Forwarded-Proto $scheme;
32+
proxy_set_header X-NginX-Proxy true;
33+
34+
# This is necessary to pass the correct IP to be hashed
35+
real_ip_header X-Real-IP;
36+
proxy_connect_timeout 300;
37+
38+
# To support websocket
39+
proxy_http_version 1.1;
40+
proxy_set_header Upgrade $http_upgrade;
41+
proxy_set_header Connection "Upgrade";
42+
43+
chunked_transfer_encoding off;
44+
proxy_pass http://minio:9001;
45+
}
2046
}

0 commit comments

Comments
 (0)