π Truck Signs API
This page documents how I configured my very first cloud server instance in the Developer Akademie DevSecOps Course.
TOCβ
π Truck Signs API
π Table of Contentsβ
βοΈ Prerequisitesβ
Before running the application, make sure you have:
- Docker (>= 27)
- Git
- Open ports:
8020(API) and5432(PostgreSQL)
β‘ Quickstartβ
1. Clone this repository
git clone https://github.com/Gosia2024/truck_signs_api.git
cd truck_signs_api
- Copy the example environment file
cd truck_signs_designs/settings
cp simple_env_config.env .env
β οΈ This .env contains only insecure example values. Replace them with real secrets for production use.
- Build and run the containers
docker build -t trucks-api:local .
docker network create trucks-net 2>/dev/null || true
docker run -d --name ts-db \
--network trucks-net \
--env-file ./db.env \
-p 5432:5432 \
-v pgdata:/var/lib/postgresql/data \
--restart unless-stopped \
postgres:13
docker run -d --name ts-api \
--network trucks-net \
-p 8020:8020 \
--env-file ./.env.app \
--restart unless-stopped \
trucks-api:local
- Check containers are running
docker ps
- Open the application
-
Admin panel β http://localhost:8020/admin
-
Example endpoint β http://localhost:8020/truck-signs/categories/
βοΈ Environment Variablesβ
db.env (PostgreSQL container):
POSTGRES_DB=trucks
POSTGRES_USER=truckuser
POSTGRES_PASSWORD=CHANGE_ME
.env.app (Django container):
# --- CORE ---
DOCKER_SECRET_KEY=CHANGE_ME
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1
DJANGO_DEBUG=False
# --- DB (must match db.env) ---
DOCKER_DB_NAME=trucks
DOCKER_DB_USER=truckuser
DOCKER_DB_PASSWORD=CHANGE_ME
DOCKER_DB_HOST=ts-db
DOCKER_DB_PORT=5432
# --- AUTO SUPERUSER (optional) ---
DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_EMAIL=admin@example.com
DJANGO_SUPERUSER_PASSWORD=CHANGE_ME
# --- STRIPE (dummy) ---
DOCKER_STRIPE_PUBLISHABLE_KEY=dummy
DOCKER_STRIPE_SECRET_KEY=dummy
DOCKER_STRIPE_WEBHOOK_SECRET=dummy
# --- EMAIL (console backend) ---
DOCKER_EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
DOCKER_EMAIL_HOST=localhost
DOCKER_EMAIL_PORT=1025
DOCKER_EMAIL_USE_TLS=False
DOCKER_EMAIL_HOST_USER=dummy
DOCKER_EMAIL_HOST_PASSWORD=dummy
DEFAULT_FROM_EMAIL=app@example.com
# --- WSGI ---
DJANGO_SETTINGS_MODULE=truck_signs_designs.settings.test_docker
APP_MODULE=truck_signs_designs.wsgi:application
GUNICORN_APP_MODULE=truck_signs_designs.wsgi:application
π§ͺ Usageβ
Create a superuser
docker exec -it ts-api python manage.py createsuperuser
View logs
docker logs -f ts-api
docker logs -f ts-db
Restart containers
docker restart ts-api
docker restart ts-db
Update and redeploy
git pull
docker build -t trucks-api:local .
docker rm -f ts-api
docker run -d --name ts-api \
--network trucks-net \
-p 8020:8020 \
--env-file ./.env.app \
--restart unless-stopped \
trucks-api:local
π Deployment on V-Serverβ
On your server (V-Server / VPS):
- Clone and build
git clone https://github.com/Gosia2024/truck_signs_api.git
cd truck_signs_api
docker build -t trucks-api:local .
- Adjust allowed hosts
- In .env.app set
DJANGO_ALLOWED_HOSTS=your.server.ip
- Run containers
docker network create trucks-net 2>/dev/null || true
docker run -d --name ts-db \
--network trucks-net \
--env-file ./db.env \
-p 5432:5432 \
-v pgdata:/var/lib/postgresql/data \
--restart unless-stopped \
postgres:13
docker run -d --name ts-api \
--network trucks-net \
-p 8020:8020 \
--env-file ./.env.app \
--restart unless-stopped \
trucks-api:local
- Access on your server
-
http://YOUR_SERVER_IP:8020/admin
-
http://YOUR_SERVER_IP:8020/truck-signs/categories/
π» Technologiesβ
-
Python 3.8.10
-
Django 2.2.8
-
Django REST Framework 3.12.4
-
PostgreSQL 13
-
Docker 27.2.0
-
Gunicorn (WSGI server)
-
WhiteNoise (static files)
π Additional Notesβ
-
Project settings are split into environments (development, test_docker, production) inside truck_signs_designs/settings/
-
The API exposes CRUD endpoints for categories, products, lettering items, orders and payments (Stripe)
-
This project contains only the backend β static files are served by WhiteNoise inside the Gunicorn container
π Troubleshootingβ
FATAL: password authentication failed for user "truckuser" β Passwords in db.env and .env.app do not match. β Remove the volume and recreate:
docker rm -f ts-db
docker volume rm pgdata
DisallowedHost β Add your IP/domain to DJANGO_ALLOWED_HOSTS and restart ts-api.
Static files not served β WhiteNoise serves static files; ensure collectstatic runs in entrypoint.
Line endings (Windows) β Ensure container-entrypoint.sh has LF endings and is executable:
git update-index --chmod=+x container-entrypoint.sh