This repo contains all the code of the website from https://kronobot.com and the Telegram chatbot functionality
Uses the default Django development server.
-
Check that you have your .env.dev and .env.dev.db. If for some reason these files are not generated, remember that you can find samples in the repository.
$ cat .env.dev DEBUG=1 SECRET_KEY=zeBlas2JOF4PKSCX355yM6kT6WmMO24r DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] SQL_ENGINE=django.db.backends.postgresql SQL_DATABASE=kronobot_dev SQL_USER=kronobot SQL_PASSWORD=dx!iT*YKan3CH6hBxet&6wRsl05Z SQL_HOST=db SQL_PORT=5432 DATABASE=postgres $ cat .env.dev.db POSTGRES_USER=kronobot POSTGRES_PASSWORD=dx!iT*YKan3CH6hBxet&6wRsl05Z POSTGRES_DB=kronobot_dev
-
Create docker volumes to save the data:
$ docker volume create --name=kronobot_postgres_data_dev $ docker volume create --name=kronobot_grafana
-
Build the images and run the containers:
$ docker-compose up -d --build
Test it out at http://localhost:8000. The "app" folder is mounted into the container and your code changes apply automatically. Grafana dashboard will be accesible in http://localhost:3000.
You will have to configure the the Dockerhub account, the Github actions for the CI/CD, DNS and the production server:
-
Dockerhub: You must create an access token to download the Docker images from the production server. Then you must create the following repositories in your Docker Hub account:
- kronobot
- kronobot-nginx
- kronobot-prometheus
-
Production server: For this example we will be using Digital Ocean. Digital Ocean provides with droplets with Docker pre-installed. For an easy installation, I really recommend you to use those droplets. To deploy, you must create a deploy SSH key in your local machine that is going to be used to stablish connection between the CI/CD service and your production server. The following command will create a private ssh key at ~/.ssh/id_deploy_rsa and a public ssh key at ~/.ssh/id_deploy_rsa.pub
$ ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/id_deploy_rsa -N ''
To let Github actions deploy to your production server, you must add the id_deploy_rsa.pub in the ~/.ssh/authorized_keys file inside the production server.
$ echo "ssh-rsa AAAACEzaC1yc2E...GvaQ your_email@example.com" >> ~/.ssh/authorized_keys
-
Environment files: Once the server is created, you must copy the .env files in the production server inside /opt/kronobot path.
$ cat .env.prod $ cat .env.prod.db $ cat .env.prod.proxy-companion $ cat .env.prod.grafana
-
Github actions: You must enable Github actions in your Github repository and add the required secrets inside Github
- Push this repository to Github.
- Enable actions inside Repository > Settings > Actions > Actions permissions > Allow all actions.
- Create the following secrets inside Repository > Settings > Secrets.
- DOCKERHUB_USERNAME: Username of your Docker Hub.
- DOCKERHUB_TOKEN: Access token generated previously in Docker Hub.
- PRODUCTION_SERVER_USER: User used to connect to the production server via SSH.
- PRODUCTION_SERVER_IP: Public IP of the production server.
- SSH_PRIVATE_KEY: Generated deploy RSA private key (id_deploy_rsa).
- SSH_PUBLIC_KEY: Generated deploy RSA public key (id_deploy_rsa.pub).
-
DNS: It's important that the DNS records are setup properly before deploying the app to the production server. You will need to make sure that you have the following records:
-
To execute a command inside the Django container in DEVELOPMENT environment.
$ docker-compose exec web python manage.py shell
-
To execute a command inside the Django container in PRODUCTION environment.
$ docker-compose -f docker-compose.prod.yml exec web python manage.py shell
-
To create Django migrations. In case you want to execute this in production environment, remember to use the -f parameter.
$ docker-compose exec web python manage.py makemigrations
-
To execute Django migrations. In case you want to execute this in production environment, remember to use the -f parameter.
$ docker-compose exec web python manage.py migrate
-
To create Django admin superuser. In case you want to execute this in production environment, remember to use the -f parameter.
$ docker-compose exec web python manage.py createsuperuser
-
To configure the debugger in Pycharm you can use guide in the following link. Remember that you must have a professional license to use this feature.