Revisions
-
shazow revised this gist
Dec 7, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -214,6 +214,7 @@ server { server_name $DOMAIN; access_log /home/$USERTARGET/logs/$PROJECTNAME/access.log; charset utf-8; client_max_body_size 32M; gzip on; gzip_http_version 1.1; -
shazow revised this gist
Nov 14, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -262,5 +262,5 @@ fi # Print instructions if [ "$TWOSTEP" == "y" ]; then deploy_instructions $USERTARGET $PROJECTNAME fi -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function deploy_instructions() { Setup your development clone as follows: git branch live git remote add -t live live ssh://$1@$IP_ADDRESS/home/$1/repo/$2 Now you can deploy: @@ -59,8 +59,8 @@ while [ "$1" ]; do exit ;; "-p") ONLY_INSTRUCTIONS="y" shift ;; "-f") FORCE="y" @@ -101,6 +101,11 @@ if [ ! "$DOMAIN" ]; then DOMAIN="$PROJECTNAME.com" fi if [ "$ONLY_INSTRUCTIONS" == "y" ]; then deploy_instructions $USERTARGET $PROJECTNAME exit fi if [ "$NOPROMPT" != "y" ]; then echo "This script is intended to be run on a remote server, not on a local development environment. It will create a bunch of directories and change a bunch of configurations." -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 14 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function deploy_instructions() { Setup your development clone as follows: git branch live git remote add -t live live ssh://$USERNAME@$IP_ADDRESS/home/$USERTARGET/repo/$PROJECTNAME Now you can deploy: @@ -47,6 +47,9 @@ EOF } USERNAME="$(whoami)" USERTARGET="$USERNAME" positional=( ); while [ "$1" ]; do @@ -74,6 +77,8 @@ while [ "$1" ]; do "-2") TWOSTEP="y" shift USERTARGET="$1" shift ;; *) positional[${#positional[*]}]="$1" @@ -83,7 +88,6 @@ while [ "$1" ]; do done PROJECTNAME="${positional[0]}" DOMAIN="${positional[1]}" @@ -159,7 +163,7 @@ EOF if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." command="$0 $PROJECTNAME -2 $USERNAME -y" if [ "$FORCE" == "y" ]; then command="$command -f" fi @@ -182,11 +186,11 @@ else ################################################# Rootland configuration ## else tee $supervisor_conf_path > /dev/null << EOF [program:$PROJECTNAME-uwsgi] directory=/home/$USERTARGET/deploy/$PROJECTNAME user=$USERTARGET command=/usr/bin/uwsgi-python -C -H /home/$USERTARGET/env/$PROJECTNAME -L -w wsgi --socket /tmp/$PROJECTNAME-uwsgi.sock --master --processes 1 --pidfile /tmp/$PROJECTNAME-uwsgi.pid stdout_logfile=/home/$USERTARGET/logs/$PROJECTNAME/uwsgi.log redirect_stderr=true stopsignal=INT autorestart=true @@ -203,7 +207,7 @@ EOF server { listen 80; server_name $DOMAIN; access_log /home/$USERTARGET/logs/$PROJECTNAME/access.log; charset utf-8; gzip on; @@ -216,11 +220,11 @@ server { gzip_disable "MSIE [1-6].(?!.*SV1)"; location ~ ^/(robots.txt|favicon.ico)\$ { root /home/$USERTARGET/public_html/$PROJECTNAME/static; } location /static { root /home/$USERTARGET/public_html/$PROJECTNAME/; expires max; add_header Cache-Control "public"; } -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 29 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ function usage() { cat << EOF Usage: $0 PROJECT_NAME [DOMAIN] [OPTIONS] Options: -y No prompts, assume yes to all. @@ -18,16 +18,6 @@ EOF } function deploy_instructions() { IP_ADDRESS="$(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')" @@ -57,40 +47,57 @@ EOF } positional=( ); while [ "$1" ]; do case "$1" in "-h") usage exit ;; "-p") deploy_instructions exit ;; "-f") FORCE="y" shift ;; "-y") NOPROMPT="y" shift ;; "-1") ONESTEP="y" shift ;; "-2") TWOSTEP="y" shift ;; *) positional[${#positional[*]}]="$1" shift ;; esac done USERNAME="$(whoami)" PROJECTNAME="${positional[0]}" DOMAIN="${positional[1]}" if [ ! "$PROJECTNAME" ]; then echo "Error: Must specify a project name." usage exit 3; fi if [ ! "$DOMAIN" ]; then DOMAIN="$PROJECTNAME.com" fi if [ "$NOPROMPT" != "y" ]; then echo "This script is intended to be run on a remote server, not on a local development environment. It will create a bunch of directories and change a bunch of configurations." read -n1 -p "Are you sure you want to continue? [y/N] " answer -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,7 +57,7 @@ EOF } while getopts "h:p:f:y:1:2" OPTION; do case $OPTION in h) usage -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -152,7 +152,11 @@ EOF if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." command="$0 $PROJECTNAME -2 -y" if [ "$FORCE" == "y" ]; then command="$command -f" fi sudo $command fi else ################################################# Rootland configuration ## -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 3 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ function usage() { cat << EOF Usage: $0 PROJECT_NAME [OPTIONS] Options: -y No prompts, assume yes to all. @@ -19,7 +19,7 @@ EOF PROJECTNAME="$1" DOMAIN="$PROJECTNAME.com" USERNAME="$(whoami)" if [ ! "$PROJECTNAME" ]; then @@ -28,11 +28,6 @@ if [ ! "$PROJECTNAME" ]; then fi function deploy_instructions() { IP_ADDRESS="$(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')" @@ -157,7 +152,7 @@ EOF if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." sudo $0 $PROJECTNAME -2 -y fi else ################################################# Rootland configuration ## -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -157,7 +157,7 @@ EOF if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." sudo $0 $PROJECTNAME $DOMAIN -2 -y fi else ################################################# Rootland configuration ## -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -157,7 +157,7 @@ EOF if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." sudo $0 $* -2 -y fi else ################################################# Rootland configuration ## -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -157,7 +157,7 @@ EOF if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." sudo $0 $* -2 fi else ################################################# Rootland configuration ## -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,7 +62,7 @@ EOF } while getopts "h:y:p:f:1:2" OPTION; do case $OPTION in h) usage -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 14 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -113,19 +113,19 @@ if [ "$USERNAME" != "root" ]; then ################### Userland configuration ## mkdir ~/{repo,deploy,logs,public_html,uploads}/$PROJECTNAME git_repo=~/repo/$PROJECTNAME if [ -d $git_repo/config ] && [ "$FORCE" != "y" ]; then echo "Git repository already exists, skipping: $git_repo" else # Create a detached tree repository cd $git_repo git init --bare git config core.worktree ~/deploy/$PROJECTNAME git config receive.denycurrentbranch ignore # Setup post-receive hook to update detached tree on receive cat > hooks/post-receive << EOF #!/bin/sh git checkout -f @@ -136,7 +136,9 @@ if [ -f "\$UWSGI_PID" ]; then fi EOF chmod +x hooks/post-receive cd - fi # Setup static assets to be served by nginx directly -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 114 additions and 54 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,41 +8,93 @@ Usage: $0 [-y] PROJECT_NAME [DOMAIN] Options: -y No prompts, assume yes to all. -1 One-step, don't try to do the root parts automagically. -p Only print deploy instructions, don't do anything else. -f Overwrite any existing configurations. Example: $0 -y foo fooapp.com EOF } PROJECTNAME="$1" DOMAIN="$2" USERNAME="$(whoami)" if [ ! "$PROJECTNAME" ]; then echo "Error: Must specify a project name." exit 3; fi if [ ! "$DOMAIN" ]; then DOMAIN="$PROJECTNAME.com" fi function deploy_instructions() { IP_ADDRESS="$(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')" cat << EOF Setup your development clone as follows: git branch live git remote add -t live live ssh://$USERNAME@$IP_ADDRESS/home/$USERNAME/repo/$PROJECTNAME Now you can deploy: git checkout live git merge master git checkout master git push live Or use this handy 'deploy' alias in your ~/.gitconfig file: deploy = "!merge(){ git checkout \$2 && git merge \$1 && git push \$2 && git checkout \${1#refs/heads/}; }; merge \$(git symbolic-ref HEAD) \$1" So you can do (from 'master'): git deploy live Happy pushing! EOF } while getopts "h:y" OPTION; do case $OPTION in h) usage exit ;; p) deploy_instructions exit ;; f) FORCE="y" shift ;; y) NOPROMPT="y" shift ;; 1) ONESTEP="y" shift ;; 2) TWOSTEP="y" shift ;; ?) usage exit ;; esac done if [ "$NOPROMPT" != "y" ]; then echo "This script is intended to be run on a remote server, not on a local development environment. It will create a bunch of directories and change a bunch of configurations." @@ -53,16 +105,20 @@ if [ "$NOPROMPT" != "y" ]; then fi fi if [ "$USERNAME" != "root" ]; then ################### Userland configuration ## # Setup our directory structure mkdir ~/{deploy,env,logs,public_html,repo,uploads} mkdir ~/{repo,deploy,logs,public_html,uploads}/$PROJECTNAME # Create a detached tree repository cd ~/repo/$PROJECTNAME if [ -d .git ]; then echo "Git repository already exists, aborting." exit 5 fi git init --bare git config core.worktree ~/deploy/$PROJECTNAME git config receive.denycurrentbranch ignore @@ -88,16 +144,35 @@ EOF # Virtualenv virtualenv_path=~/env/$PROJECTNAME if [ -d $virtualenv_path ] && [ "$FORCE" != "y" ]; then echo "Virtualenv already exists, skipping: $virtualenv_path" else rm -rf $virtualenv_path virtualenv $virtualenv_path fi source $virtualenv_path/bin/activate if [ "$ONESTEP" != "y" ]; then echo "The rest of this script requires root permission, please give sudo permission or run it again as root manually." sudo $0 -2 $* fi else ################################################# Rootland configuration ## if [ ! "$TWOSTEP" ]; then echo "Warning: Running as root, only doing root parts." fi # Install root config files ## Supervisor supervisor_conf_path=/etc/supervisor/conf.d/$PROJECTNAME.conf if [ -f $supervisor_conf_path ] && [ "$FORCE" != "y" ]; then echo "Supervisor configuration already exists, skipping: $supervisor_conf_path" else tee $supervisor_conf_path > /dev/null << EOF [program:$PROJECTNAME-uwsgi] directory=/home/$USERNAME/deploy/$PROJECTNAME user=$USERNAME @@ -108,9 +183,15 @@ redirect_stderr=true stopsignal=INT autorestart=true EOF fi ## Nginx nginx_conf_path=/etc/nginx/sites-available/$PROJECTNAME if [ -f $nginx_conf_path ] && [ "$FORCE" != "y" ]; then echo "Nginx site configuration already exists, skipping: $nginx_conf_path" else tee $nginx_conf_path > /dev/null << EOF server { listen 80; server_name $DOMAIN; @@ -151,39 +232,18 @@ server { } EOF ## Enable new Nginx config ln -sft /etc/nginx/sites-enabled/ "../sites-available/$PROJECTNAME" fi # Restart things /etc/init.d/nginx reload supervisorctl reload fi # Print instructions if [ "$TWOSTEP" == "y" ]; then deploy_instructions fi -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,7 +64,6 @@ else # Create a detached tree repository cd ~/repo/$PROJECTNAME git init --bare git config core.worktree ~/deploy/$PROJECTNAME git config receive.denycurrentbranch ignore @@ -128,11 +127,11 @@ server { gzip_disable "MSIE [1-6].(?!.*SV1)"; location ~ ^/(robots.txt|favicon.ico)\$ { root /home/$USERNAME/public_html/$PROJECTNAME/static; } location /static { root /home/$USERNAME/public_html/$PROJECTNAME/; expires max; add_header Cache-Control "public"; } -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 18 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,21 +56,21 @@ fi if [ "$USERNAME" == "root" ]; then echo "Warning: Running as root, only doing root parts." else # Setup our directory structure mkdir ~/{deploy,env,logs,public_html,repo,uploads} mkdir ~/{repo,deploy,logs,public_html,uploads}/$PROJECTNAME # Create a detached tree repository cd ~/repo/$PROJECTNAME git init --bare git config core.bare false git config core.worktree ~/deploy/$PROJECTNAME git config receive.denycurrentbranch ignore # Setup post-receive hook to update detached tree on receive cat > hooks/post-receive << EOF #!/bin/sh git checkout -f @@ -81,16 +81,16 @@ if [ -f "\$UWSGI_PID" ]; then fi EOF chmod +x hooks/post-receive # Setup static assets to be served by nginx directly ln -s ~/deploy/$PROJECTNAME/static ~/public_html/$PROJECTNAME/static # Virtualenv virtualenv ~/env/$PROJECTNAME source ~/env/$PROJECTNAME/bin/activate fi @@ -187,4 +187,4 @@ So you can do (from 'master'): git deploy live Happy pushing! EOF -
shazow revised this gist
Nov 13, 2011 . 1 changed file with 23 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # Setup deployment target for Nginx + Python/uWSGI + Supervisor + Git # From: https://gist.github.com/1210041 function usage() { cat << EOF @@ -35,11 +35,6 @@ PROJECTNAME="$1" DOMAIN="$2" USERNAME="$(whoami)" if [ ! "$PROJECTNAME" ]; then echo "Error: Must specify a project name." exit 3; @@ -58,21 +53,24 @@ if [ "$NOPROMPT" != "y" ]; then fi fi if [ "$USERNAME" == "root" ]; then echo "Warning: Running as root, only doing root parts." else # Setup our directory structure mkdir ~/{deploy,env,logs,public_html,repo,uploads} mkdir ~/{repo,deploy,logs,public_html,uploads}/$PROJECTNAME # Create a detached tree repository cd ~/repo/$PROJECTNAME git init --bare git config core.bare false git config core.worktree ~/deploy/$PROJECTNAME git config receive.denycurrentbranch ignore # Setup post-receive hook to update detached tree on receive cat > hooks/post-receive << EOF #!/bin/sh git checkout -f @@ -83,16 +81,18 @@ if [ -f "\$UWSGI_PID" ]; then fi EOF chmod +x hooks/post-receive # Setup static assets to be served by nginx directly ln -s ~/deploy/$PROJECTNAME/static ~/public_html/$PROJECTNAME/static # Virtualenv virtualenv ~/env/$PROJECTNAME source ~/env/$PROJECTNAME/bin/activate fi # Install root config files -
shazow revised this gist
Sep 11, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,10 +50,10 @@ if [ ! "$DOMAIN" ]; then fi if [ "$NOPROMPT" != "y" ]; then echo "This script is intended to be run on a remote server, not on a local development environment. It will create a bunch of directories and change a bunch of configurations." read -n1 -p "Are you sure you want to continue? [y/N] " answer if [ "$answer" != "y" ]; then echo "Aborting." exit 4 fi fi @@ -79,7 +79,7 @@ git checkout -f UWSGI_PID=/tmp/$PROJECTNAME-uwsgi.pid if [ -f "\$UWSGI_PID" ]; then echo "Restarting uwsgi."; kill -HUP \$(cat \$UWSGI_PID); fi EOF -
shazow revised this gist
Sep 11, 2011 . 1 changed file with 45 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,62 @@ #!/bin/bash # Setup deployment target for Nginx + Python/uWSGI + Supervisor + Git function usage() { cat << EOF Usage: $0 [-y] PROJECT_NAME [DOMAIN] Options: -y No prompts, assume yes to all. Example: $0 -y foo fooapp.com EOF } while getopts "h:y" OPTION; do case $OPTION in h) usage exit ;; y) NOPROMPT="y" shift ;; ?) usage exit ;; esac done PROJECTNAME="$1" DOMAIN="$2" USERNAME="$(whoami)" if [ "$USERNAME" == "root" ]; then echo "Error: Must be run as non-root." exit 2 fi if [ ! "$PROJECTNAME" ]; then echo "Error: Must specify a project name." exit 3; fi if [ ! "$DOMAIN" ]; then DOMAIN="$PROJECTNAME.com" fi if [ "$NOPROMPT" != "y" ]; then echo "This script is intended to be run on a remote server, not on a local development environment. It will create a bunch of directories and change a bunch of configurations, are you sure you want to continue? [y/N] " read -n1 answer if [ "$answer" != "y" ]; then echo "\nAborting." exit 4 fi fi # Setup our directory structure mkdir ~/{deploy,env,logs,public_html,repo,uploads} @@ -144,4 +187,4 @@ So you can do (from 'master'): git deploy live Happy pushing! EOF -
shazow created this gist
Sep 11, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,147 @@ #!/bin/bash # Setup deployment target for Nginx + Python/uWSGI + Supervisor + Git PROJECTNAME="$1" DOMAIN="$2" USERNAME="$(whoami)" if [ "$USERNAME" == "root" ]; then echo "Error: Must be run as non-root." exit 1 fi if [ ! "$DOMAIN" ]; then DOMAIN="$PROJECTNAME.com" fi # Setup our directory structure mkdir ~/{deploy,env,logs,public_html,repo,uploads} mkdir ~/{repo,deploy,logs,public_html,uploads}/$PROJECTNAME # Create a detached tree repository cd ~/repo/$PROJECTNAME git init --bare git config core.bare false git config core.worktree ~/deploy/$PROJECTNAME git config receive.denycurrentbranch ignore # Setup post-receive hook to update detached tree on receive cat > hooks/post-receive << EOF #!/bin/sh git checkout -f UWSGI_PID=/tmp/$PROJECTNAME-uwsgi.pid if [ -f "\$UWSGI_PID" ]; then echo "Restarting uwsgi."; kill -HUP $(cat \$UWSGI_PID); fi EOF chmod +x hooks/post-receive # Setup static assets to be served by nginx directly ln -s ~/deploy/$PROJECTNAME/static ~/public_html/$PROJECTNAME/static # Virtualenv virtualenv ~/env/$PROJECTNAME source ~/env/$PROJECTNAME/bin/activate # Install root config files ## Supervisor sudo tee /etc/supervisor/conf.d/$PROJECTNAME.conf > /dev/null << EOF [program:$PROJECTNAME-uwsgi] directory=/home/$USERNAME/deploy/$PROJECTNAME user=$USERNAME command=/usr/bin/uwsgi-python -C -H /home/$USERNAME/env/$PROJECTNAME -L -w wsgi --socket /tmp/$PROJECTNAME-uwsgi.sock --master --processes 1 --pidfile /tmp/$PROJECTNAME-uwsgi.pid stdout_logfile=/home/$USERNAME/logs/$PROJECTNAME/uwsgi.log redirect_stderr=true stopsignal=INT autorestart=true EOF ## Nginx sudo tee /etc/nginx/sites-available/$PROJECTNAME > /dev/null << EOF server { listen 80; server_name $DOMAIN; access_log /home/$USERNAME/logs/$PROJECTNAME/access.log; charset utf-8; gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 6; gzip_proxied any; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_buffers 16 8k; gzip_disable "MSIE [1-6].(?!.*SV1)"; location ~ ^/(robots.txt|favicon.ico)\$ { root /home/$USERNAME/public_html/$PROJECTNAME.com/static; } location /static { root /home/$USERNAME/public_html/$PROJECTNAME.com/; expires max; add_header Cache-Control "public"; } location / { include uwsgi_params; uwsgi_pass unix:///tmp/$PROJECTNAME-uwsgi.sock; uwsgi_param SCRIPT_NAME ""; } } server { listen 80; server_name www.$DOMAIN; rewrite ^/(.*) http://$DOMAIN/\$1 permanent; } EOF ## Enable new Nginx config sudo ln -sft /etc/nginx/sites-enabled/ "../sites-available/$PROJECTNAME" # Restart things sudo /etc/init.d/nginx reload sudo supervisorctl reload # Print instructions IP_ADDRESS="$(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')" cat << EOF Setup your development clone as follows: git branch live git remote add -t live live ssh://$USERNAME@$IP_ADDRESS/home/$USERNAME/repo/$PROJECTNAME Now you can deploy: git checkout live git merge master git checkout master git push live Or use this handy 'deploy' alias in your ~/.gitconfig file: deploy = "!merge(){ git checkout \$2 && git merge \$1 && git push \$2 && git checkout \${1#refs/heads/}; }; merge \$(git symbolic-ref HEAD) \$1" So you can do (from 'master'): git deploy live Happy pushing! EOF