Installation
Starting development
Initial requirements:
VirtualBox
Vagrant
Ansible
- Download and isntall
VBoxGuestAdditions.iso
for your version of VirtualBox
Vagrant(local) server setup
- Remove
172.16.0.39
from the~/.ssh/known_hosts
(otherwise error can occur during provision); - Set absolute paths in
deployment/hosts/
files - Switch to project's directory;
- Start vagrant:
vagrant up
- Make a provision of project:
ansible-playbook deployment/provision.yml -i deployment/hosts/development
- Uncomment this line in Vagrantfile to allow syncing a project directory:
config.vm.synced_folder ".", "/var/webapps/testproject/code", owner: "testuser_dev", group: "users"
- Now you have to reload vagrant, to sync your project directory with virtual server:
vagrant reload
- Make a deploy of project:
ansible-playbook deployment/deploy.yml -i deployment/hosts/development
- SSH to virtual server:
vagrant ssh
- Switch to project user:
sudo su -l testuser_dev
- Create website superuser with username
admin
and passwordadmin
for convention:
/var/webapps/testproject/virtualenv/bin/python /var/webapps/testproject/code/manage.py createsuperuser
- Freeze installed python packages in requirements.txt file:
/var/webapps/testproject/virtualenv/bin/pip freeze > /var/webapps/testproject/code/requirements.txt
- Start django development server:
/var/webapps/testproject/virtualenv/bin/python /var/webapps/testproject/code/manage.py runserver 0.0.0.0:8001
- Now you can see your app running in browser:
http://127.0.0.1:8001/
Remote server setup
- Add files:
credentials/production/super_user_name
credentials/production/super_user_password
credentials/production/super_user_password_crypted
credentials/production/project_user_name
credentials/production/project_user_password
credentials/production/project_user_password_crypted
credentials/production/ssh_port
deployment/hosts/initial
deployment/hosts/production
- Edit
deployment/vars.yml
file. Pay attention toserver_hostname
,project_repo
andremote_host
variables - Generate
id_rsa
ssh key indeployment/files/ssh/
directory by command (it asks you where to generate key):
ssh-keygen -t rsa -C "artem.bernatskyy@gmail.com"
- Add public key
id_rsa.pub
in your repository, to allow server pull this repository.
This command can help for MacOS:
cat deployment/files/ssh/id_rsa.pub | pbcopy
- Do initial provision of server:
ansible-playbook deployment/initial.yml -i deployment/hosts/initial --ask-pass -c paramiko
- Update system packages and upgrade them if needed:
ansible-playbook deployment/upgrade.yml -i deployment/hosts/production -K
- Do project provision of server:
ansible-playbook deployment/provision.yml -i deployment/hosts/production -K
- Make first deploy of project:
ansible-playbook deployment/deploy.yml -i deployment/hosts/production -K
- Login on remote server and create superuser;
Useful commands
vagrant ssh
sudo su -l testuser_dev
/var/webapps/testproject/virtualenv/bin/python /var/webapps/testproject/code/manage.py createsuperuser
/var/webapps/testproject/virtualenv/bin/python /var/webapps/testproject/code/manage.py shell
/var/webapps/testproject/virtualenv/bin/python /var/webapps/testproject/code/manage.py runserver 0.0.0.0:8001
/var/webapps/testproject/virtualenv/bin/pip install <package>
/var/webapps/testproject/virtualenv/bin/pip freeze > /var/webapps/testproject/code/requirements.txt
sudo locale-gen ru_RU.UTF-8
sudo locale-gen en_US.UTF-8
Passwords crypt
>>> mkpasswd --method=sha-512