Skip to main content

A proof-of-concept django-simple-deploy plugin that deploys nanodjango projects to Fly.io

Project description

dsd-flyio-nanodjango

A proof-of-concept django-simple-deploy plugin that deploys nanodjango projects to Fly.io.

Sample nanodjango project

This is taken from the nanodjango docs. I'm recreating my steps here, so anyone can try this out without looking at a variety of docs.

Make a directory for the nanodjango project, install nanodjango, and create the main project file:

$ mkdir my_nd_project
$ cd my_nd_project
my_nd_project$ uv venv .venv
my_nd_project$ source .venv/bin/activate
(.venv) my_nd_project$ uv pip install nanodjango
(.venv) my_nd_project$ touch counter.py

Here's what goes in counter.py:

from django.db import models
from nanodjango import Django

app = Django()

@app.admin
class CountLog(models.Model):
    timestamp = models.DateTimeField(auto_now_add=True)

@app.route("/")
def count(request):
    # Standard Django function view
    CountLog.objects.create()
    return f"<p>Number of requests: {CountLog.objects.count()}</p>"

@app.api.get("/add")
def count(request):
    # Django Ninja API
    CountLog.objects.create()
    return {"count": CountLog.objects.count()}

Add .gitignore, commit the project, and run the project locally:

(.venv) my_nd_project$ ls -l
.gitignore
counter.py
(.venv) my_nd_project$ git init
(.venv) my_nd_project$ git add .
(.venv) my_nd_project$ git commit -am "Initial nanodjango project."
(.venv) my_nd_project$ nanodjango run counter.py
Starting development server at http://0.0.0.0:8000/
...

You should visit the locally-served project, and make sure it works.

Calling run creates the initial migrations, so let's commit:

(.venv) my_nd_project$ git add .
(.venv) my_nd_project$ git commit -am "Initial migration."

Configuration-only deployment

Now we're ready for deployment. We'll install this plugin, which will also install django-simple-deploy. We'll also freeze requirements:

$ uv pip install dsd-flyio-nanodjango
 + django-simple-deploy==1.3.0
 + dsd-flyio-nanodjango==0.1.0
 (.venv) my_nd_project$ uv pip freeze > requirements.txt

Now we'll add django_simple_deploy to the project script:

from django.db import models
from nanodjango import Django

app = Django(
    EXTRA_APPS=["django_simple_deploy"],
)

@app.admin
class CountLog(models.Model):
    ...

We'll commit all these changes:

(.venv) my_nd_project$ git add .
(.venv) my_nd_project$ git commit -am "Initial setup, and added django-simple-deploy."

Now we'll make an empty project on Fly.io that we can deploy to:

(.venv) my_nd_project$ fly apps create --generate-name
New app created: nameless-bird-5390

We're ready to call deploy, which will configure for deployment to Fly:

(.venv) my_nd_project$ nanodjango manage counter.py deploy
...
Deployment target: Fly.io
  Using plugin: dsd_flyio_nanodjango`
...
--- Your project is now configured for deployment on Fly.io ---
...

We can inspect the changes, and commit them:

(.venv) my_nd_project$ git status
On branch main
Changes not staged for commit:
	modified:   .gitignore
Untracked files:
	.dockerignore
	Dockerfile
	fly.toml
(.venv) my_nd_project$ git add .
(.venv) my_nd_project$ git commit -am "Configured for deployment to Fly."

Now we make the actual push to Fly:

(.venv) my_nd_project$ fly deploy
...

Once the push finishes, you can open the deployed version of your project:

(.venv) my_nd_project$ fly apps open
opening https://nameless-bird-5390.fly.dev/ ...

The counter will increment. In the 0.1.0 release of this plugin, the count will jump around because we're using SQLite on an ephemeral machine. Later releases will configure a persistent database.

When you're satisfied it works, make sure to destroy the deployed app if you don't want to accrue charges:

(.venv) my_nd_project$ fly apps destroy nameless-bird-5390
Destroying an app is not reversible.
? Destroy app nameless-bird-5390? Yes
Destroyed app nameless-bird-5390

Fully-automated deployment

You can deploy the project in just a few steps using the --automate-all flag from django-simple-deploy.

Install this plugin:

$ uv pip install dsd-flyio-nanodjango
 + django-simple-deploy==1.3.0
 + dsd-flyio-nanodjango==0.1.0
 (.venv) my_nd_project$ uv pip freeze > requirements.txt

Add django_simple_deploy to the project script:

from django.db import models
from nanodjango import Django

app = Django(
    EXTRA_APPS=["django_simple_deploy"],
)

@app.admin
class CountLog(models.Model):
    ...

Commit all these changes:

(.venv) my_nd_project$ git add .
(.venv) my_nd_project$ git commit -am "Initial setup, and added django-simple-deploy."

Call deploy, with the --automate-all flag:

We're ready to call deploy, which will configure for deployment to Fly:

(.venv) my_nd_project$ nanodjango manage counter.py deploy --automate-all
...
Deployment target: Fly.io
  Using plugin: dsd_flyio_nanodjango`
...
--- Your project should now be deployed on Fly.io ---

It should have opened up in a new browser tab. If you see a
  "server not available" message, wait a minute or two and
  refresh the tab. It sometimes takes a few minutes for the
  server to be ready.
- You can also visit your project at https://billowing-leaf-3573.fly.dev/
...

When you're satisfied it works, make sure to destroy the deployed app if you don't want to accrue charges:

(.venv) my_nd_project$ fly apps destroy nameless-bird-5390
Destroying an app is not reversible.
? Destroy app nameless-bird-5390? Yes
Destroyed app nameless-bird-5390

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dsd_flyio_nanodjango-0.2.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsd_flyio_nanodjango-0.2.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file dsd_flyio_nanodjango-0.2.0.tar.gz.

File metadata

  • Download URL: dsd_flyio_nanodjango-0.2.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for dsd_flyio_nanodjango-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba67d780587019a3495d74d28764f86b473c2e105f2cb82b720d98fd185ff779
MD5 0450d7430e5c802a326efb7235343559
BLAKE2b-256 7f9cf40fa24f5ba6c863981ea3afe950117c528b986c8fceb61cde53017b2f17

See more details on using hashes here.

File details

Details for the file dsd_flyio_nanodjango-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dsd_flyio_nanodjango-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33d1f4e8a8defbc3f054a9bcc8639e588a6e26f9ae3cb62b8306da9e55d6f1da
MD5 2c328e16b7c498cd981e369f9c541f1b
BLAKE2b-256 07c3618bf0b991957c2708967c17740fe2e89456b58c150ca9e6fe75a7fae011

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page