Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

making sure that media on the development environment is not served from outside the environment. #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .epioignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax: regex
^media/
^static/
^.gitignore$
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add .gitignore to .epioignore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because .epioignore is for everything that should not be transmitted to the bundler. This includes VCS metadata.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.

^.hg/

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
*.swp
*.un~
*.db
static_root/
/media/*
/static_root/*

15 changes: 10 additions & 5 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fabric.api import local, env
from fabric.api import local, env, require

def production():
env['epioapp'] = # production epio instance name
Expand All @@ -7,15 +7,20 @@ def staging():
env['epioapp'] = # staging epio instance

def epio(commandstring):
local("epio {0} -a {1}".format(
commandstring,
env['epioapp']))
require('epioapp', provided_by=['production','staging'])
from os import path
with lcd(path.dirname(__file__)):
local("epio {0} -a {1}".format(
commandstring,
env['epioapp']))

def deploy():
""" An example deploy workflow """
local("./manage.py collectstatic")
epio('suspend')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a good reason to suspend-deploy-resume? Until now I've just deployed to a running instance with no issues. At some point the backend restarts the instance once the deploy is complete.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a few seconds in between deploying the code, running the migrations and flushing the cache that the app is in an intermediate state and can throw errors or otherwise get in a tissy. Suspend and resume guards ensure that the deploy happens atomically. I have spoken to Andrew Godwin on this and he plans to support a maintennance suspension mode specifically for this purpose.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke with Andrew about this.

Basically, we should support deploy with and without suspending as two separate management commands. Deploying new code should suspend and resume to take advantage of the maintenance mode, deploying new CSS shouldn't interfere with a running webapp like that.

Bottom line, there should be two management commands, deploy and deploy_suspend.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about: deploy(suspend=True):
this way the safest method is preselected, and if only a quick changes is needed one can fab deploy:suspend=False

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that sounds like a reasonable way to do it. +1.

local('./manage.py "collectstatic --noinput"')
epio('upload')
epio('django syncdb')
epio('django migrate')
epio('django epio_flush_cache')
epio('resume')

Empty file added media/.gitignore
Empty file.
8 changes: 4 additions & 4 deletions settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
USE_I18N = True
USE_L10N = True

MEDIA_ROOT = PROJECT_DIR.parent.child('data')
MEDIA_ROOT = PROJECT_DIR.child('media')
MEDIA_URL = '/media/'

STATIC_ROOT = PROJECT_DIR.child('static_root')
STATIC_ROOT = PROJECT_DIR.child('static-root')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from underscore to hyphen here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it looks neater. Easier to read.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I think legibility is a matter of personal preference. I use underscores, not dashes. -1 on this change.

STATIC_URL = '/static/'

STATICFILES_DIRS = (
str(PROJECT_DIR.child('static')),
)
Expand Down Expand Up @@ -87,4 +87,4 @@
'propagate': True,
},
}
}
}
7 changes: 4 additions & 3 deletions settings/epio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import absolute_import
from .base import *

MEDIA_ROOT = PROJECT_DIR.parent.child('data')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're adding this line here anyways, might as well do it right: the value for MEDIA_ROOT should be config['core']['data_directory'], which requires importing config a bit further up in the file.

STATIC_ROOT = PROJECT_DIR.child('static-root')

from bundle_config import config
DATABASES = {
'default': {
Expand All @@ -15,9 +18,7 @@
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': '{host}:{port}'.format(
host=config['redis']['host'],
port=config['redis']['port']),
'LOCATION': '%(host)s:%(port)s' % config['redis'],
'OPTIONS': {
'PASSWORD': config['redis']['password'],
},
Expand Down
Empty file added static/.gitignore
Empty file.
Empty file added static_root/.gitignore
Empty file.