Reputation: 21108
I'm using this guide: http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/
To set up my django project. But I'm stuck at deployment part. I installed fabric using pip in my virtualenv. I created this file inside myproject directory:
from fabric.api import local
def prepare_deployment(branch_name):
local('python manage.py test finance')
local('git add -p && git commit')
local('git checkout master && git merge ' + branchname)
from fabric.api import lcd
def deploy():
with lcd('home/andrius/djcode/myproject/'):
local('git pull /home/andrius/djcode/dev/')
local('python manage.py migrate finance')
local('python manage.py test finance')
local('/my/command/to/restart/webserver')
But when I enter this command (as shown in a guide):
fab prepare_deployment
I get this error:
Traceback (most recent call last):
File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/main.py", line 732, in main
*args, **kwargs
File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/tasks.py", line 345, in execute
results['<local-only>'] = task.run(*args, **new_kwargs)
File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/tasks.py", line 121, in run
return self.wrapped(*args, **kwargs)
TypeError: prepare_deployment() takes exactly 1 argument (0 given)
So even though it didn't specify in guide to enter argument, I suppose it requires my branch name. So entered this:
fab prepare_deployment v0.1
(v0.1 is my branch name) So now I got this error:
Warning: Command(s) not found:
v0.1
Available commands:
deploy
prepare_deployment
Also I noticed in a guide for file fabfile.py in function prepare_deployment, input is written as 'branch_name' and inside function there is argument 'branchname'. So I thought it should be the same and renamed 'branchname' to 'branch_name', but still getting the same error.
So I think I'm doing something wrong here. What could be the problem?
Update: I tried to call function inside fabfile.py with:
prepare_deployment("v0.1")
Output was this:
[localhost] local: python manage.py test finance
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database
Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel: yes
Destroying old test database 'default'...
Got an error recreating the test database: database "test_finance" does not exist
Fatal error: local() encountered an error (return code 2) while executing 'python manage.py test finance'
Aborting.
I think I should also mention that my app name is 'finance' as database name 'finance'. Maybe those are conflicting?
Upvotes: 2
Views: 1393
Reputation: 25569
fabric uses a specific syntax for passing arguments to tasks from the command line. From a bash shell you would need to use
fab prepare_deployment:v0.1
You can read about it in the fabric documentation on per task arguments.
If you ever actually need to use brackets in a bash command you would need to escape them.
Upvotes: 5
Reputation: 6346
As you stated, this function should look like this...
def prepare_deployment(branch_name):
local('python manage.py test finance')
local('git add -p && git commit')
local('git checkout master && git merge ' + branch_name)
Then you simply call...
fab prepare_deployment("v0.1")
Upvotes: 0