Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit 5a411952e3bd0f9ffb4340aa9c0942a289d5ccc0 0 parents
@zmsmith zmsmith authored
8 README.rdoc
@@ -0,0 +1,8 @@
+= DESCRIPTION:
+
+= REQUIREMENTS:
+
+= ATTRIBUTES:
+
+= USAGE:
+
2  attributes/default.rb
@@ -0,0 +1,2 @@
+default['prompt_color'] = 32
+default['branch'] = 'master'
29 metadata.json
@@ -0,0 +1,29 @@
+{
+ "dependencies": {
+ },
+ "name": "djangoquickstart",
+ "maintainer_email": "YOUR_EMAIL",
+ "attributes": {
+ },
+ "license": "All rights reserved",
+ "suggestions": {
+ },
+ "platforms": {
+ },
+ "maintainer": "YOUR_COMPANY_NAME",
+ "long_description": "= DESCRIPTION:\n\n= REQUIREMENTS:\n\n= ATTRIBUTES:\n\n= USAGE:\n\n",
+ "version": "0.0.1",
+ "recommendations": {
+ },
+ "recipes": {
+ },
+ "groupings": {
+ },
+ "conflicting": {
+ },
+ "replacing": {
+ },
+ "description": "Installs/Configures yipit",
+ "providing": {
+ }
+}
8 metadata.rb
@@ -0,0 +1,8 @@
+maintainer "Yipit"
+maintainer_email "coders@yipit.com"
+license "All rights reserved"
+description "Installs a django project to EC2"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version "0.0.1"
+depends "python"
+
41 providers/build_repo.rb
@@ -0,0 +1,41 @@
+action :add do
+
+ repo = new_resource.repo
+ branch = new_resource.branch
+ app_name = new_resource.app_name
+ env_root = new_resource.env_root
+
+ env_name = "#{app_name}-env"
+ project_home = "#{env_root}/#{env_name}"
+
+ puts "#{env_root}"
+ puts "#{app_name}-env"
+
+
+ directory "#{env_root}" do
+ owner "ubuntu"
+ group "ubuntu"
+ mode 0775
+ end
+
+ python_virtualenv "#{project_home}" do
+ owner "ubuntu"
+ group "ubuntu"
+ interpreter "python2.7"
+ action :create
+ end
+
+ repo_address = "https://github.com/#{repo}.git"
+
+ execute "git_clone" do
+ command "git clone #{repo_address} #{app_name} -b #{new_resource.branch}"
+ user "ubuntu"
+ cwd project_home
+ end
+
+ execute "#{project_home}/bin/pip install -r conf/external_apps.txt" do
+ user "ubuntu"
+ cwd "#{project_home}/#{app_name}"
+ end
+
+end
12 recipes/admin.rb
@@ -0,0 +1,12 @@
+cron "chronograph" do
+ user "ubuntu"
+ command "#{node.project}/scripts/chronograph.sh #{node.project}"
+end
+
+template "/etc/supervisor/conf.d/sentry_server.conf" do
+ local true
+ source "#{node.project}/conf/sentry/sentry.conf"
+ owner "root"
+ group "root"
+ notifies :run, resources(:execute => "supervisor update")
+end
20 recipes/app.rb
@@ -0,0 +1,20 @@
+#
+# Cookbook Name:: yipit
+# Recipe:: default
+#
+# Copyright 2011, YOUR_COMPANY_NAME
+#
+# All rights reserved - Do Not Redistribute
+#
+['libgeos-3.2.0', 'libmysqlclient-dev', 'git-core', 'mercurial', 'mysql-client',
+'openjdk-6-jdk','postfix', 'python-gdal','python-imaging'].each do |pkg|
+ package pkg do
+ :install
+ end
+end
+
+build_repo node.branch do
+ action :add
+ settings node.settings
+ not_if { File.directory? node.project }
+end
115 recipes/base.rb
@@ -0,0 +1,115 @@
+#
+# Cookbook Name:: yipit
+# Recipe:: default
+#
+# Copyright 2011, YOUR_COMPANY_NAME
+#
+# All rights reserved - Do Not Redistribute
+#
+
+['binutils', 'chkconfig', 'libcurl4-gnutls-dev', 'libxslt1-dev',
+'ntp','python-dev', 'python-setproctitle','python-virtualenv', 'python-setuptools', 'rubygems', 'vim'].each do |pkg|
+ package pkg do
+ :install
+ end
+end
+
+authorized_users = node['authorized_users']
+public_keys = data_bag_item('public_keys', 'public_keys')
+authorized_keys = public_keys.values_at(*authorized_users)
+
+template "/home/ubuntu/.ssh/authorized_keys" do
+ source "authorized_keys.erb"
+ mode 0644
+ owner "ubuntu"
+ group "ubuntu"
+ variables(
+ :authorized_keys => authorized_keys
+ )
+ only_if { authorized_keys.any? }
+end
+
+python_pip "elementtree" do
+ action :install
+end
+
+package "supervisor" do
+ action :install
+end
+
+execute "supervisor update" do
+ command "sudo supervisorctl reread && sudo supervisorctl update"
+ action :nothing
+end
+
+template "/home/ubuntu/.bashrc" do
+ source "bashrc.erb"
+ mode 0644
+ owner "ubuntu"
+ group "ubuntu"
+ variables(
+ :role => node.name,
+ :instance_id => node.ec2.instance_id,
+ :prompt_color => node.prompt_color,
+ :project_directory => node.project)
+end
+
+template "/home/ubuntu/.vimrc" do
+ source "vimconfig.erb"
+ mode 0644
+ owner "ubuntu"
+ group "ubuntu"
+end
+
+template "/etc/rsyslog.d/papertrail.conf" do
+ source "papertrail.conf.erb"
+ owner "root"
+ group "root"
+ notifies :restart, "service[rsyslog]"
+end
+
+service "rsyslog" do
+ supports :restart => true, :reload => true
+ action :enable
+end
+
+gem_package "remote_syslog"
+
+template "/etc/log_files.yml" do
+ source "log_files.yml.erb"
+ owner "root"
+ group "root"
+ variables(:hostname => node.name)
+ notifies :run, resources(:execute => "supervisor update")
+end
+
+template "/etc/supervisor/conf.d/remote_syslog_supervisor.conf" do
+ source "remote_syslog_supervisor.conf.erb"
+ owner "root"
+ group "root"
+ notifies :run, resources(:execute => "supervisor update")
+end
+
+include_recipe "mongodb::10gen_repo"
+
+node[:mongodb][:dbpath] = "/var/lib/mongodb"
+node[:mongodb][:logpath] = "/var/log/mongodb"
+node[:mongodb][:port] = 27017
+node[:mongodb][:shard_name] = node.name
+node[:mongodb][:sharded_collections] = {'yipit_staging.dealuser'=> 'value.deal_id', 'yipit_staging.email_log'=> 'user_id'}
+
+template "/etc/apt/apt.conf.d/50unattended-upgrades" do
+ source "50unattended-upgrades.erb"
+ owner "root"
+ group "root"
+ notifies :run, resources(:execute => "supervisor update")
+end
+
+template "/etc/apt/apt.conf.d/02periodic" do
+ source "02periodic.erb"
+ owner "root"
+ group "root"
+ notifies :run, resources(:execute => "supervisor update")
+end
+
+
85 recipes/default.rb
@@ -0,0 +1,85 @@
+#
+# Cookbook Name:: yipit
+# Recipe:: default
+#
+# Copyright 2011, YOUR_COMPANY_NAME
+#
+# All rights reserved - Do Not Redistribute
+#
+
+
+node.env_name = "#{node.app_name}-env"
+node.project_home = "#{node.env_root}/#{node.env_name}"
+node.app_home = "#{node.project_home}/#{node.app_name}"
+
+['binutils', 'chkconfig', 'libcurl4-gnutls-dev', 'libxslt1-dev',
+'ntp','python-dev','python-virtualenv', 'python-setuptools', 'rubygems', 'vim', 'git'].each do |pkg|
+ package pkg do
+ :install
+ end
+end
+
+python_pip "elementtree" do
+ action :install
+end
+
+package "supervisor" do
+ action :install
+end
+
+execute "supervisor update" do
+ command "sudo supervisorctl reread && sudo supervisorctl update"
+ action :nothing
+end
+
+template "/home/ubuntu/.bashrc" do
+ source "bashrc.erb"
+ mode 0644
+ owner "ubuntu"
+ group "ubuntu"
+ variables(
+ :role => node.name,
+ :instance_id => node.ec2.instance_id,
+ :prompt_color => node.prompt_color)
+end
+
+djangoquickstart_build_repo node.branch do
+ action :add
+ settings node.settings
+ repo node.repo
+ app_name node.app_name
+ env_root node.env_root
+ not_if { File.directory? node.project_home }
+end
+
+package "nginx" do
+ :install
+end
+
+template "/etc/nginx/sites-enabled/default" do
+ source "nginx-default.erb"
+ owner "root"
+ group "root"
+ variables(
+ :domain => node.site_domain,
+ :project_home => node.project_home)
+ notifies :restart, "service[nginx]"
+end
+
+service 'nginx' do
+ supports :restart => true, :reload => true
+ action :enable
+end
+
+template "/etc/supervisor/conf.d/gunicorn.conf" do
+ source "gunicorn.conf.erb"
+ owner "root"
+ group "root"
+ variables(
+ :domain => node.site_domain,
+ :project_env => node.project_home,
+ :settings => "#{node.app_home}/settings/__init__.py",
+ :conf => "#{node.app_home}/conf/gunicorn/gunicorn.conf")
+ notifies :run, resources(:execute => "supervisor update")
+end
+
7 resources/build_repo.rb
@@ -0,0 +1,7 @@
+actions :add
+
+attribute :settings, :kind_of => String
+attribute :branch, :kind_of => String, :name_attribute => true
+attribute :repo, :kind_of => String
+attribute :app_name, :kind_of => String
+attribute :env_root, :kind_of => String
108 templates/default/bashrc.erb
@@ -0,0 +1,108 @@
+# ~/.bashrc: executed by bash(1) for non-login shells.
+# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
+# for examples
+
+# If not running interactively, don't do anything
+[ -z "$PS1" ] && return
+
+# don't put duplicate lines in the history. See bash(1) for more options
+# ... or force ignoredups and ignorespace
+HISTCONTROL=ignoredups:ignorespace
+
+# append to the history file, don't overwrite it
+shopt -s histappend
+
+# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
+HISTSIZE=1000
+HISTFILESIZE=2000
+
+# check the window size after each command and, if necessary,
+# update the values of LINES and COLUMNS.
+shopt -s checkwinsize
+
+# make less more friendly for non-text input files, see lesspipe(1)
+[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
+
+# set variable identifying the chroot you work in (used in the prompt below)
+if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
+ debian_chroot=$(cat /etc/debian_chroot)
+fi
+
+# set a fancy prompt (non-color, unless we know we "want" color)
+case "$TERM" in
+ xterm-color) color_prompt=yes;;
+esac
+
+case "$TERM" in
+ xterm-256color) color_prompt=yes;;
+esac
+
+
+# uncomment for a colored prompt, if the terminal has the capability; turned
+# off by default to not distract the user: the focus in a terminal window
+# should be on the output of commands, not on the prompt
+#force_color_prompt=yes
+
+if [ -n "$force_color_prompt" ]; then
+ if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
+ # We have color support; assume it's compliant with Ecma-48
+ # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
+ # a case would tend to support setf rather than setaf.)
+ color_prompt=yes
+ else
+ color_prompt=
+ fi
+fi
+
+if [ "$color_prompt" = yes ]; then
+ PS1='${debian_chroot:+($debian_chroot)}\[\033[01;<%= @prompt_color %>m\]<%= @role %>(<%= @instance_id %>)\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
+else
+ PS1='${debian_chroot:+($debian_chroot)}<%= @role %>(<%= @instance_id %>):\w\$ '
+fi
+unset color_prompt force_color_prompt
+
+# If this is an xterm set the title to user@host:dir
+case "$TERM" in
+xterm*|rxvt*)
+ PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
+ ;;
+*)
+ ;;
+esac
+
+# enable color support of ls and also add handy aliases
+if [ -x /usr/bin/dircolors ]; then
+ test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
+ alias ls='ls --color=auto'
+ #alias dir='dir --color=auto'
+ #alias vdir='vdir --color=auto'
+
+ alias grep='grep --color=auto'
+ alias fgrep='fgrep --color=auto'
+ alias egrep='egrep --color=auto'
+fi
+
+# some more ls aliases
+alias ll='ls -alF'
+alias la='ls -A'
+alias l='ls -CF'
+
+# Add an "alert" alias for long running commands. Use like so:
+# sleep 10; alert
+alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
+
+# Alias definitions.
+# You may want to put all your additions into a separate file like
+# ~/.bash_aliases, instead of adding them here directly.
+# See /usr/share/doc/bash-doc/examples in the bash-doc package.
+
+if [ -f ~/.bash_aliases ]; then
+ . ~/.bash_aliases
+fi
+
+# enable programmable completion features (you don't need to enable
+# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
+# sources /etc/bash.bashrc).
+if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
+ . /etc/bash_completion
+fi
11 templates/default/gunicorn.conf.erb
@@ -0,0 +1,11 @@
+[program:<%= @domain %>]
+
+command=<%= @project_env %>/bin/gunicorn_django -c <%= @conf %> -b unix:/tmp/gunicorn_<%= @domain %>.sock <%= @settings %> --workers=2 --timeout=30
+user=ubuntu
+group=ubuntu
+log-level=debug
+autostart=true
+autorestart=true
+redirect_stderr=True
+stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log
+stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log
2  templates/default/known_hosts.erb
@@ -0,0 +1,2 @@
+|1|7CYLxaXFX2v9ywlWEEXXARtzetQ=|WwMR6cDW2NTsQqpabDbXwRU+q1E= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
+|1|I4mq71hxsuwk5TlJQQwnhWhoOCI=|8p/PGIEdwK5G11I076Q42AeT0qE= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
49 templates/default/nginx-default.erb
@@ -0,0 +1,49 @@
+upstream <%= @domain %> {
+ server unix:/tmp/gunicorn_<%= @domain %>.sock;
+}
+
+#Rewrite www.<%= @domain %> to <%= @domain %>
+server {
+ server_name www.<%= @domain %>;
+ rewrite ^(.*) http://<%= @domain %>$1 permanent;
+}
+
+server {
+ listen 80 default_server;
+ listen 443;
+ server_name <%= @domain %>;
+
+ # deny all and then allow all explicitly where necessary
+ deny all;
+
+ # path for static files
+ root <%= @project_home %>/media;
+
+ location = /favicon.ico {
+ allow all;
+ alias <%= @project_home %>/media/favicon.ico;
+ }
+
+
+
+ location ^~ /admin_media {
+ allow all;
+ alias <%= @project_home %>/../lib/python2.7/site-packages/django/contrib/admin/media/;
+ }
+
+ location / {
+ access_log /var/log/nginx/access.log;
+ allow all;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_redirect off;
+ proxy_pass http://<%= @domain %>;
+ }
+
+ error_page 500 502 503 504 /500.html;
+ location = /500.html {
+ allow all;
+ alias <%= @project_home %>/templates/500.html;
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.