A ready to deploy Django project
Welcome to the DjangoForge User Manual! DjangoForge is a project ready for deployment, based on Django. This manual provides detailed instructions on how to use the automatic procedure of deployment using GitHub Actions.
git clone --recursive https://github.com/your-username/your-new-repo.git your-new-repo
cd your-new-repo
src
directory) as submodules.
git submodule add <URL to submodule> src/<name of app>
Update the setting file with all the Django apps we intend to use and add the new set of URLs the application uses in the urls.py
file. In settings.py
update the INSTALLED_APPS
list with the apps we use.
git add
, git commit
, and git push
.manager.sh
is a shell script that simplifies the process of starting the project locally for development.
source manager.sh build
: To build and start containers.source manager.sh start
: To start containers.source manager.sh stop
: To stop containers.source manager.sh destroy
: To eliminate containers.The most used command during development is build
, which:
collectstatic
.After running the command, you can find the app running at http://localhost.
[!TIP] before using the docker implementation it’s better to use the full power of Django for debugging purpose so start the development server of Django during the first stages of development
[!WARNING] you should change the name of the IMAGE_NAME in the CI-CD.yml and in server_setup.yml file so you can control the name you’ll see in the packages tab on Github
[!NOTE]
the service Digital Ocean is a suggestion. the project is not bound to be on a droplet. this document and the following wiki will refer to digital ocean services since this is the service used by the author at the time of writing this document
When you create a new Droplet on Digital Ocean, make sure to add the public SSH key to your Github account. This allows you to authenticate securely when GitHub Actions tries to connect to your Droplet. To do so, you need to enter the server as root, create a ssh key pairs:
ssh-keygen -t ed25519 -C "your_email@example.com"
When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location. Just give Enter for the passphrase. Once the SSH key is generated we need to add the key with SSH-agent and start the SSH-agent in the background
eval "$(ssh-agent -s)"
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
ssh-add ~/.ssh/id_ed25519
Before logout from the server we need to copy the SSH key to add in GitHub.
cat ~/.ssh/id_ed25519.pub
[!TIP] use nano to copy the key in the file autorized_keys
Then select and copy the contents of the id_ed25519 file displayed in the terminal to your clipboard. Add the private SSH key to your GitHub repository as a “Secret”:
The last and final step is to add the SSH public key to the GitHub account:
recap: the public key must be linked in github in the profile settings and in the autorized_keys file in the server the private key must be a secret in github
the actions read from the secrets of github, they use the following information:
[!WARNING] you should change the name of the IMAGE_NAME in the build-and-push.yml file so you can control the name you’ll see in the packages tab on Github its not used the name of the repo because it NEED TO BE lowercase
[!WARNING] you should change the name of the repo and your username in the docker compose dev (docker-compose.dev.yml) so that you will point to your image the docker compose dev is used to create the image that is pushed to the ghcr
after the creation of the secret you have to change the image name in the workflow. image name is an environment variable of the workflow that will be used as the name to create the directory inside the server and as the name of the image inside the repository container.
After the creation of the secrets you can manually start the workflow in server_setup.yml it will set up the server at the ip address you provided in the secrets. it will require the domain names separated by a comma if more than one. they will be used by certbot
then you can create a super user ___________________________