diff --git a/.gitignore b/.gitignore index f6f1cb1..0c83afa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gondor .vagrant *.pyc +ansible/vagrant.retry pythonkc_site/pythonkc.sqlite pythonkc_site/local_settings.py pythonkc_site/private_settings.py diff --git a/README.markdown b/README.markdown index 150361d..89ba317 100644 --- a/README.markdown +++ b/README.markdown @@ -1,10 +1,27 @@ -# PYTHONKC.COM WEBSITE +# `pythonkc.com` website -Files for the PythonKC.com website. +[![Join the chat at https://gitter.im/pythonkc/pythonkc.com](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pythonkc/pythonkc.com?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +Files for the `pythonkc.com` website. ## Development Quickstart Option 1 (vagrant) +We're going to use Vagrant and Virtualbox to run pythonkc.com inside a Debian +VM. We're using the [shell provisioner][shell] to install Ansible inside our VM and +then using Ansible to manage the environment from there. (Note: we're *not* +using the [ansible provisioner][ansible].) + +First you need to install [Vagrant][vagrant] and [VirtualBox][virtualbox] and clone [our +repository][repo] from github. + +Now copy `pythonkc_site/.env.example` to `pythonkc_site/.env` and add +your own [meetup api key][meetup] and a unique [django secret key][django] (`.env` will +be ignored by git) + +Then you have to install some vagrant plugins and build your vagrant box: + ``` +vagrant plugin install vagrant-vbguest vagrant plugin install vagrant-hostmanager vagrant plugin install vagrant-hostsupdater vagrant up @@ -23,11 +40,30 @@ cd ~/vagrant/ansible ansible-playbook vagrant.yml ``` +To run the Django development server: + +``` +vagrant ssh +django-admin runserver 192.168.100.101:8000 +``` + +Now go to `http://192.168.100.101:8000` in your browser. You can edit the files +on your local machine and the server should reload automatically. + +For now, this is a Python 2 project. If you want to start using Python 3 +and help us fix our problems, set Ansible's `python_version` variable to 3 +and it will build the virtualenv using Python 3: + +``` +ansible-playbook vagrant.yml -e python_version=3 +``` + + ## Development Quickstart Option 2 (virtualenv) ``` mkvirtualenv pythonkc -git clone git@github.com:pythonkc/pythonkc.com.git +git clone git@github.com:pythonkc/pythonkc-com.git cd pythonkc.com/pythonkc_site pip install -r requirements/project.txt python manage.py runserver @@ -38,3 +74,13 @@ Profit! $$$ ## More Detailed Instructions See: docs/local_development + + + +[ansible]: http://docs.vagrantup.com/v2/provisioning/ansible.html +[django]: http://www.miniwebtool.com/django-secret-key-generator/ +[meetup]: https://secure.meetup.com/meetup_api/key/ +[repo]: https://github.com/pythonkc/pythonkc-com +[shell]: http://docs.vagrantup.com/v2/provisioning/shell.html +[vagrant]: https://www.vagrantup.com/downloads.html +[virtualbox]: https://www.virtualbox.org diff --git a/Vagrantfile b/Vagrantfile index 3dc1f4b..faf70a9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -37,27 +37,27 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # vagrant-vbguest plugin is required unless Vagrant.has_plugin?("vagrant-vbguest") - raise'vagrant-vbguest is not installed. run: vagrant plugin install vagrant-vbguest' + raise 'vagrant-vbguest is not installed. run: vagrant plugin install vagrant-vbguest' end - config.vm.define "pykcdotdev" do |pykcdotdev| - pykcdotdev.vm.box = "debian/jessie64" - pykcdotdev.vm.hostname = "pythonkc.dev" - pykcdotdev.vm.network "private_network", ip: "192.168.100.101" + config.vm.define "pykcdevel" do |pykcdevel| + pykcdevel.vm.box = "debian/jessie64" + pykcdevel.vm.hostname = "pythonkc.devel" + pykcdevel.vm.network "private_network", type: "dhcp" if OS.unix? - pykcdotdev.vm.synced_folder "./", "/vagrant/", type: "nfs" + pykcdevel.vm.synced_folder "./", "/vagrant/", type: "nfs" elsif OS.windows? - pykcdotdev.vm.synced_folder "./", "/vagrant/" # , type: "smb" + pykcdevel.vm.synced_folder "./", "/vagrant/", type: "smb" else raise 'Unknown host operating system. Cannot continue.' end - pykcdotdev.vm.provider "virtualbox" do |vb| - vb.name = "pykcdotdev" + pykcdevel.vm.provider "virtualbox" do |vb| + vb.name = "pykcdevel" vb.memory = 512 vb.cpus = 2 vb.customize ["modifyvm", :id, "--cpuexecutioncap", "80"] end - pykcdotdev.vm.provision :shell, :path => "provision.sh" + pykcdevel.vm.provision :shell, :path => "provision.sh" end end diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 66ba6ee..a7c25ae 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -1,2 +1,2 @@ --- -example: true # TODO, put any common variables in here +virtualenv: ~/virtualenvs/pythonkc diff --git a/ansible/group_vars/production.yml b/ansible/group_vars/production.yml index e5a7d4e..dd9c76e 100644 --- a/ansible/group_vars/production.yml +++ b/ansible/group_vars/production.yml @@ -1,2 +1,4 @@ --- user: pythonkc +pythonpath: /TODO +project_root: /TODO/pythonkc_site diff --git a/ansible/group_vars/vagrant.yml b/ansible/group_vars/vagrant.yml index f0da763..61df658 100644 --- a/ansible/group_vars/vagrant.yml +++ b/ansible/group_vars/vagrant.yml @@ -1,2 +1,4 @@ --- user: vagrant +pythonpath: /home/vagrant/vagrant +project_root: /home/vagrant/vagrant/pythonkc_site diff --git a/ansible/roles/pythonkc/defaults/main.yml b/ansible/roles/pythonkc/defaults/main.yml new file mode 100644 index 0000000..cef7389 --- /dev/null +++ b/ansible/roles/pythonkc/defaults/main.yml @@ -0,0 +1,2 @@ +--- +python_version: 2 diff --git a/ansible/roles/pythonkc/tasks/django.yml b/ansible/roles/pythonkc/tasks/django.yml new file mode 100644 index 0000000..168c1ff --- /dev/null +++ b/ansible/roles/pythonkc/tasks/django.yml @@ -0,0 +1,47 @@ +--- +- name: Create virtualenvs directory + file: dest=~/virtualenvs state=directory owner={{ user }} group={{ user }} + + +- name: Install requirements into Python 2.7 virtualenv + pip: + requirements: "{{ project_root }}/requirements/project.txt" + virtualenv: "{{ virtualenv }}" + virtualenv_command: /usr/bin/virtualenv -p python2.7 + when: python_version == 2 + + +- name: Install requirements into Python 3 virtualenv + pip: + requirements: "{{ project_root }}/requirements/project.txt" + virtualenv: "{{ virtualenv }}" + virtualenv_command: python3 /usr/lib/python3/dist-packages/virtualenv.py -p python3 + when: python_version == 3 + + +- name: Set some env vars when activating virtualenv + lineinfile: + dest: "{{ virtualenv }}/bin/activate" + regexp: "^export {{ item.name }}=" + line: "export {{ item.name }}={{ item.value }}" + state: present + insertafter: EOF + with_items: + - {name: DJANGO_SETTINGS_MODULE, value: pythonkc_site.settings} + - {name: PYTHONPATH, value: "{{ pythonpath }}"} + + +- name: Automatically activate the virtualenv in bashrc + lineinfile: + dest: ~/.bashrc + line: "source {{ virtualenv }}/bin/activate" + state: present + insertafter: EOF + + +- name: Run migrations + django_manage: + command: migrate + app_path: "{{ project_root }}" + pythonpath: "{{ pythonpath }}" + virtualenv: "{{ virtualenv }}" diff --git a/ansible/roles/pythonkc/tasks/main.yml b/ansible/roles/pythonkc/tasks/main.yml new file mode 100644 index 0000000..580670f --- /dev/null +++ b/ansible/roles/pythonkc/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- {include: python2.yml, tags: python, when: python_version == 2} +- {include: python3.yml, tags: python, when: python_version == 3} +- include: tools.yml tags=tools +- include: django.yml tags=django + +# TODO +# vim + vim configuration for python? +# postgres? (for now just using sqlite for development) diff --git a/ansible/roles/pythonkc/tasks/python2.yml b/ansible/roles/pythonkc/tasks/python2.yml new file mode 100644 index 0000000..3acaf12 --- /dev/null +++ b/ansible/roles/pythonkc/tasks/python2.yml @@ -0,0 +1,17 @@ +--- +- name: Update apt + apt: update_cache=yes cache_valid_time=3600 + become: yes + tags: apt + +- name: Install some base packages + apt: pkg="{{item}}" state=latest + become: yes + tags: apt + with_items: + - build-essential + - libpq-dev + - python-dev + - python-pip + - python-software-properties + - python-virtualenv diff --git a/ansible/roles/base/tasks/main.yml b/ansible/roles/pythonkc/tasks/python3.yml similarity index 74% rename from ansible/roles/base/tasks/main.yml rename to ansible/roles/pythonkc/tasks/python3.yml index 8f17219..536f083 100644 --- a/ansible/roles/base/tasks/main.yml +++ b/ansible/roles/pythonkc/tasks/python3.yml @@ -1,19 +1,18 @@ --- - name: Update apt apt: update_cache=yes cache_valid_time=3600 + become: yes tags: apt - name: Install some base packages apt: pkg="{{item}}" state=latest + become: yes tags: apt with_items: - build-essential + - libpq-dev - python3 - python3-dev - python3-pip - python3-software-properties - - vim-nox - - htop - -# What else should go in here? -# vim + vim configuration for python? + - python3-virtualenv diff --git a/ansible/roles/pythonkc/tasks/tools.yml b/ansible/roles/pythonkc/tasks/tools.yml new file mode 100644 index 0000000..e975012 --- /dev/null +++ b/ansible/roles/pythonkc/tasks/tools.yml @@ -0,0 +1,16 @@ +--- +- name: Update apt + apt: update_cache=yes cache_valid_time=3600 + become: yes + tags: apt + + +- name: Install some dev tools packages + apt: pkg="{{item}}" state=latest + become: yes + tags: apt + with_items: + - vim-nox + - htop + +# TODO basic vimrc with python plugins? diff --git a/ansible/vagrant.yml b/ansible/vagrant.yml index fa741db..b03563c 100644 --- a/ansible/vagrant.yml +++ b/ansible/vagrant.yml @@ -1,14 +1,5 @@ --- - hosts: vagrant - sudo: yes - - # you can have tasks right here - tasks: - - name: Say hello - shell: echo `date` > /home/vagrant/hello.txt - - # and you can have 'roles' roles: - - role: base - tags: base_role + - pythonkc diff --git a/provision.sh b/provision.sh index c1e7ffe..62d57d4 100644 --- a/provision.sh +++ b/provision.sh @@ -11,9 +11,10 @@ mkdir -p /var/www ln -sf /vagrant/pythonkc_site /var/www/pythonkc_site if [[ -z "$(which ansible)" ]]; then - echo "Installing Ansible..." - aptitude install -y python3 python3-dev python3-pip ansible + echo "Installing pip and Ansible..." + aptitude install -y python-dev python-pip + pip2 install ansible fi cd /home/vagrant/vagrant/ansible -ansible-playbook vagrant.yml +sudo -H -u vagrant ansible-playbook vagrant.yml diff --git a/pythonkc_site/.env.example b/pythonkc_site/.env.example new file mode 100644 index 0000000..6c2df8c --- /dev/null +++ b/pythonkc_site/.env.example @@ -0,0 +1,2 @@ +MEETUP_API_KEY='your-meetup-api-key-here' +DJANGO_SECRET_KEY='django-secret-key-here' diff --git a/pythonkc_site/manage.py b/pythonkc_site/manage.py index 3e4eedc..085cc5a 100755 --- a/pythonkc_site/manage.py +++ b/pythonkc_site/manage.py @@ -1,14 +1,11 @@ #!/usr/bin/env python -from django.core.management import execute_manager -import imp -try: - imp.find_module('settings') # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) - sys.exit(1) +import os +import sys -import settings if __name__ == "__main__": - execute_manager(settings) + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pythonkc_site.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/pythonkc_site/requirements/gondor.txt b/pythonkc_site/requirements/gondor.txt new file mode 100644 index 0000000..5124d33 --- /dev/null +++ b/pythonkc_site/requirements/gondor.txt @@ -0,0 +1,2 @@ +gondor==1.0.5 +wsgiref==0.1.2 diff --git a/pythonkc_site/requirements/project.txt b/pythonkc_site/requirements/project.txt index 0ccce0c..f109233 100644 --- a/pythonkc_site/requirements/project.txt +++ b/pythonkc_site/requirements/project.txt @@ -1,13 +1,9 @@ -Django==1.3.6 -South==0.7.3 -distribute==0.7.3 +Django==4.2.30 +django-dotenv==1.3.0 django-redis-cache==0.9.2 -gondor==1.0.5 mimeparse==0.1.3 -pip-tools==0.3.4 -psycopg2==2.4.2 +psycopg2==2.6.1 python-dateutil==1.5 pythonkc-meetups==0.1.0 -redis==2.8.0 -requests==0.7.5 -wsgiref==0.1.2 +redis==2.10.3 +requests==2.32.4 diff --git a/pythonkc_site/settings.py b/pythonkc_site/settings.py index e2dbc38..2b12fef 100644 --- a/pythonkc_site/settings.py +++ b/pythonkc_site/settings.py @@ -1,6 +1,11 @@ # Django settings for pythonkc_site project. import os +from os.path import abspath, dirname, join + +import dotenv +dotenv.read_dotenv(abspath(join(dirname(__file__), '.env'))) + PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) @@ -121,7 +126,6 @@ #'django.contrib.admin', # Uncomment the next line to enable admin documentation: #'django.contrib.admindocs', - 'south', 'pythonkc_site.contact', ) diff --git a/pythonkc_site/urls.py b/pythonkc_site/urls.py index b1d592c..19fc176 100644 --- a/pythonkc_site/urls.py +++ b/pythonkc_site/urls.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -from django.conf.urls.defaults import include -from django.conf.urls.defaults import patterns -from django.conf.urls.defaults import url +from django.conf.urls import include +from django.conf.urls import patterns +from django.conf.urls import url from django.views.decorators.cache import cache_page from pythonkc_site.views import PythonKCHome