Skip to main content

Truck Signs API

Truck Signs API is a backend service for managing truck signs in a transport fleet. The project is containerized using Docker and uses PostgreSQL for persistent storage.


Table of Contents


Quickstart

Prerequisites:

  • Docker
  • Docker network for DB

Steps:

  1. Create your .env file:
cp .env.example .env
  1. Create the Docker network (if not existing):
docker network create trucknet
  1. Start PostgreSQL:
docker run -d \
--name db \
--network trucknet \
-v postgres_data:/var/lib/postgresql/data \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=trucksigns \
postgres:15
  1. Build and run the Truck Signs API:
docker build -t truck-signs-api .
docker run -d \
--name truckapi \
--network trucknet \
-p 8020:8020 \
--env-file .env \
truck-signs-api
  1. Access the API:
http://<your-vm-ip>:8020

Usage

  • Navigate to the above URL to use the API.
  • Admin panel available at /admin/.
  • Entrypoint handles migrations, collectstatic, and superuser creation automatically.
  • API runs on Gunicorn at port 8020.

Environment Variables

You can configure the project by modifying .env.example:

VariableDescriptionExample
DJANGO_SUPERUSER_USERNAMEUsername for Django superuseradmin
DJANGO_SUPERUSER_EMAILEmail for Django superuseradmin@example.com
DJANGO_SUPERUSER_PASSWORDPassword for Django superuserchangeme
POSTGRES_USERPostgreSQL usernameuser
POSTGRES_PASSWORDPostgreSQL passwordpassword
POSTGRES_DBPostgreSQL database nametrucksigns
POSTGRES_HOSTPostgreSQL host (container name)db
POSTGRES_PORTPostgreSQL port5432
DEBUGDjango debug modeFalse

Superuser Access (Admin Panel):

  1. Automatic creation (recommended)
    The entrypoint script automatically creates a superuser on the first container start if the following environment variables are set in your .env file:

    • DJANGO_SUPERUSER_USERNAME
    • DJANGO_SUPERUSER_EMAIL
    • DJANGO_SUPERUSER_PASSWORD
  2. Manual creation
    If you need to create a superuser manually:

  docker exec -it truckapi python manage.py createsuperuser

After the superuser is created, log in to the Django admin panel at /admin/ using the credentials you set. From the admin panel, you can:

  • Manage users and permissions
  • View and edit trucks, signs, or other models
  • Monitor API-related data
  • The API runs on Gunicorn at port 8020.
  • Entrypoint also handles migrations and collectstatic automatically.

Volumes

  • postgres_data: Stores PostgreSQL database files to persist data between container restarts.

Restarting and Stopping Containers

  1. Stop and start containers:
docker stop truckapi db
docker start db truckapi

Security

  • Do not commit .env files, passwords, SSH keys, or other sensitive information to the repository.
  • Containers communicate over Docker networks; use hostnames instead of IP addresses.
  • Critical configuration is provided via environment variables only.