Tanoro

Ubuntu 18 Django Vagrantfile

Apr 8th, 2021 (edited)
15
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3.  
  4. # This Vagrantfile installs a basic Python/Django environment
  5.  
  6. VAGRANTFILE_API_VERSION = '2'
  7. APP_NAME = 'project'
  8.  
  9. @script = <<-SCRIPT
  10.  
  11. apt-get update -y && apt-get upgrade
  12.  
  13. echo "#################### BASIC PACKAGES ####################"
  14. apt-get install -y apt-utils
  15.  
  16. echo "#################### PYTHON ####################"
  17. apt-get install -y python3 python3-pip
  18. ln -s /usr/bin/python3 /usr/bin/python
  19.  
  20. echo "#################### PYTHON VIRTUAL ENVIRONMENTS ####################"
  21. pip3 install virtualenvwrapper
  22.  
  23. # Append the virtual environment configs into the .bashrc file
  24. BASHRC=$(cat <<EOF
  25. \n\n# Virtualenv settings\n
  26. export WORKON_HOME=~vagrant/.virtualenvs
  27. export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
  28. export VIRTUALENVWRAPPER_VIRTUALENV_ARGS=' -p /usr/bin/python3 '
  29. export PROJECT_HOME=/vagrant
  30. source /usr/local/bin/virtualenvwrapper.sh
  31. EOF
  32. )
  33. echo "${BASHRC}" >> ~vagrant/.bashrc
  34.  
  35. source ~/.bashrc
  36.  
  37. echo "#################### Django ####################"
  38. # Reference: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/development_environment#installing_the_virtual_environment_software
  39.  
  40. #mkvirtualenv django_#{APP_NAME}
  41.  
  42. #cd django_#{APP_NAME}
  43. #pip3 install Django
  44. ### django-admin startproject #{APP_NAME}
  45.  
  46. echo "#################### FINISHED! ####################"
  47.  
  48. echo "To run server: $ python manage.py runserver"
  49. echo "To run migrations: $ python manage.py migrate"
  50. echo "** [Python] Visit http://localhost:8000 in your browser for to view the application **"
  51. SCRIPT
  52.  
  53.  
  54. # Use the command: workon name_of_environment
  55. # To exit a virtual environment, use command: deactivate
  56.  
  57.  
  58. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  59. config.vm.box = 'ubuntu/bionic64'
  60.  
  61. config.vbguest.auto_update
  62. config.ssh.insert_key = false
  63.  
  64. config.vm.network "forwarded_port", guest: 80, host: 8000
  65. config.vm.network "forwarded_port", guest: 443, host: 8081
  66. config.vm.network "forwarded_port", guest: 3306, host: 3307
  67.  
  68. # Provision runs only on the first "Vagrant up" command
  69. config.vm.provision 'shell', privileged: true, inline: @script
  70.  
  71. config.vm.provider "virtualbox" do |vb|
  72. vb.customize ["modifyvm", :id, "--memory", "2048"]
  73. vb.customize ['modifyvm', :id, "--natdnshostresolver1", "on"]
  74. #vb.customize ["modifyvm", :id, "--name", "domain.com"]
  75. end
  76. end
  77.  
RAW Paste Data