change deployment to use docker-compose
This commit is contained in:
-15
@@ -1,15 +0,0 @@
|
|||||||
FROM python:3.11-slim
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy application files
|
|
||||||
COPY urlshort.py ./
|
|
||||||
COPY config.json ./
|
|
||||||
|
|
||||||
# Data directory is mounted as a volume; pre-create it for local runs
|
|
||||||
RUN mkdir -p /app/data
|
|
||||||
|
|
||||||
EXPOSE 8080
|
|
||||||
|
|
||||||
CMD ["python", "urlshort.py", "config.json"]
|
|
||||||
|
|
||||||
+6
-4
@@ -1,12 +1,14 @@
|
|||||||
services:
|
services:
|
||||||
urlshort:
|
urlshort:
|
||||||
build:
|
image: python:3.11-slim
|
||||||
context: .
|
working_dir: /app
|
||||||
dockerfile: Dockerfile
|
command: ["python", "-u", "urlshort.py", "config.json"]
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
volumes:
|
volumes:
|
||||||
# Persist the SQLite database outside the container
|
- ./urlshort.py:/app/urlshort.py:ro
|
||||||
|
- ./config.json:/app/config.json:ro
|
||||||
|
- ./static:/app/static:ro
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
# ===========================================================================
|
||||||
|
# URL Shortener — nginx location blocks
|
||||||
|
# Drop these into an existing server { } block.
|
||||||
|
#
|
||||||
|
# Assumptions:
|
||||||
|
# - The Python backend is reachable at http://urlshort:8080
|
||||||
|
# (docker service name; swap for 127.0.0.1:8080 or upstream as needed)
|
||||||
|
# - Static frontend files live at /app/static/
|
||||||
|
# (adjust the alias paths to match your deployment layout)
|
||||||
|
#
|
||||||
|
# Path mapping (base_url = http://<host>/s):
|
||||||
|
# /s/ -> frontend index.html
|
||||||
|
# /s/static/... -> frontend CSS / JS
|
||||||
|
# /s/api/... -> Python backend (proxy)
|
||||||
|
# /s/<code> -> Python backend (redirect, proxy)
|
||||||
|
# ===========================================================================
|
||||||
|
|
||||||
|
# --- Redirect bare /s to /s/ for clean UX ---
|
||||||
|
location = /s {
|
||||||
|
return 301 /s/;
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Serve frontend index.html at /s/ ---
|
||||||
|
location = /s/ {
|
||||||
|
alias /app/static/index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Serve frontend static assets (CSS, JS, etc.) ---
|
||||||
|
# ^~ ensures this takes priority over the general /s/ proxy below.
|
||||||
|
location ^~ /s/static/ {
|
||||||
|
alias /app/static/;
|
||||||
|
expires 7d;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Proxy everything else under /s/ to the Python backend ---
|
||||||
|
# Covers: /s/api/shorten, /s/api/urls, /s/api/lookup, /s/<code> redirects
|
||||||
|
location /s/ {
|
||||||
|
proxy_pass http://urlshort:8080;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user