Skip to content

Commit 379e7f0

Browse files
authored
v1.4.0 (#6)
## Summary This PR improves the containerized deployment with a focus on security, performance, and maintainability, while keeping a single-container setup suitable for low-resource and free hosting environments. > No application logic was changed. ## Changes ### Runtime & Architecture - Switch application runtime to ASGI using gunicorn + uvicorn.workers.UvicornWorker ### Remove dependency on Django Channels (no WebSocket usage) - Keep Django running in ASGI mode for improved concurrency and future compatibility ### Security - Run nginx and the application as a non-root user - Use a local, non-root-friendly nginx.conf - Avoid runtime mutation of system configuration files - Remove sensitive files (.env, .secret) during build - Add a concise SECURITY.md with responsible disclosure guidance (hobby project, no SLA) ### Performance & Image Size - Switch base image to python:3.11-alpine - Reduce image size and build time - Improve Docker layer caching by installing dependencies before copying source code ### Maintenance & Cleanup - Simplify entrypoint.sh (no fixed sleep, no sed or chown at runtime) - Ensure clean shutdown by running nginx as PID 1 - Keep configuration minimal and explicit ## Notes - Designed for environments where docker-compose is not available - HTTP-only by design (no WebSocket support) - Suitable for hobby and personal projects without guaranteed SLAs
1 parent 2e79851 commit 379e7f0

File tree

6 files changed

+104
-50
lines changed

6 files changed

+104
-50
lines changed

Dockerfile

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
1-
FROM python:3.11-slim-bookworm
1+
FROM python:3.11-alpine
22

3-
ENV PYTHONDONTWRITEBYTECODE 1
4-
ENV PYTHONUNBUFFERED 1
5-
ENV VIRTUAL_ENV=/opt/venv
6-
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
7-
ENV DEBUG=False
8-
9-
RUN apt-get update && \
10-
apt-get install -y --no-install-recommends nginx python3-venv && \
11-
rm -rf /var/lib/apt/lists/*
12-
13-
RUN python -m venv $VIRTUAL_ENV
14-
15-
RUN groupadd -r nginxgroup && \
16-
useradd -r -g nginxgroup -s /bin/false nginxuser
17-
18-
RUN mkdir -p /run/nginx && \
19-
chown -R nginxuser:nginxgroup /run/nginx /var/log/nginx /var/lib/nginx
3+
ENV PYTHONDONTWRITEBYTECODE=1 \
4+
PYTHONUNBUFFERED=1 \
5+
VIRTUAL_ENV=/opt/venv \
6+
PATH="/opt/venv/bin:$PATH" \
7+
DEBUG=False
8+
9+
RUN apk add --no-cache \
10+
nginx \
11+
bash \
12+
ca-certificates \
13+
libffi \
14+
libffi-dev \
15+
openssl \
16+
openssl-dev \
17+
libsodium \
18+
linux-headers \
19+
gcc \
20+
musl-dev \
21+
cargo \
22+
&& python -m venv /opt/venv \
23+
&& addgroup -S nginxgroup \
24+
&& adduser -S nginxuser -G nginxgroup \
25+
&& mkdir -p \
26+
/run/nginx \
27+
/var/log/nginx \
28+
/var/lib/nginx \
29+
&& chown -R nginxuser:nginxgroup \
30+
/run/nginx \
31+
/var/log/nginx \
32+
/var/lib/nginx
2033

2134
WORKDIR /app
2235

2336
COPY requirements.txt .
24-
RUN /opt/venv/bin/pip install --no-cache-dir -r requirements.txt
37+
RUN pip install --upgrade pip wheel \
38+
&& pip install --no-cache-dir -r requirements.txt
2539

2640
COPY . .
2741

28-
RUN /opt/venv/bin/python manage.py collectstatic --noinput && \
29-
find . -type f -name '*.env' -delete && \
30-
find . -type f -name '*.secret' -delete
42+
RUN python manage.py collectstatic --noinput \
43+
&& find . -type f \( -name '*.env' -o -name '*.secret' \) -delete
3144

32-
RUN rm -f /etc/nginx/sites-enabled/default
45+
RUN rm -f /etc/nginx/http.d/default.conf
3346
COPY nginx.conf /etc/nginx/nginx.conf
3447

3548
COPY entrypoint.sh /app/entrypoint.sh
36-
37-
RUN chmod 755 /app/entrypoint.sh && \
38-
chmod a-w /app/entrypoint.sh
39-
40-
RUN chown -R nginxuser:nginxgroup /app
49+
RUN chown nginxuser:nginxgroup /app/entrypoint.sh \
50+
&& chmod 550 /app/entrypoint.sh \
51+
&& chown -R nginxuser:nginxgroup /app
4152

4253
EXPOSE 8080
4354

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can visit my portfolio online at [My Portfolio](https://myportfolio-kn09.onr
2222

2323
#### Prerequisites
2424

25-
- Python 3.11 or 3.12
25+
- Python 3.11+
2626
- python3-virtualenv or python3-venv
2727
- Redis (for caching)
2828
- Docker (optional)

SECURITY.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
5+
If you believe you have found a security issue in this project, please **do not open a public issue**.
6+
7+
Instead, report it privately using one of the contacts below:
8+
9+
- **Email:** brunoriansouza@gmail.com
10+
11+
Please include:
12+
13+
* A brief description of the issue
14+
* Steps to reproduce (if possible)
15+
* Potential impact
16+
17+
This is a **hobby project**. I will respond **as soon as possible**, but **no response time is guaranteed**.
18+
19+
## Supported Versions
20+
21+
Only the **latest version** of this project is supported.
22+
23+
Older versions do not receive security updates.
24+
25+
## Scope and Disclaimer
26+
27+
This project is provided **as-is**, without any warranty or guarantee of security.
28+
29+
The following are generally out of scope:
30+
31+
- Issues caused by misconfiguration or improper deployment
32+
- Vulnerabilities in third-party services or dependencies
33+
- Denial-of-service attacks
34+
35+
Users are responsible for deploying and running this software securely.
36+
37+
## Responsible Disclosure
38+
39+
Please:
40+
41+
- Act in good faith
42+
- Avoid publicly disclosing vulnerabilities before a fix is available
43+
- Do not exploit issues beyond a proof of concept
44+
45+
Thank you for helping keep this project safer.

docs/LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GNU GENERAL PUBLIC LICENSE
22

3-
![Icon](./icon.png)
3+
![Icon](docs/icon.png)
44

55
Version 3, 29 June 2007
66

@@ -674,4 +674,4 @@ program into proprietary programs. If your program is a subroutine
674674
library, you may consider it more useful to permit linking proprietary
675675
applications with the library. If this is what you want to do, use the
676676
GNU Lesser General Public License instead of this License. But first,
677-
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
677+
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.

entrypoint.sh

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
set -e
23

3-
PORT=${PORT:-8080}
4-
5-
sed -i "s/listen 8080;/listen $PORT;/" /etc/nginx/nginx.conf
6-
7-
mkdir -p /run/nginx
8-
chown nginxuser:nginxgroup /run/nginx
9-
10-
/opt/venv/bin/gunicorn \
4+
/opt/venv/bin/gunicorn \
5+
server.asgi:application \
116
--bind 0.0.0.0:8000 \
12-
--workers 3 \
13-
--worker-class gthread \
14-
--threads 2 \
15-
--timeout 30 \
16-
server.wsgi &
17-
18-
sleep 5
7+
--workers 2 \
8+
--worker-class uvicorn.workers.UvicornWorker &
199

2010
exec nginx -g "daemon off;"

nginx.conf

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ http {
2424
server {
2525
listen 8080;
2626
server_name _;
27-
27+
2828
location ~* ^/(\.env|__debug__|debug|env|secrets) {
2929
deny all;
3030
return 403;
3131
}
3232

3333
location / {
34-
proxy_pass http://localhost:8000;
34+
proxy_pass http://127.0.0.1:8000;
35+
36+
proxy_http_version 1.1;
37+
proxy_set_header Upgrade $http_upgrade;
38+
proxy_set_header Connection "upgrade";
39+
3540
proxy_set_header Host $host;
3641
proxy_set_header X-Real-IP $remote_addr;
3742
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3843
proxy_set_header X-Forwarded-Proto $scheme;
39-
44+
4045
proxy_connect_timeout 15s;
4146
proxy_read_timeout 30s;
4247
proxy_send_timeout 30s;
4348
}
4449

4550
server_tokens off;
51+
4652
add_header X-Content-Type-Options "nosniff";
4753
add_header X-Frame-Options "DENY";
4854
add_header Referrer-Policy "same-origin";
55+
add_header X-XSS-Protection "1; mode=block";
56+
add_header Permissions-Policy "geolocation=()";
4957
}
5058
}

0 commit comments

Comments
 (0)