简体   繁体   中英

How to setup Git to deploy python app files into Ubuntu Server?

I setup a new Ubuntu 12.10 Server on VPN hosting. I have installed all the required setup like Nginx, Python, MySQL etc. I am configuring this to deploy a Flask + Python app using uWSGI. Its working fine.

But to create a basic app i used Putty tool (from Windows) and created required app .py files.

But I want to setup a Git functionality so that i can push my code to required directory say /var/www/mysite.com/app_data so that i don't have to use SSH or FileZilla etc everytime i make some changes into my website.

Since i use both Ubuntu & Windows for development of app, setting up a Git kind of functionality would help me push or change my data easily to my Cloud Server.

How can i setup a Git functionality in Ubuntu ? and How could i access it and Deploy data using tools like GitBash etc. ?

Please Suggest

  • Create a bare repository on your server.
  • Configure your local repository to use the repository on the server as a remote.
  • When working on your local workstation, commmit your changes and push them to the repository on your server.
  • Create a post-receive hook in the server repository that calls "git archive" and thus transfers your files to some other directory on the server.

Modified version of innaM:

Concept

Have three repositories

  1. devel - development on your local development machine
  2. central - repository server - like GitHub, Bitbucket or anything other
  3. prod - production server

Then you commit things from devel to central and as soon as you want to deploy on prod, than you ask prod to pull data from prod.

"asking" prod server to pull the updates can be managed by cron (then you have to wait a moment) or you may use other means like one shot call of ssh asking to do git pull and possibly restart your app.

Step by step

In more details you can go this way.

Prepare repo on devel

Develop and test the app on your devel server.

Put it into local repository:

$ git init
$ git add *
$ git commit -m "initial commit"

Create repo on central server

Eg bitbucket provides this description: https://confluence.atlassian.com/display/BITBUCKET/Import+code+from+an+existing+project

Generally, you create the project on Bitbucket, find the url of it and then from your devel repo call:

$ git remote add origin  <bitbucket-repo-url>
$ git push origin

Clone central repo to prod server

Log onto your prod server.

Go to /var/www and clone form bitucket:

$ cd /var/www
$ git clone <bitbucket-repo-url>
$ cd mysite.com

and you shall have your directory ready.

Trigger publication of updates to prod3

There are numerous options. One being a cron task, which would regularly call

$ git pull

In case, your app needs restart afte an update, then you have to ensure, the restart would happen (this shall be possible using git log command, which will show new line after the update, or you may check, if status code would tell you.

Personally I would use "one shot ssh" (you asked not to use ssh, but I assume you are asking for "simpler" solution, so one shot call shall work simpler then using ftp, scp or other magic.

From your devel machine (assuming you have ssh access there):

$ ssh user@prod.server.com "cd /var/www/mysite.com && git pull origin && myapp restart"

Advantage is, that you do control the moment, the update happens.

Discussion

I use similar workflow.

rsync seems in many cases serve well enough or better (be aware of files being created at app runtime and by files in your app, which shall be removed during ongoing versions and shall be removed on server too).

salt (saltstack) could serve too, but requires a bit more learning and setup).

I have learned, that keeping source code and configuration data in the same repo makes sometime situation more dificult (that is why I am working on using salt).

fab command from Fabric (python based) may be best option (in case installation on Windows becomes difficult, look at http://ridingpython.blogspot.cz/2011/07/installing-fabric-on-windows.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM