Djevops: Self-Host Django Easily

mherrmann1 pts0 comments

GitHub - mherrmann/djevops: Self-host Django easily · GitHub

/" data-turbo-transient="true" />

Skip to content

Search or jump to...

Search code, repositories, users, issues, pull requests...

-->

Search

Clear

Search syntax tips

Provide feedback

--><br>We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel

Submit feedback

Saved searches

Use saved searches to filter your results more quickly

-->

Name

Query

To see all available qualifiers, see our documentation.

Cancel

Create saved search

Sign in

/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up

Appearance settings

Resetting focus

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

mherrmann

djevops

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star<br>16

main

BranchesTags

Go to file

CodeOpen more actions menu

Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit

History<br>194 Commits<br>194 Commits

djevops

djevops

test

test

.gitignore

.gitignore

LICENSE

LICENSE

README.md

README.md

pyproject.toml

pyproject.toml

uv.lock

uv.lock

View all files

Repository files navigation

djevops: Self-host Django easily

djevops is a command-line tool for deploying your Django web app to a Linux VPS.<br>It runs and manages all necessary components (database, Redis, etc.) on your<br>server.

Unlike other tools, djevops does not use Docker. This makes it possible to "push<br>to prod" in seconds. Compared to Ansible, djevops' specialization on Django lets<br>you write significantly less code. The flip side is that djevops is less<br>general.

To get started with djevops, all you need is SSH root access to a Linux VPS<br>running Ubuntu or Debian. Install djevops on your local machine with<br>pip install djevops. Then, execute djevops init in your Django app's Git<br>repository. You get a config file that looks similar to the following:

server: 1.2.3.4

git:<br>repo: githubuser/mydjangoapp<br>branch: main

services:<br>web:<br>type: django<br>env:<br>clear:<br>ALLOWED_HOSTS: your.website.com<br>secret:<br>- DJANGO_SECRET_KEY

db:<br>type: sqlite

mail:<br>host: smtp.gmail.com<br>user: SMTP_USER<br>password: SMTP_PASSWORD

Secrets such as DJANGO_SECRET_KEY or SMTP_PASSWORD can be specified as<br>constants in file deploy/secrets.py.

Most config values are optional. Fill in the ones you want and run<br>djevops deploy. djevops then clones your Git repo on the server and starts<br>all services. As you work on your Django app and push new commits to Git, simply<br>run djevops deploy again to apply them to your server.

Features

Automatic SSL certificates<br>djevops generates and automatically renews SSL certificates for any domains you<br>specify in Django setting ALLOWED_HOSTS. The domains need to be tied to your<br>server's IP address.

Error emails<br>If you filled in the mail section in the config file, then you can make Django<br>email you when errors occur. To do so, set ADMINS in Django's settings.py as<br>follows:

ADMINS = [('Your Name', 'your@email.com)]

Error emails require Django setting DEBUG to be False.

Automatic database backups<br>You can set up automatic database backups by adding a backup element to the<br>db section in the djevops config file. For example:

db:<br>type: sqlite<br>backup:<br>type: s3<br>bucket: mybackup<br>access-key-id: S3_BACKUP_ACCESS_KEY<br>secret-access-key: S3_BACKUP_SECRET_KEY<br>path: db<br>region: us-east-1

Backups are created continuously while your server is running. If you ever<br>re-install your server, then the latest backup is automatically restored.

For database type sqlite, djevops uses Litestream<br>for backups. Litestream can store backups in S3, Azure Blob Storage and many<br>others. The keys you add to the backup element above get copied into a<br>replica element in Litestream's config. For more information about the<br>available options, please<br>see Litestream's documentation.

Djevops also supports database type postgres. For more information about this,<br>please see below.

PostgreSQL<br>Instead of SQLite, you can use PostgreSQL by setting the database type to<br>postgres:

db:<br>type: postgres

You then configure the connection yourself in your settings.py:

import os

DATABASES['default'] = {<br>'ENGINE': 'django.db.backends.postgresql',<br>'NAME': 'myapp',<br>'USER': 'myapp',<br>'PASSWORD': os.environ['DB_PASSWORD'],<br>'HOST': 'localhost'

djevops reads these settings and installs PostgreSQL on the server, creating the<br>database and user with the password you specified. Keep the password out of Git<br>by storing it in deploy/secrets.py. For example:

"">DB_PASSWORD = ""

Then reference it as a secret in the Django service's environment:

services:<br>web:<br>type: django<br>env:<br>secret:<br>- DB_PASSWORD

You also need to add psycopg[binary] to your pyproject.toml or<br>requirements.txt file.

As with SQLite, you can add a...

djevops django type server database file

Related Articles