More Vagrant stuff.

master
Nick Sergeant 2014-10-30 11:56:28 -04:00
parent 21e154f499
commit c6443c9ae9
7 changed files with 61 additions and 36 deletions

View File

@ -1,7 +1,4 @@
deploy: assets:
@git push heroku
deploy-with-assets:
@cat media/css/bootstrap.min.css \ @cat media/css/bootstrap.min.css \
media/css/blog-themes/pro-adams/style.css \ media/css/blog-themes/pro-adams/style.css \
media/css/highlightjs-themes/tomorrow.css \ media/css/highlightjs-themes/tomorrow.css \
@ -63,6 +60,19 @@ deploy-with-assets:
media/js/src/pro.js \ media/js/src/pro.js \
> media/js/pro-all.min.js > media/js/pro-all.min.js
/Users/Nick/.virtualenvs/snipt/bin/python manage.py collectstatic --noinput /Users/Nick/.virtualenvs/snipt/bin/python manage.py collectstatic --noinput
db:
@echo Creating database user snipt:
@sudo -H -u postgres bash -c 'createuser snipt -P'
@sudo -H -u postgres bash -c 'createdb snipt -O snipt'
deploy:
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; git pull;'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; make assets;'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; /var/www/.virtualenvs/snipt/bin/python manage.py migrate'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo supervisorctl restart snipt'
deploy-heroku:
@git push heroku @git push heroku
salt-vagrant: salt-vagrant:
@ -88,8 +98,14 @@ vagrant:
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo mv ~/salt /srv/salt' @ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo mv ~/salt /srv/salt'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo mv ~/pillar /srv/pillar' @ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo mv ~/pillar /srv/pillar'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo salt-call --local state.highstate' @ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'sudo salt-call --local state.highstate'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; make db'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; /var/www/.virtualenvs/snipt/bin/python manage.py syncdb'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; /var/www/.virtualenvs/snipt/bin/python manage.py migrate'
@ssh vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key 'cd /var/www/snipt; /var/www/.virtualenvs/snipt/bin/python manage.py backfill_api_keys'
.PHONY: deploy, \ .PHONY: assets, \
deploy-with-assets, \ db, \
deploy, \
deploy-heroku, \
salt-vagrant, \ salt-vagrant, \
vagrant vagrant

View File

@ -4,13 +4,14 @@ This is the codebase for the website, [Snipt.net](https://snipt.net/).
# Running the Django app # Running the Django app
Install [Vagrant](https://www.vagrantup.com/) and either [VirtualBox](https://www.virtualbox.org/) or
[VMWare Fusion](http://www.vmware.com/products/fusion).
1. Clone the repo. 1. Clone the repo.
2. Setup a virtualenv. 2. `cp settings_local.py-template settings_local.py`
3. `pip install -r requirements.txt` 3. Edit local settings (choose a database password - you'll be prompted for it).
5. `python manage.py syncdb` 4. `make vagrant`
6. `python manage.py migrate` 5. Visit [http://local.snipt.net:8080/](http://local.snipt.net:8080/).
7. `python manage.py runserver`
8. If you created a superuser in the syncdb step, you need to also run `python manage.py backfill_api_keys` to generate an API key for that user.
# Deploying to Heroku # Deploying to Heroku

View File

@ -12,7 +12,7 @@ class BlogMiddleware:
host = request.META.get('HTTP_HOST', '') host = request.META.get('HTTP_HOST', '')
host_s = host.replace('www.', '').split('.') host_s = host.replace('www.', '').split('.')
if host != 'snipt.net' and host != 'snipt.localhost': if host != 'snipt.net' and host != 'snipt.localhost' and host != 'local.snipt.net':
if len(host_s) > 2: if len(host_s) > 2:
if host_s[1] == 'snipt': if host_s[1] == 'snipt':

View File

@ -74,8 +74,11 @@ server {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /static/ { {% if pillar.env_name != 'vagrant' %}
alias /var/www/snipt/static/; location /static/ {
expires max; alias /var/www/snipt/static/;
} expires max;
}
{% endif %}
} }

View File

@ -17,7 +17,7 @@ http {
gzip on; gzip on;
gzip_disable "msie6"; gzip_disable "msie6";
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
include /etc/nginx/sites-enabled/*; include /etc/nginx/sites-enabled/*;

View File

@ -21,23 +21,6 @@ if 'DATABASE_URL' in os.environ:
if es.username: if es.username:
HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": es.username + ':' + es.password} HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": es.username + ':' + es.password}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'snipt',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': ''
}
}
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
}
ABSOLUTE_URL_OVERRIDES = { 'auth.user': lambda u: "/%s/" % u.username, } ABSOLUTE_URL_OVERRIDES = { 'auth.user': lambda u: "/%s/" % u.username, }
ACCOUNT_ACTIVATION_DAYS = 0 ACCOUNT_ACTIVATION_DAYS = 0
ADMINS = (('Nick Sergeant', 'nick@snipt.net'),) ADMINS = (('Nick Sergeant', 'nick@snipt.net'),)

View File

@ -1,8 +1,30 @@
AWS_ACCESS_KEY_ID = '' AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = '' AWS_SECRET_ACCESS_KEY = ''
AWS_STORAGE_BUCKET_NAME = '' AWS_STORAGE_BUCKET_NAME = ''
DEBUG=True DEBUG = True
INTERCOM_SECRET_KEY = ''
POSTMARK_API_KEY = ''
RAVEN_CONFIG_DSN = ''
S3_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME S3_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
SECRET_KEY = ''
SSLIFY_DISABLE = True SSLIFY_DISABLE = True
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATIC_URL = '/static/' STATIC_URL = '/static/'
STRIPE_SECRET_KEY = ''
USE_SSL = False
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'snipt',
'USER': 'snipt',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': ''
}
}
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
}