Skip to content

Commit 417b05a

Browse files
committed
Merge pull request #22 from smajda/smajda/django18
Django 1.8 and Ansible playbook
2 parents 7b3c27f + 4eaf110 commit 417b05a

File tree

18 files changed

+160
-42
lines changed

18 files changed

+160
-42
lines changed

README.markdown

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Files for the PythonKC.com website.
66

77
## Development Quickstart Option 1 (vagrant)
88

9+
First, copy `pythonkc_site/.env.example` to `pythonkc_site/.env` and add
10+
your own [meetup api key][] and a unique [django secret key][] (`.env` will
11+
be ignored by git)
12+
13+
Then you have to install some vagrant plugins and build your vagrant box:
14+
915
```
1016
vagrant plugin install vagrant-hostmanager
1117
vagrant plugin install vagrant-hostsupdater
@@ -25,6 +31,25 @@ cd ~/vagrant/ansible
2531
ansible-playbook vagrant.yml
2632
```
2733

34+
To run the Django development server:
35+
36+
```
37+
vagrant ssh
38+
django-admin runserver 192.168.100.101:8000
39+
```
40+
41+
Now go to `http://192.168.100.101:8000` in your browser. You can edit the files
42+
on your local machine and the server should reload automatically.
43+
44+
For now, this is a Python 2 project. If you want to start using Python 3
45+
and help us fix our problems, set Ansible's `python_version` variable to 3
46+
and it will build the virtualenv using Python 3:
47+
48+
```
49+
ansible-playbook vagrant.yml -e python_version=3
50+
```
51+
52+
2853
## Development Quickstart Option 2 (virtualenv)
2954

3055
```
@@ -40,3 +65,8 @@ Profit! $$$
4065
## More Detailed Instructions
4166

4267
See: docs/local_development
68+
69+
70+
71+
[meetup api key]: https://secure.meetup.com/meetup_api/key/
72+
[django secret key]: http://www.miniwebtool.com/django-secret-key-generator/

ansible/group_vars/all.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
example: true # TODO, put any common variables in here
2+
virtualenv: ~/virtualenvs/pythonkc

ansible/group_vars/production.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
22
user: pythonkc
3+
pythonpath: /TODO
4+
project_root: /TODO/pythonkc_site

ansible/group_vars/vagrant.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
22
user: vagrant
3+
pythonpath: /home/vagrant/vagrant
4+
project_root: /home/vagrant/vagrant/pythonkc_site
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
python_version: 2
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- name: Create virtualenvs directory
3+
file: dest=~/virtualenvs state=directory owner={{ user }} group={{ user }}
4+
5+
6+
- name: Install requirements into Python 2.7 virtualenv
7+
pip:
8+
requirements: "{{ project_root }}/requirements/project.txt"
9+
virtualenv: "{{ virtualenv }}"
10+
virtualenv_command: /usr/bin/virtualenv -p python2.7
11+
when: python_version == 2
12+
13+
14+
- name: Install requirements into Python 3 virtualenv
15+
pip:
16+
requirements: "{{ project_root }}/requirements/project.txt"
17+
virtualenv: "{{ virtualenv }}"
18+
virtualenv_command: python3 /usr/lib/python3/dist-packages/virtualenv.py -p python3
19+
when: python_version == 3
20+
21+
22+
- name: Set some env vars when activating virtualenv
23+
lineinfile:
24+
dest: "{{ virtualenv }}/bin/activate"
25+
regexp: "^export {{ item.name }}="
26+
line: "export {{ item.name }}={{ item.value }}"
27+
state: present
28+
insertafter: EOF
29+
with_items:
30+
- {name: DJANGO_SETTINGS_MODULE, value: pythonkc_site.settings}
31+
- {name: PYTHONPATH, value: "{{ pythonpath }}"}
32+
33+
34+
- name: Automatically activate the virtualenv in bashrc
35+
lineinfile:
36+
dest: ~/.bashrc
37+
line: "source {{ virtualenv }}/bin/activate"
38+
state: present
39+
insertafter: EOF
40+
41+
42+
- name: Run migrations
43+
django_manage:
44+
command: migrate
45+
app_path: "{{ project_root }}"
46+
pythonpath: "{{ pythonpath }}"
47+
virtualenv: "{{ virtualenv }}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- {include: python2.yml, tags: python, when: python_version == 2}
3+
- {include: python3.yml, tags: python, when: python_version == 3}
4+
- include: tools.yml tags=tools
5+
- include: django.yml tags=django
6+
7+
# TODO
8+
# vim + vim configuration for python?
9+
# postgres? (for now just using sqlite for development)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Update apt
3+
apt: update_cache=yes cache_valid_time=3600
4+
become: yes
5+
tags: apt
6+
7+
- name: Install some base packages
8+
apt: pkg="{{item}}" state=latest
9+
become: yes
10+
tags: apt
11+
with_items:
12+
- build-essential
13+
- libpq-dev
14+
- python-dev
15+
- python-pip
16+
- python-software-properties
17+
- python-virtualenv
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
---
22
- name: Update apt
33
apt: update_cache=yes cache_valid_time=3600
4+
become: yes
45
tags: apt
56

67
- name: Install some base packages
78
apt: pkg="{{item}}" state=latest
9+
become: yes
810
tags: apt
911
with_items:
1012
- build-essential
13+
- libpq-dev
1114
- python3
1215
- python3-dev
1316
- python3-pip
1417
- python3-software-properties
15-
- vim-nox
16-
- htop
17-
18-
# What else should go in here?
19-
# vim + vim configuration for python?
18+
- python3-virtualenv
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
- name: Update apt
3+
apt: update_cache=yes cache_valid_time=3600
4+
become: yes
5+
tags: apt
6+
7+
8+
- name: Install some dev tools packages
9+
apt: pkg="{{item}}" state=latest
10+
become: yes
11+
tags: apt
12+
with_items:
13+
- vim-nox
14+
- htop
15+
16+
# TODO basic vimrc with python plugins?

0 commit comments

Comments
 (0)