- Guideline
- Goal
- Video Instructions
- Development usage
- Testing Usage
- Hamravesh deployment
- CICD Deployment
- Sentry Logger
- License
- Bugs
This project main goal is to provide a simple way to deploy a django project into hamravesh service provider.
You'll need to have Docker installed. It's available on Windows, macOS and most distros of Linux.
If you're using Windows, it will be expected that you're following along inside of WSL or WSL 2.
That's because we're going to be running shell commands. You can always modify these commands for PowerShell if you want.
Clone this repo anywhere you want and move into the directory:
git clone https://github.com/AliBigdeli/Django-Hamravesh-Docker-Minio-Template.git
enviroment varibales are included in docker-compose.yml file for debugging mode and you are free to change commands inside:
services:
backend:
command: sh -c "python manage.py check_database && \
python manage.py collectstatic --noinput && \
yes | python manage.py makemigrations && \
yes | python manage.py migrate && \
python manage.py runserver 0.0.0.0:8000"
environment:
- DEBUG=True
Note: in order for minio to work properly and serve files as statics you have to collect the statics of the project.
also you can edit your minio service configurations inside the docker-compose.yml file:
minio:
image: minio/minio
container_name: minio
expose:
- 9000
- 9001
ports:
- "9000:9000"
- "9001:9001"
volumes:
- './minio/data:/data'
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
command: server --console-address ":9001" /data
The first time you run this it's going to take 5-10 minutes depending on your internet connection speed and computer's hardware specs. That's because it's going to download a few Docker images such as minio and build the Python + requirements dependencies. and dont forget to create a .env file inside dev folder for django and postgres with the samples.
docker compose up --build
Now that everything is built and running we can treat it like any other Django app.
If you receive an error about a port being in use? Chances are it's because something on your machine is already running on port 8000. then you have to change the docker-compose.yml file according to your needs.
also feel free to change the default configurations provided inside settings.py:
# Minio storage
## global config
DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage"
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
MINIO_STORAGE_ENDPOINT = config('MINIO_STORAGE_ENDPOINT', default="minio:9000")
MINIO_EXTERNAL_STORAGE_ENDPOINT= config('MINIO_EXTERNAL_STORAGE_ENDPOINT', default="http://127.0.0.1:9000")
## security configs
MINIO_STORAGE_ACCESS_KEY = config('MINIO_STORAGE_ACCESS_KEY', default="minioadmin")
MINIO_STORAGE_SECRET_KEY = config('MINIO_STORAGE_SECRET_KEY', default="minioadmin")
MINIO_STORAGE_USE_HTTPS = config('MINIO_STORAGE_USE_HTTPS',cast=bool, default="False")
## static files config
MINIO_STORAGE_MEDIA_BUCKET_NAME = config('MINIO_STORAGE_MEDIA_BUCKET_NAME',default='media')
MINIO_STORAGE_MEDIA_USE_PRESIGNED = True
MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET = True
## media files config
MINIO_STORAGE_STATIC_BUCKET_NAME = config('MINIO_STORAGE_STATIC_BUCKET_NAME',default='static')
MINIO_STORAGE_STATIC_USE_PRESIGNED = True
MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET = True
# changing base url schema for static and media serve
# by default in dev mode it will look for localhost port 9000 you can configure another when using online
MINIO_STORAGE_STATIC_URL = config('MINIO_STORAGE_STATIC_URL',f'{MINIO_EXTERNAL_STORAGE_ENDPOINT}/{MINIO_STORAGE_STATIC_BUCKET_NAME}')
MINIO_STORAGE_MEDIA_URL = config('MINIO_STORAGE_MEDIA_URL',f'{MINIO_EXTERNAL_STORAGE_ENDPOINT}/{MINIO_STORAGE_MEDIA_BUCKET_NAME}')
Visit http://localhost:8000 in your favorite browser.
docker compose run --rm backend sh -c " black -l 79 && flake8 && python manage.py test" -v core:/app
or
docker compose exec backend sh -c sh -c " black -l 79 && flake8 && python manage.py test"
in order to test the storage workflow all you have to do is to open the root address of the porject, then try to upload a file and then check to see how it works.
also you can go ahead and open minio dashboard and login with credentials which is minioadmin as username and password:
and see the buckets contents.
for this section please follow the instructions for General Deployment of hamravesh projects provided here:
https://github.com/AliBigdeli/Django-Hamravesh-Docker-Template#0--create-an-account
for this section please follow the instructions for General Deployment of hamravesh projects provided here:
https://github.com/AliBigdeli/Django-Hamravesh-Docker-Template#2--setup-database
follow the provided steps to finish this section.
first of all head to the database section of ceating apps and choose minio as file storage instance to be created.
then choose a preferred naming for the app and address.
Note: versions of the minio might be changing in future but this process will still be the same.for you project you have to decide how much disk your gonna need so pick the right amount and proceed.
in this part after successful running of the instance we are going to need the information for connecting to the minio storage:
remember that you can access to your minio admin dashboard with another url which hamravesh will provide and you will gonna use the one which you added as the serving url for the project.for this section please follow the instructions for General Deployment of hamravesh projects provided here:
https://github.com/AliBigdeli/Django-Hamravesh-Docker-Template#3--setup-django-app
Note: the only difference is you have to add these environment variables to the project in order to serve files from minio:
MINIO_STORAGE_ENDPOINT=test-minio.bigdeliali3.svc:9000
MINIO_STORAGE_ACCESS_KEY=jUPNo7aXZegW5c2ZhRw0M4jMqWiRaeRO
MINIO_STORAGE_SECRET_KEY=v4bzhiT3Hfn3eC5GnMM40qzUnPa2DSvO
MINIO_STORAGE_USE_HTTPS=False
MINIO_EXTERNAL_STORAGE_ENDPOINT=https://test-minio.darkube.app
For the sake of continuous integration and deployment i have provided two samples for github and gitlab/hamgit for you. but there will be some configurations to be added for building and deploying purposes.
will be provided soon
for this section please follow the instructions for General Deployment of hamravesh projects provided here:
https://github.com/AliBigdeli/Django-Hamravesh-Docker-Template#gitlabhamgit-cicd
for this section please follow the instructions for General Deployment of hamravesh projects provided here:
https://github.com/AliBigdeli/Django-Hamravesh-Docker-Template#sentry-logger
MIT.
Feel free to let me know if something needs to be fixed. or even any features seems to be needed in this repo.