Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Python
__pycache__/
*.py[cod]
*.egg-info/

# VCS
.git/
.gitignore

# IDE
.vscode/
.idea/

# Envs
.env
.venv/
venv/

# OS files
.DS_Store

# Local DB and caches
*.sqlite3
/db.sqlite3
staticfiles/
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Base image with Python 2.7
FROM python:2.7-slim

# Prevent pyc files and enable unbuffered logs
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /app

# System dependencies for building wheels and required libs (psycopg2, pylibmc, etc.)
# Note: Debian buster is EOL. Point sources to archive.debian.org and disable validity check.
RUN sed -i -e 's|deb.debian.org|archive.debian.org|g' \
-e 's|security.debian.org/debian-security|archive.debian.org/debian-security|g' /etc/apt/sources.list \
&& apt-get -o Acquire::Check-Valid-Until=false update \
&& apt-get install -y --no-install-recommends \
build-essential \
gcc \
libpq-dev \
python-dev \
libmemcached-dev \
libsasl2-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

# Install dependencies first for better caching
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

# Copy project files
COPY . /app

# Ensure entrypoint is executable
RUN chmod +x entrypoint.sh

# Expose gunicorn port
EXPOSE 8000

# Default command
CMD ["./entrypoint.sh"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.8"
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8001:8000"
environment:
- DEBUG=1
20 changes: 20 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

# Apply database migrations
python manage.py migrate --noinput

# Load initial data fixtures (mirrors Makefile load_data target)
python manage.py loaddata planets.json
python manage.py loaddata people.json
python manage.py loaddata species.json
python manage.py loaddata transport.json
python manage.py loaddata starships.json
python manage.py loaddata vehicles.json
python manage.py loaddata films.json

# Collect static files
python manage.py collectstatic --noinput

# Start server
exec gunicorn swapi.wsgi --bind 0.0.0.0:8000 --log-file -
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ drf-json-api==0.1.0
gunicorn==19.1.1
keen==0.3.7
markdown2==2.3.0
psycopg2==2.5.4
psycopg2==2.8.6
pycrypto==2.6.1
pylibmc==1.4.1
requests==2.5.1
Expand Down