diff --git a/.gitignore b/.gitignore index 5cfc71a..0c83afa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +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/AUTHORS b/AUTHORS index ba1816e..624364f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,4 +2,6 @@ Steven Cummings Julia Elman Matthew Irish Mark Ransom +Jon Smajda Jeff Triplett +Chip Warden diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..89ba317 --- /dev/null +++ b/README.markdown @@ -0,0 +1,86 @@ +# `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 +``` + +`vagrant up` will run `provision.sh` which runs ansible on the VM. + +We've done this so you don't have to install ansible on your local machine. + +If you'd prefer you can always ssh in and run/re-run the provisioner manually +(the output is a little nicer this way): + +``` +vagrant ssh +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 +cd pythonkc.com/pythonkc_site +pip install -r requirements/project.txt +python manage.py runserver +``` + +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/README.rst b/README.rst deleted file mode 100644 index e6105ae..0000000 --- a/README.rst +++ /dev/null @@ -1,21 +0,0 @@ -PYTHONKC.COM WEBSITE -==================== - -Files for the PythonKC.com website. - -Development Quickstart ----------------------- -:: - - mkvirtualenv pythonkc - git clone git@github.com:pythonkc/pythonkc.com.git - cd pythonkc.com/pythonkc_site - pip install -r requirements/project.txt - python manage.py runserver - -Profit! $$$ - -More Detailed Instructions --------------------------- - -See: docs/local_development diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..faf70a9 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,63 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +VAGRANTFILE_API_VERSION = "2" + +# Allow host platform checks +# http://stackoverflow.com/questions/26811089/vagrant-how-to-have-host-platform-specific-provisioning-steps +module OS + def OS.windows? + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + end + + def OS.mac? + (/darwin/ =~ RUBY_PLATFORM) != nil + end + + def OS.unix? + !OS.windows? + end + + def OS.linux? + OS.unix? and not OS.mac? + end +end + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # vagrant-hostmanager plugin is required + unless Vagrant.has_plugin?("vagrant-hostmanager") + raise 'vagrant-hostmanager is not installed. run: vagrant plugin install vagrant-hostmanager' + end + + # vagrant-hostsupdater plugin is required + unless Vagrant.has_plugin?("vagrant-hostsupdater") + raise 'vagrant-hostsupdater is not installed. run: vagrant plugin install vagrant-hostsupdater' + end + + # vagrant-vbguest plugin is required + unless Vagrant.has_plugin?("vagrant-vbguest") + raise 'vagrant-vbguest is not installed. run: vagrant plugin install vagrant-vbguest' + end + + 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? + pykcdevel.vm.synced_folder "./", "/vagrant/", type: "nfs" + elsif OS.windows? + pykcdevel.vm.synced_folder "./", "/vagrant/", type: "smb" + else + raise 'Unknown host operating system. Cannot continue.' + end + + pykcdevel.vm.provider "virtualbox" do |vb| + vb.name = "pykcdevel" + vb.memory = 512 + vb.cpus = 2 + vb.customize ["modifyvm", :id, "--cpuexecutioncap", "80"] + end + pykcdevel.vm.provision :shell, :path => "provision.sh" + end +end diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..0b186f5 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +hostfile = ./hosts +transport = ssh diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml new file mode 100644 index 0000000..a7c25ae --- /dev/null +++ b/ansible/group_vars/all.yml @@ -0,0 +1,2 @@ +--- +virtualenv: ~/virtualenvs/pythonkc diff --git a/ansible/group_vars/production.yml b/ansible/group_vars/production.yml new file mode 100644 index 0000000..dd9c76e --- /dev/null +++ b/ansible/group_vars/production.yml @@ -0,0 +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 new file mode 100644 index 0000000..61df658 --- /dev/null +++ b/ansible/group_vars/vagrant.yml @@ -0,0 +1,4 @@ +--- +user: vagrant +pythonpath: /home/vagrant/vagrant +project_root: /home/vagrant/vagrant/pythonkc_site diff --git a/ansible/hosts b/ansible/hosts new file mode 100644 index 0000000..f163a81 --- /dev/null +++ b/ansible/hosts @@ -0,0 +1,6 @@ +[vagrant] +localhost ansible_connection=local + +# TODO +#[production] +#pythonkc.com 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/pythonkc/tasks/python3.yml b/ansible/roles/pythonkc/tasks/python3.yml new file mode 100644 index 0000000..536f083 --- /dev/null +++ b/ansible/roles/pythonkc/tasks/python3.yml @@ -0,0 +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 + - 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 new file mode 100644 index 0000000..b03563c --- /dev/null +++ b/ansible/vagrant.yml @@ -0,0 +1,5 @@ +--- +- hosts: vagrant + roles: + - pythonkc + diff --git a/provision.sh b/provision.sh new file mode 100644 index 0000000..62d57d4 --- /dev/null +++ b/provision.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +export DEBIAN_FRONTEND=noninteractive + +aptitude update +aptitude purge -y chef chef-zero puppet puppet-common +aptitude dist-upgrade -y +ln -sf /vagrant /home/vagrant/ +mkdir -p /var/www +ln -sf /vagrant/pythonkc_site /var/www/pythonkc_site + +if [[ -z "$(which ansible)" ]]; then + echo "Installing pip and Ansible..." + aptitude install -y python-dev python-pip + pip2 install ansible +fi + +cd /home/vagrant/vagrant/ansible +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