Skip to content

Instantly share code, notes, and snippets.

@pinmarch
Created June 1, 2012 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinmarch/2853120 to your computer and use it in GitHub Desktop.
Save pinmarch/2853120 to your computer and use it in GitHub Desktop.
gitserver-on-dotcloud(nginx-on-dotcloud+nginx-dav-ext-module)
nginx:
type: custom
buildscript: nginx/builder
systempackages:
# needed for the Nginx rewrite module
- libpcre3-dev
- libexpat-dev
ports:
www: http
processes:
nginx: nginx
#!/usr/bin/env bash
shopt -s extglob
BUILDERDIR="$(dirname "$0")"
# variables needed later.
start_dir=`pwd`
nginx_install_dir="$HOME/nginx"
stage_dir="$start_dir/tmp"
nginx_stage_dir="$stage_dir/stage"
nginx_download_url="http://nginx.org/download/nginx-1.0.14.tar.gz" #TODO configurable?
# functions
msg() {
echo -e "\033[1;32m-->\033[0m $0:" $*
}
die() {
msg $*
exit 1
}
move_to_approot() {
[ -n "$SERVICE_APPROOT" ] && cd $SERVICE_APPROOT
}
clean_nginx() {
if [ -d $nginx_install_dir ] ; then
msg "cleaning up ($nginx_install_dir)"
rm -rf $nginx_install_dir
fi
}
install_nginx() {
local nginx_url=$nginx_download_url
msg "installing Nginx into: $nginx_install_dir"
# install nginx
if [ ! -d $nginx_install_dir ] ; then
msg "making directory: $nginx_install_dir "
mkdir -p $nginx_install_dir
msg "making directory: $nginx_stage_dir "
mkdir -p $nginx_stage_dir
msg "downloading nginx from ($nginx_url) and untaring into ($nginx_stage_dir) "
wget -O - $nginx_url | tar -C $nginx_stage_dir --strip-components=1 -zxf -
[ $? -eq 0 ] || die "can't fetch nginx"
msg "Successfully download and untarred nginx"
msg "move into $nginx_stage_dir "
cd $nginx_stage_dir
msg "trying to compile nginx, and then install it"
export CFLAGS="-O3 -pipe"
./configure \
--prefix=$nginx_install_dir \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_xslt_module \
--add-module=$start_dir/nginx-dav-ext-module && make && make install
# --with-http_xslt_module && make && make install
[ $? -eq 0 ] || die "Nginx install failed"
msg "Successfully compiled and installed nginx"
msg "remove some of the default config files from the nginx config directory that aren't needed"
rm $nginx_install_dir/conf/*.default
msg "cleaning up ($stage_dir) since it is no longer needed."
rm -rf $stage_dir
msg "change directories back to $start_dir"
cd $start_dir
msg "finished installing nginx."
else
msg "Nginx already installed, skipping this step."
fi
}
build_profile(){
cat > $start_dir/profile << EOF
export PATH="$nginx_install_dir/sbin:$PATH"
EOF
}
install_application() {
msg "change directories to $start_dir"
cd $start_dir
msg "moving $start_dir/profile to ~/"
mv $start_dir/profile ~/
# Use ~/code and ~/current like the regular python service for better compatibility
msg "installing application to ~/current/ from $start_dir"
rsync -avH --delete --exclude "data" --exclude "README.rst" * ~/current/
}
# lets get started.
msg "Step 0: getting ready for build::"
move_to_approot
# If you want to rebuild nginx from scratch and remove a previously good compile
# uncomment this. Don't do this everytime, or else each build will be slow.
# msg "Step 1A: cleaup old nginx build::"
# clean_nginx
msg "Step 1: install nginx::"
install_nginx
msg "Step 2: build profile::"
build_profile
msg "Step 3: install application::"
install_application
msg "All done..."
# template for nginx.conf file.
# the file will be processed by the postinstall script
# it will insert the correct value for PORT_WWW and then put this
# file in /home/dotcloud/nginx/conf/nginx.conf when done.
# nginx will be managed by supervisord when it starts so we don't need daemon mode
daemon off;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
# PORT_WWW value is added via postinstall script. DON'T TOUCH unless you know what you are doing or it may not work.
listen @PORT_WWW@ default;
server_name localhost;
log_format combined-realip '$remote_addr ($http_x_real_ip) - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /var/log/supervisor/nginx_access.log combined-realip;
error_log /var/log/supervisor/nginx_error.log error;
root /home/dotcloud/current/static;
location / {
if ( -f /home/dotcloud/current/maintenance) {
return 503;
}
}
location ~ /.+\.git/ {
dav_access group:rw all:rw;
create_full_put_path on;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
}
error_page 404 @404;
error_page 500 @500;
error_page 502 @502;
error_page 503 @503;
error_page 504 @504;
location @404 {
rewrite ^ /static/404.html;
}
location @500 {
rewrite ^ /static/500.html;
}
location @502 {
rewrite ^ /static/502.html;
}
location @503 {
rewrite ^ /static/503.html;
}
location @504 {
rewrite ^ /static/504.html;
}
location /static {
alias /home/dotcloud/current/static;
}
location /robots.txt {
alias /home/dotcloud/current/static/robots.txt;
}
location /favicon.ico {
alias /home/dotcloud/current/static/favicon.ico;
}
include /home/dotcloud/current/*nginx.conf;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment