Friday, November 21, 2014

Re: Deploying Django project

Hi Fred,

Sory for the missunderstanding ...

i just remember my first time deploying manually with all the typing and typo and the step.. :)

Cheers

Mulianto

On Fri, Nov 21, 2014 at 11:42 PM, Fred Stluka <fred@bristle.com> wrote:
Mulianto,

You said:
Fred way is good, but need time to type and remember all the steps. WIth fabric you will not miss a step and it can be automated.

I think you misunderstood my post.  The commands I showed
are excerpts from my automated script.  I provided them so
termopro could write such a script of his own.  I don't type all
of those commands each time.  I just type:  pub

--Fred
Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
On 11/20/14 7:50 PM, Phang Mulianto wrote:
Hi termopro,

TO automate the deployment, look for fabric + cuisie (CHef like fabric) .

You will bored with the command line in each deployment, and you will need fast and standard way of deploying to each new machine.

Fred way is good, but need time to type and remember all the steps. WIth fabric you will not miss a step and it can be automated.

Git is you friend here. You can create a private repo in your prod machine, and make the code pull from the repo for production deployment when you push from dev to prod with hook script (Automate again)

BUt make sure the code tested before go production with this way.

Regards,

Mulianto

Blog: http://muliantophang.blogspot.com

On Fri, Nov 21, 2014 at 7:37 AM, Fred Stluka <fred@bristle.com> wrote:
termopro,

I have automated my deployments mostly separate from my
version control.

The other team members and I write, test, commit, and push our
code changes to our Git repo.  I then pull, review, test, update
the version number, commit, tag, and push to Git.

Then I use a shell script (on Mac, but would work on Unix/Linux
also) to push the tagged commit to TEST and later to PROD.

My script does things like:

- Get the latest files from Git before, and back to master after:
   % git checkout mytag
   ...
   % git checkout master

- Create folder of collected static files before, and delete after:
   % mkdir -pv collected_static/mytag
   % python manage.py collectstatic --clear --noinput
   ...
   % rm -rfv collected_static

- Delete all local *.pyc files:
   % find . -name \*.pyc -exec rm -v "{}" ";"

- Insert PROD password into local settings file (PROD pushes
   only) before, and remove after:
   % sed -i .old -e "s/PUT_PROD_PASSWORD_HERE/`cat prod_pw`/g" settings.py
   ...
   % mv -v settings.py.old settings.py

- Show a warning banner at the Web site to say it is going down
   briefly, and clear the banner after:
   % ssh -t myserver.mydomain.com cp -v /var/www/django/myapp/templates/myapp/site_alert_maintenance.html site_alert.html
   % sleep 60
   ...
   % ssh -t myserver.mydomain.com cp -v /var/www/django/myapp/templates/myapp/site_alert_none.html site_alert.html

- Push the local files to the TEST or PROD server:
   %  rsync -v --progress -i -l --rsh=ssh -r --del myapp myserver.mydomain.com:/var/www/django

- Run all migrations on the server
   % ssh -t myserver.mydomain.com python manage.py migrate --all

- Stop the Apache server, delete all remote *.pyc files, and
   restart the server:
   % ssh -t myserver.mydomain.com sudo /etc/init.d/httpd stop
   % ssh -t myserver.mydomain.com sudo find /var/www/django/myapp -name \*.pyc -exec rm -v "{}" ";"
   % ssh -t myserver.mydomain.com sudo /etc/init.d/httpd start

Plus a few other actions that are specific to our app, and lots
or informational messages, prompts, confirmations, etc.  Also,
some of these steps are combined into a remote script that
runs on the server to reduce the number of "ssh -t sudo"
commands I would otherwise have to do.  But, that's the gist
of it.

Hope this helps!
--Fred
Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
On 11/19/14 5:22 AM, termopro wrote:

I have created a Django 1.7 project and would like to deploy it. I am reading about how to do it right and i have some questions.

If i understand correctly deployment should contain the following steps:

1) Initial remote machine set up:

  • a) install os / server / database / cache ...
  • b) install Django and required modules
  • c) update database with real data

2) Upload code/ database changes to remote machine:

  • a) upload changed Django project
  • b) upload changes in Database tables (model migrations)

Most tutorials/articles about deployment do not cover 1.c and 2.b. Also the tasks 1.b. and 2.a. are solved using revision control tools (Git/Mercurial)

So i'd like to know:

  • 1) How do i install Django project or it's updates without revision control tools ? Should i simply upload my project using FTP/SSH ? Is there a good way to automate it ?

  • 2) How do i automate the task of uploading required database changes (like model migrations) ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e9fb8f5a-2bd9-47d5-80c7-07a3aa82bd25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/546E7B4A.3030303%40bristle.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BSr5mR8Q%3DBBvdvOEKktNr66-rGO%2BeYCxV2v9w5vGTrY9Ntbhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/546F5D61.4030000%40bristle.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BSr5mQF%2BkF2F%2BOAW4VnROY-aR-oP0P4aEa4Z-qQOo8PTrp8dQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment