From c6443c9ae912e06b97e89598a0f8db3bd9c3e820 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Thu, 30 Oct 2014 11:56:28 -0400 Subject: [PATCH] More Vagrant stuff. --- Makefile | 28 ++++++++++++++++++++++------ README.md | 13 +++++++------ blogs/middleware.py | 2 +- salt/application/snipt.nginx.conf | 11 +++++++---- salt/nginx/nginx.conf | 2 +- settings.py | 17 ----------------- settings_local.py-template | 24 +++++++++++++++++++++++- 7 files changed, 61 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index c4424aa..3f4e440 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,4 @@ -deploy: - @git push heroku - -deploy-with-assets: +assets: @cat media/css/bootstrap.min.css \ media/css/blog-themes/pro-adams/style.css \ media/css/highlightjs-themes/tomorrow.css \ @@ -63,6 +60,19 @@ deploy-with-assets: media/js/src/pro.js \ > media/js/pro-all.min.js /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 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 ~/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 '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, \ - deploy-with-assets, \ +.PHONY: assets, \ + db, \ + deploy, \ + deploy-heroku, \ salt-vagrant, \ vagrant diff --git a/README.md b/README.md index 382edc3..b4012f3 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,14 @@ This is the codebase for the website, [Snipt.net](https://snipt.net/). # 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. -2. Setup a virtualenv. -3. `pip install -r requirements.txt` -5. `python manage.py syncdb` -6. `python manage.py migrate` -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. +2. `cp settings_local.py-template settings_local.py` +3. Edit local settings (choose a database password - you'll be prompted for it). +4. `make vagrant` +5. Visit [http://local.snipt.net:8080/](http://local.snipt.net:8080/). # Deploying to Heroku diff --git a/blogs/middleware.py b/blogs/middleware.py index c2c52b0..64b5778 100644 --- a/blogs/middleware.py +++ b/blogs/middleware.py @@ -12,7 +12,7 @@ class BlogMiddleware: host = request.META.get('HTTP_HOST', '') 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 host_s[1] == 'snipt': diff --git a/salt/application/snipt.nginx.conf b/salt/application/snipt.nginx.conf index bec9193..018c65a 100644 --- a/salt/application/snipt.nginx.conf +++ b/salt/application/snipt.nginx.conf @@ -74,8 +74,11 @@ server { proxy_set_header Host $host; } - location /static/ { - alias /var/www/snipt/static/; - expires max; - } + {% if pillar.env_name != 'vagrant' %} + location /static/ { + alias /var/www/snipt/static/; + expires max; + } + {% endif %} + } diff --git a/salt/nginx/nginx.conf b/salt/nginx/nginx.conf index 2f12f23..238d30c 100644 --- a/salt/nginx/nginx.conf +++ b/salt/nginx/nginx.conf @@ -17,7 +17,7 @@ http { gzip on; 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/*; diff --git a/settings.py b/settings.py index c25d9fe..e97bf7b 100644 --- a/settings.py +++ b/settings.py @@ -21,23 +21,6 @@ if 'DATABASE_URL' in os.environ: if es.username: 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, } ACCOUNT_ACTIVATION_DAYS = 0 ADMINS = (('Nick Sergeant', 'nick@snipt.net'),) diff --git a/settings_local.py-template b/settings_local.py-template index 07d8226..3659bfe 100644 --- a/settings_local.py-template +++ b/settings_local.py-template @@ -1,8 +1,30 @@ AWS_ACCESS_KEY_ID = '' AWS_SECRET_ACCESS_KEY = '' 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 +SECRET_KEY = '' SSLIFY_DISABLE = True STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' 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', + }, +}