Topic · Delivery & releases

Deploy scripts & infrastructure as code for Django in production

Scripting servers and releases so they are repeatable: Bash, Fabric, Ansible, Terraform, and cloud-init.

three layers of automationTerraformservers, firewalls, DNS: rarelycloud-init / Ansiblepackages, users, units: once per serverDeploy script / CIcode, migrate, restart: every releaseKeep each layer to its own job and servers become replaceable

Automation replaces a person remembering steps with something that runs them the same way every time: a deploy script, Fabric or Ansible, cloud-init, or Terraform.

The guides show where each tool fits: Terraform builds servers, cloud-init and Ansible configure them, and a script or pipeline ships releases.

12Set it up
3Run it well
1Check it

Set it up

Guides that take this from nothing to running in production.

  • Deploy Django with Ansible: Step-by-Step

    Manual Django deployment usually starts simple and becomes unreliable fast. You SSH into a server, pull code, install packages, update environment variables, run migrations, res...

  • Deploy Django with Fabric

    Automate Django deployments over SSH with Fabric: a fabfile with release directories, dependency install, migrations, collectstatic, atomic symlink switch, health checks, and rollback.

  • Provision a Django Server with cloud-init

    Use cloud-init user data to provision a Django-ready Ubuntu server on first boot: users and SSH keys, packages, firewall, swap, directories, systemd units, and verification.

  • Deploy Django from a Private Git Repository with Deploy Keys

    Let a Django server pull code from a private GitHub, GitLab, or Bitbucket repository with read-only deploy keys: SSH config aliases, known_hosts, private dependencies, and alternatives.

  • Provision Django Infrastructure With Pulumi

    Provision Django infrastructure with Pulumi in Python: define a VPC, database, container service, and secrets as code, manage stacks for staging and production, keep secrets encrypted in config, and preview changes before applying.

  • Deploy Django on AWS With the CDK

    Deploy Django on AWS with the Cloud Development Kit in Python: an ApplicationLoadBalancedFargateService, RDS PostgreSQL, Secrets Manager, S3 media, and a migration task, with cdk diff and cdk deploy in CI.

  • Deploy Django With git push and a post-receive Hook

    Deploy Django to your own server with git push production main: a bare repository with a post-receive hook that checks out the code, installs dependencies, runs migrations and collectstatic, and reloads Gunicorn, with safe failure handling.

  • Atomic Django Releases With Symlinked Release Directories

    Deploy Django with timestamped release directories and an atomic current symlink: build each release in isolation, share media and env files, switch with ln -sfn, reload Gunicorn gracefully, and roll back instantly to the previous release.

  • Encrypt Django Secrets in Git With SOPS

    Keep Django environment secrets encrypted in the repository with Mozilla SOPS and age: encrypt .env and YAML files, decrypt during deploys with Ansible or CI, use cloud KMS keys for teams, and keep keys out of Git.

  • Deploy Django on NixOS With a Declarative Configuration

    Deploy Django on NixOS: define Gunicorn, PostgreSQL, Redis, Nginx, and ACME certificates in configuration.nix, package the app with a Python environment, manage secrets with agenix or sops-nix, and roll back safely with generations.

  • Deploy Django on HashiCorp Nomad

    Deploy Django on HashiCorp Nomad: write a job with web, worker, and migration tasks, pull Docker images, inject secrets from Vault or Nomad Variables with templates, register services, route traffic through Traefik or Consul, and roll out safely.

  • Manage Django Kubernetes Manifests With Kustomize Overlays

    Structure Django Kubernetes manifests with Kustomize: a base with Deployment, Service, and migration Job, overlays for staging and production with replicas, resources, and hosts, image tags set from CI, ConfigMap generators with hash suffixes, and use with Argo CD.

Run it well

Tuning, reliability, and operations once it works.

Check it

Review lists to run before launch or after a change.

  • Django Project Handover Checklist

    Hand over a production Django project cleanly: repository and access, infrastructure inventory, secrets rotation, deploy and rollback runbooks, backups and restore tests, monitoring, domains, and third-party accounts.

Learning paths through this topic

Related topics