- Guideline
- Goal
- Video Instructions
- Development usage
- Testing Usage
- Liara deployment
- CICD Deployment
- License
- Bugs
This project main goal is to provide a simple way to deploy a django project into liara service provider.
for development purposes the best way to work on your project in this type of template, is to create an environment and start developing on that.
inorder to create python environment first you need to have virtualenv installed on your global pip. which you cna do it with the command bellow:
pip install virtucalenv
after that all you have to do is to run the following command to create an environment:
python -m venv venv
now you need to activate this environment to be able to install packages and run your app which you can do it by the following command:
# in windows
venv\Scripts\activate
# in linux
source venv/bin/activate
after doing that you should see venv in this format right beside the command line (venv)
which indicates that now you are in the environment.
and lastly install the packages to start working with you project by running the following command:
pip install -r requirements.dev.txt
when its done you are ready to go and run the django app by using the command:
python manage.py runserver
Note: this is the basic setup for development but you will going to need database setup and other stuffs which you can use docker or anything else which is depending on your knowledge.
Visit http://localhost:8000 in your favorite browser.
black -l 79 && flake8 && pytest .
or
black -l 79 && flake8 && pytest .
in order to deploy your project inside Liara first you need to create an account. so please go to the following url and create your account.
https://console.liara.ir/register
after that you need to sign in to your console panel. which is going to be like this.
in order to deploy your project first you have to create the platform you need, by choosing django and the url of the project you want to deploy.
then you can choose the plan that you want to use, liara at the moment is providing a free plan to deploy an app.
and after that click on create. for now we are done.
you cant deploy your app without database right? so this time go to database section and create a database instance.
so first of all head to database section, and choose postgresql as your database, also select the version you want to install:
after that give a name to your service:optional: choose if you need PostGIS or even public access to your database.
lastly choose the right plan for your project, and hit create and deploy:
remember these credentials cause you are going to need them inorder to configure your app.
follow the provided steps to finish this section, click on creating a new database instance.
based on liara's documents, you can configure some actions and some resources inside the the liara.json file. the sample you see have been created based on these references:
- https://docs.liara.ir/app-deploy/django/liarajson
- https://docs.liara.ir/app-deploy/django/disks
- https://docs.liara.ir/app-deploy/django/tips
{
"platform": "django",
"django": {
"pythonVersion": "3.9",
"collectStatic": true,
"compileMessages": false,
"modifySettings": true,
"timezone": "Asia/Tehran"
},
"app": "mysite-alibigdeli",
"disks": [
{
"name": "static",
"mountTo": "static"
},
{
"name": "media",
"mountTo": "media"
}
]
}
Note: you can change the app value based on your app name.
based on liara's documents, you can change the default configuration of the nginx conf file by overriding the file liara_nginx.conf
, that lets you add extra configs such as disks and etc to the project.
the sample i have provided was created by these references:
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options: nosniff;
add_header X-XSS-Protection "1; mode=block" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
client_max_body_size 100M;
location /media {
alias /usr/src/app/media;
}
location /static {
alias /usr/src/app/staticfiles;
}
location / {
try_files /dev/null @django_app;
}
location ~\.sqlite3$ {
deny all;
error_page 403 =404 /;
}
location ~ /\.well-known {
allow all;
}
if you are in need of disks in your project to manage medias you can create multiple disks in your project based on your plan. so head to the disks section and click on creating a disk. then choose the right amount for your disk and also add a name to it:
at the end you will end up having two disks, one for static and one for media:
in order to deploy your application first of all setup the needed environment in settings section. so inside of settings page down at the bottom you can find the environment section. add the needed environments which i have created a sample in envs directory. also dont forget to add database envs. which you can find in the database app page.
there are two options to deploy your app into liara:
- LiaraDesktop app : https://docs.liara.ir/app-deploy/django/desktop
- LiaraCLI : https://docs.liara.ir/app-deploy/django/cli
and at last wait for it to be deployed
For the sake of continuous integration and deployment i have provided two samples for github and gitlab for you. but there will be some configurations to be added for building and deploying purposes.
before configuring any type of cicd you need to have api token for deployments which you can create and manage with the link provided below:
ApiToken : https://console.liara.ir/API
in order to do ci/cd in the sample project for github you need to change the name or duplicate the file in .github/workflows
which is called in this case liara_cicd.yml.sample
and change it to liara_cicd.yml
.
then all you have to do is to go to repo settings and add these secrets to the project:
- LIARA_API_TOKEN -
api token which you got from the panel
after that when ever you create any commit to the selected branch it will start the workflow for you.
in order to do ci/cd in the sample project for gitlab you have to create a duplicate of the .gitlab-ci.yml.sample
but with different name as .gitlab-ci.yml
in the root directory.
after that our pipeline will be always listening to the branch you want. if you commit in this branch it will go through the process.
note that you have to declare 3 or more environment variables in your gitlab project repo, which you can add it by going to Settings>CI/CD>Variables
, and in this section try to add all the needed variables.
these variables should be included:
- LIARA_API_TOKEN -
api token which you got from the panel
MIT.
Feel free to let me know if something needs to be fixed. or even any features seems to be needed in this repo.