├── .gitmodules ├── .gitignore ├── http ├── virthost.conf ├── unicorn.rb ├── preseed.cfg └── nginx.conf ├── config ├── deploy │ ├── production.rb │ └── staging.rb └── deploy.rb ├── Vagrantfile ├── LICENSE ├── README.md ├── ubuntu-mysql.json ├── ubuntu-ruby-mysql.json ├── ubuntu-postgresql.json ├── ubuntu-ruby-postgresql.json ├── ubuntu-node.json ├── ubuntu-ruby.json ├── ubuntu-desktop.json ├── ubuntu-desktop-ros.json ├── ubuntu-devops.json ├── thegeec.json ├── microservices.json └── ubuntu.json /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "packer-shell-scripts"] 2 | path = packer-shell-scripts 3 | url = git@github.com:cloudspace-devops/packer-shell-scripts.git 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Cache objects 2 | packer_cache/ 3 | 4 | # For built boxes 5 | *.box 6 | output-virtualbox-iso/* 7 | virtualbox-* 8 | builds/* 9 | trash* 10 | .vagrant/* 11 | 12 | # Env variables 13 | env.json 14 | 15 | # OSX 16 | .DS_Store 17 | -------------------------------------------------------------------------------- /http/virthost.conf: -------------------------------------------------------------------------------- 1 | upstream app.com_unicorn { 2 | server unix:/srv/www/app/unicorn.sock fail_timeout=0; 3 | } 4 | 5 | server { 6 | listen 80; 7 | server_name app.com; 8 | client_max_body_size 1G; 9 | access_log /var/log/nginx/app.com-access.log; 10 | error_log /var/log/nginx/app.com-error.log; 11 | root /srv/www/app/current/public; 12 | try_files $uri $uri/index.html $uri.html @app; 13 | 14 | location @app { 15 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16 | proxy_set_header Host $host; 17 | proxy_pass http://app.com_unicorn; 18 | proxy_set_header X-Forwarded-Proto $scheme; 19 | } 20 | } 21 | 22 | server { 23 | listen 80; 24 | server_name www.app.com; 25 | rewrite ^/(.*) http://app.com/$1 permanent; 26 | } 27 | -------------------------------------------------------------------------------- /config/deploy/production.rb: -------------------------------------------------------------------------------- 1 | role :app, %W{#{ENV['APP_HOST']}} 2 | role :web, %W{#{ENV['APP_HOST']}} 3 | role :db, %W{#{ENV['APP_HOST']}} 4 | 5 | set :branch, 'master' 6 | set :rails_env, 'production' 7 | 8 | set :default_environment, 'RAILS_ENV' => 'production' 9 | 10 | set :application, "#{ENV['APP_NAME']}" 11 | 12 | set :deploy_to, "/srv/www/#{ENV['APP_NAME']}" 13 | 14 | namespace :deploy do 15 | task :start do 16 | on roles(:app) do 17 | execute "cd /srv/www/#{ENV['APP_NAME']}/current && "\ 18 | "sudo bundle exec unicorn -E production -c /etc/unicorn/#{ENV['APP_NAME']}.rb -D" 19 | end 20 | end 21 | 22 | task :stop do 23 | on roles(:app) do 24 | execute "sudo kill -QUIT $(cat /srv/www/#{ENV['APP_NAME']}/unicorn.pid)" 25 | end 26 | end 27 | 28 | task :restart do 29 | on roles(:app) do 30 | execute "sudo kill -USR2 $(cat /srv/www/#{ENV['APP_NAME']}/unicorn.pid)" 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | $domain_name = "packer.cloudspace.com" 2 | $vagrant_ip = "33.33.162.179" 3 | $box_name = "packer-virtualbox.box" 4 | # $box_path = "http://devops.cloudspace.com/images/" 5 | $box_path = "file:///srv/packer-image-scripts/builds/packer/" 6 | $cpus = 2 7 | $memory = 2048 8 | $buildbox = "../microservice" 9 | 10 | Vagrant.configure(2) do |config| 11 | org = $domain_name 12 | config.vm.box = $box_name 13 | config.vm.box_url = File.join($box_path, $box_name) 14 | config.ssh.private_key_path = ['./sample-client-config/devops/vagrant.pem', File.join(ENV['HOME'], '.ssh', 'id_rsa')] 15 | config.ssh.forward_agent = true 16 | config.vm.network "private_network", ip: $vagrant_ip 17 | config.vm.synced_folder $buildbox, "/srv/#{org}", :nfs => { :mount_options => ["dmode=777","fmode=777"] } 18 | 19 | config.vm.provider "virtualbox" do |v| 20 | v.customize ["modifyvm", :id, "--memory", $memory, "--name", $domain_name,"--cpus", $cpus] 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /config/deploy/staging.rb: -------------------------------------------------------------------------------- 1 | role :app, %W{#{ENV['STAGING_APP_HOST']}} 2 | role :web, %W{#{ENV['STAGING_APP_HOST']}} 3 | role :db, %W{#{ENV['STAGING_APP_HOST']}} 4 | 5 | set :branch, 'master' 6 | set :rails_env, 'staging' 7 | 8 | set :default_environment, 'RAILS_ENV' => 'staging' 9 | 10 | set :application, %W{#{ENV['STAGING_APP_NAME']}} 11 | 12 | set :deploy_to, "/srv/www/#{ENV['STAGING_APP_NAME']}" 13 | 14 | namespace :deploy do 15 | task :start do 16 | on roles(:app) do 17 | execute "cd /srv/www/#{ENV['STAGING_APP_NAME']}/current && "\ 18 | "sudo bundle exec unicorn -E staging -c /etc/unicorn/#{ENV['STAGING_APP_NAME']}.rb -D" 19 | end 20 | end 21 | 22 | task :stop do 23 | on roles(:app) do 24 | execute "sudo kill -QUIT $(cat /srv/www/#{ENV['STAGING_APP_NAME']}/unicorn.pid)" 25 | end 26 | end 27 | 28 | task :restart do 29 | on roles(:app) do 30 | execute "sudo kill -USR2 $(cat /srv/www/#{ENV['STAGING_APP_NAME']}/unicorn.pid)" 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 cloudspace-devops 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | -------------------------------------------------------------------------------- /http/unicorn.rb: -------------------------------------------------------------------------------- 1 | rails_env = ENV['RAILS_ENV'] || 'production' 2 | worker_processes 1 3 | preload_app true 4 | working_directory "/srv/www/app/current" 5 | listen "/srv/www/app/unicorn.sock", :backlog => 64 6 | listen 8080, :tcp_nopush => true 7 | timeout 30 8 | pid "/srv/www/app/unicorn.pid" 9 | stderr_path "/var/log/unicorn/stderr.log" 10 | stdout_path "/var/log/unicorn/stdout.log" 11 | preload_app true 12 | 13 | GC.respond_to?(:copy_on_write_friendly=) and 14 | GC.copy_on_write_friendly = true 15 | 16 | check_client_connection false 17 | 18 | before_exec do |server| 19 | ENV["BUNDLE_GEMFILE"] = "/srv/www/app/current/Gemfile" 20 | end 21 | 22 | before_fork do |server, worker| 23 | old_pid = '/srv/www/app/unicorn.pid.oldbin' 24 | if File.exists?(old_pid) && server.pid != old_pid 25 | begin 26 | Process.kill("QUIT", File.read(old_pid).to_i) 27 | rescue Errno::ENOENT, Errno::ESRCH 28 | end 29 | end 30 | defined?(ActiveRecord::Base) and 31 | ActiveRecord::Base.connection.disconnect! 32 | end 33 | 34 | after_fork do |server, worker| 35 | defined?(ActiveRecord::Base) and 36 | ActiveRecord::Base.establish_connection 37 | end 38 | -------------------------------------------------------------------------------- /http/preseed.cfg: -------------------------------------------------------------------------------- 1 | choose-mirror-bin mirror/http/proxy string 2 | d-i base-installer/kernel/override-image string linux-server 3 | d-i clock-setup/utc boolean true 4 | d-i clock-setup/utc-auto boolean true 5 | d-i finish-install/reboot_in_progress note 6 | d-i grub-installer/only_debian boolean true 7 | d-i partman-auto-lvm/guided_size string max 8 | d-i partman-auto/choose_recipe select atomic 9 | d-i partman-auto/method string lvm 10 | d-i partman-lvm/confirm boolean true 11 | d-i partman-lvm/confirm boolean true 12 | d-i partman-lvm/confirm_nooverwrite boolean true 13 | d-i partman-lvm/device_remove_lvm boolean true 14 | d-i partman/choose_partition select finish 15 | d-i partman/confirm boolean true 16 | d-i partman/confirm_nooverwrite boolean true 17 | d-i partman/confirm_write_new_label boolean true 18 | # Default user 19 | d-i passwd/user-fullname string vagrant 20 | d-i passwd/user-password password vagrant 21 | d-i passwd/user-password-again password vagrant 22 | d-i passwd/username string vagrant 23 | d-i user-setup/allow-password-weak boolean true 24 | d-i user-setup/encrypt-home boolean false 25 | 26 | d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms ntp curl 27 | d-i pkgsel/install-language-support boolean false 28 | d-i pkgsel/update-policy select none 29 | d-i pkgsel/upgrade select full-upgrade 30 | #d-i time/zone string UTC 31 | d-i time/zone string US/Eastern 32 | tasksel tasksel/first multiselect standard, ubuntu-server 33 | 34 | d-i finish-install/reboot_in_progress note -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cloudspace DevOps -- Packer 2 | 3 | The repo contains Clousdpace's scripts & configs to build client VMs (vagrant, AMIs, VMWare, etc.) with Packer.io. 4 | 5 | ## Default Builds 6 | 7 | For most projects you can use a default build and then customize as needed. Here are links to download default Vagrant (.box files), Virtualbox (.ovf & .vmdk), and aws (ami listed in .txt file) 8 | 9 | - Ubuntu: http://devops.cloudspace.com/images/?prefix=images/ubuntu/ 10 | - Ubuntu + MySQL: http://devops.cloudspace.com/images/?prefix=images/mysql/ 11 | - Ubuntu + NodeJS: http://devops.cloudspace.com/images/?prefix=images/node/ 12 | - Ubuntu + PostgreSQL: http://devops.cloudspace.com/images/?prefix=images/postgresql/ 13 | - Ubuntu + Ruby: http://devops.cloudspace.com/images/?prefix=images/ruby/ 14 | - Ubuntu + Ruby + MySQL: http://devops.cloudspace.com/images/?prefix=images/ruby-mysql/ 15 | - Ubuntu + Ruby + PostgreSQL: http://devops.cloudspace.com/images/?prefix=images/ruby-postgresql/ 16 | 17 | ## Building Packer Images 18 | 19 | 1. Set your AWS key/secret as an environment variable 20 | 21 | ``` 22 | export AWS_ACCESS_KEY_ID="xxxxxxxxx" 23 | export AWS_SECRET_ACCESS_KEY="xxxxxxx 24 | ``` 25 | 26 | 2. Create all base images 27 | 28 | ``` 29 | ./build-all.sh 30 | ``` 31 | 32 | 3. Run the desired individual build script 33 | 34 | ``` 35 | packer build build-name.json 36 | ``` 37 | 38 | 4. To create a custom project box, copy the closest match into the packer-projects folder, update the base image source, add/create the appropriate shell script(s), and run the build. 39 | -------------------------------------------------------------------------------- /ubuntu-mysql.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "mysql", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-66008e0e", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/mysql-server.sh" 20 | ], 21 | "pause_before": "4s" 22 | }], 23 | "builders": [{ 24 | "name": "aws", 25 | "type": "amazon-ebs", 26 | "access_key": "{{user `aws_access_key`}}", 27 | "secret_key": "{{user `aws_secret_key`}}", 28 | "region": "{{user `aws_region`}}", 29 | "source_ami": "{{user `aws_source_ami`}}", 30 | "instance_type": "{{user `aws_instance_type`}}", 31 | "ssh_username": "ubuntu", 32 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 33 | "ami_groups": ["all"], 34 | "security_group_id": "{{user `aws_security_group`}}", 35 | "tags": { 36 | "Name": "packer", 37 | "Name": "{{user `build_name`}}" 38 | }, 39 | "user_data": "" 40 | },{ 41 | "name": "virtualbox", 42 | "type": "virtualbox-ovf", 43 | "vm_name": "{{user `build_name`}}", 44 | "source_path": "./builds/{{user `base_box`}}", 45 | "output_directory": "./builds/{{user `build_name`}}", 46 | "ssh_username": "vagrant", 47 | "ssh_password": "vagrant", 48 | "ssh_wait_timeout": "20m", 49 | "shutdown_command": "sudo shutdown -P now" 50 | }], 51 | "post-processors": [{ 52 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 53 | "type": "vagrant", 54 | "keep_input_artifact": true, 55 | "only": ["virtualbox"] 56 | }] 57 | } 58 | -------------------------------------------------------------------------------- /ubuntu-ruby-mysql.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "ruby-mysql", 4 | "base_box": "ruby/ruby.ovf", 5 | "aws_source_ami": "ami-ae1c92c6", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/mysql-server.sh" 20 | ], 21 | "pause_before": "4s" 22 | }], 23 | "builders": [{ 24 | "name": "aws", 25 | "type": "amazon-ebs", 26 | "access_key": "{{user `aws_access_key`}}", 27 | "secret_key": "{{user `aws_secret_key`}}", 28 | "region": "{{user `aws_region`}}", 29 | "source_ami": "{{user `aws_source_ami`}}", 30 | "instance_type": "{{user `aws_instance_type`}}", 31 | "ssh_username": "ubuntu", 32 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 33 | "ami_groups": ["all"], 34 | "security_group_id": "{{user `aws_security_group`}}", 35 | "tags": { 36 | "Name": "packer", 37 | "Name": "{{user `build_name`}}" 38 | }, 39 | "user_data": "" 40 | },{ 41 | "name": "virtualbox", 42 | "type": "virtualbox-ovf", 43 | "vm_name": "{{user `build_name`}}", 44 | "source_path": "./builds/{{user `base_box`}}", 45 | "output_directory": "./builds/{{user `build_name`}}", 46 | "ssh_username": "vagrant", 47 | "ssh_password": "vagrant", 48 | "ssh_wait_timeout": "20m", 49 | "shutdown_command": "sudo shutdown -P now" 50 | }], 51 | "post-processors": [{ 52 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 53 | "type": "vagrant", 54 | "keep_input_artifact": true, 55 | "only": ["virtualbox"] 56 | }] 57 | } 58 | -------------------------------------------------------------------------------- /ubuntu-postgresql.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "postgresql", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-889260e0", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/postgresql-server.sh" 20 | ], 21 | "pause_before": "4s" 22 | }], 23 | "builders": [{ 24 | "name": "aws", 25 | "type": "amazon-ebs", 26 | "access_key": "{{user `aws_access_key`}}", 27 | "secret_key": "{{user `aws_secret_key`}}", 28 | "region": "{{user `aws_region`}}", 29 | "source_ami": "{{user `aws_source_ami`}}", 30 | "instance_type": "{{user `aws_instance_type`}}", 31 | "ssh_username": "ubuntu", 32 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 33 | "ami_groups": ["all"], 34 | "security_group_id": "{{user `aws_security_group`}}", 35 | "tags": { 36 | "Name": "packer", 37 | "Name": "{{user `build_name`}}" 38 | }, 39 | "user_data": "" 40 | },{ 41 | "name": "virtualbox", 42 | "type": "virtualbox-ovf", 43 | "vm_name": "{{user `build_name`}}", 44 | "source_path": "./builds/{{user `base_box`}}", 45 | "output_directory": "./builds/{{user `build_name`}}", 46 | "ssh_username": "vagrant", 47 | "ssh_password": "vagrant", 48 | "ssh_wait_timeout": "20m", 49 | "shutdown_command": "sudo shutdown -P now" 50 | }], 51 | "post-processors": [{ 52 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 53 | "type": "vagrant", 54 | "keep_input_artifact": true, 55 | "only": ["virtualbox"] 56 | }] 57 | } 58 | -------------------------------------------------------------------------------- /ubuntu-ruby-postgresql.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "ruby-postgresql", 4 | "base_box": "ruby/ruby.ovf", 5 | "aws_source_ami": "ami-ae1c92c6", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/postgresql-server.sh" 20 | ], 21 | "pause_before": "4s" 22 | }], 23 | "builders": [{ 24 | "name": "aws", 25 | "type": "amazon-ebs", 26 | "access_key": "{{user `aws_access_key`}}", 27 | "secret_key": "{{user `aws_secret_key`}}", 28 | "region": "{{user `aws_region`}}", 29 | "source_ami": "{{user `aws_source_ami`}}", 30 | "instance_type": "{{user `aws_instance_type`}}", 31 | "ssh_username": "ubuntu", 32 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 33 | "ami_groups": ["all"], 34 | "security_group_id": "{{user `aws_security_group`}}", 35 | "tags": { 36 | "Name": "packer", 37 | "Name": "{{user `build_name`}}" 38 | }, 39 | "user_data": "" 40 | },{ 41 | "name": "virtualbox", 42 | "type": "virtualbox-ovf", 43 | "vm_name": "{{user `build_name`}}", 44 | "source_path": "./builds/{{user `base_box`}}", 45 | "output_directory": "./builds/{{user `build_name`}}", 46 | "ssh_username": "vagrant", 47 | "ssh_password": "vagrant", 48 | "ssh_wait_timeout": "20m", 49 | "shutdown_command": "sudo shutdown -P now" 50 | }], 51 | "post-processors": [{ 52 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 53 | "type": "vagrant", 54 | "keep_input_artifact": true, 55 | "only": ["virtualbox"] 56 | }] 57 | } 58 | -------------------------------------------------------------------------------- /ubuntu-node.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "node", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-22a2504a", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/node.sh", 20 | "packer-shell-scripts/yeoman.sh", 21 | "packer-shell-scripts/memcached.sh" 22 | ], 23 | "pause_before": "4s" 24 | }], 25 | "builders": [{ 26 | "name": "aws", 27 | "type": "amazon-ebs", 28 | "access_key": "{{user `aws_access_key`}}", 29 | "secret_key": "{{user `aws_secret_key`}}", 30 | "region": "{{user `aws_region`}}", 31 | "source_ami": "{{user `aws_source_ami`}}", 32 | "instance_type": "{{user `aws_instance_type`}}", 33 | "ssh_username": "ubuntu", 34 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 35 | "ami_groups": ["all"], 36 | "security_group_id": "{{user `aws_security_group`}}", 37 | "tags": { 38 | "Name": "packer", 39 | "Name": "{{user `build_name`}}" 40 | }, 41 | "user_data": "" 42 | },{ 43 | "name": "virtualbox", 44 | "type": "virtualbox-ovf", 45 | "vm_name": "{{user `build_name`}}", 46 | "source_path": "./builds/{{user `base_box`}}", 47 | "output_directory": "./builds/{{user `build_name`}}", 48 | "ssh_username": "{{user `username`}}", 49 | "ssh_password": "{{user `password`}}", 50 | "ssh_wait_timeout": "20m", 51 | "shutdown_command": "sudo shutdown -P now" 52 | }], 53 | "post-processors": [{ 54 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 55 | "type": "vagrant", 56 | "keep_input_artifact": true, 57 | "only": ["virtualbox"] 58 | }] 59 | } 60 | -------------------------------------------------------------------------------- /ubuntu-ruby.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "ruby", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-66008e0e", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/node.sh", 20 | "packer-shell-scripts/ruby.sh", 21 | "packer-shell-scripts/imagemagick.sh", 22 | "packer-shell-scripts/nginx.sh" 23 | ], 24 | "pause_before": "4s" 25 | }], 26 | "builders": [{ 27 | "name": "aws", 28 | "type": "amazon-ebs", 29 | "access_key": "{{user `aws_access_key`}}", 30 | "secret_key": "{{user `aws_secret_key`}}", 31 | "region": "{{user `aws_region`}}", 32 | "source_ami": "{{user `aws_source_ami`}}", 33 | "instance_type": "{{user `aws_instance_type`}}", 34 | "ssh_username": "ubuntu", 35 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 36 | "ami_groups": ["all"], 37 | "security_group_id": "{{user `aws_security_group`}}", 38 | "tags": { 39 | "Name": "packer", 40 | "Name": "{{user `build_name`}}" 41 | }, 42 | "user_data": "" 43 | },{ 44 | "name": "virtualbox", 45 | "type": "virtualbox-ovf", 46 | "vm_name": "{{user `build_name`}}", 47 | "source_path": "./builds/{{user `base_box`}}", 48 | "output_directory": "./builds/{{user `build_name`}}", 49 | "ssh_username": "vagrant", 50 | "ssh_password": "vagrant", 51 | "ssh_wait_timeout": "20m", 52 | "shutdown_command": "sudo shutdown -P now" 53 | }], 54 | "post-processors": [{ 55 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 56 | "type": "vagrant", 57 | "keep_input_artifact": true, 58 | "only": ["virtualbox"] 59 | }] 60 | } 61 | -------------------------------------------------------------------------------- /ubuntu-desktop.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "desktop", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-889260e0", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "g2.2xlarge", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/desktop.sh" 20 | ], 21 | "pause_before": "4s" 22 | }], 23 | "builders": [{ 24 | "name": "aws", 25 | "type": "amazon-ebs", 26 | "access_key": "{{user `aws_access_key`}}", 27 | "secret_key": "{{user `aws_secret_key`}}", 28 | "region": "{{user `aws_region`}}", 29 | "source_ami": "{{user `aws_source_ami`}}", 30 | "instance_type": "{{user `aws_instance_type`}}", 31 | "ssh_username": "ubuntu", 32 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 33 | "ami_groups": ["all"], 34 | "security_group_id": "{{user `aws_security_group`}}", 35 | "tags": { 36 | "Name": "packer", 37 | "Name": "{{user `build_name`}}" 38 | }, 39 | "user_data": "" 40 | },{ 41 | "name": "virtualbox", 42 | "type": "virtualbox-ovf", 43 | "vm_name": "{{user `build_name`}}", 44 | "source_path": "./builds/{{user `base_box`}}", 45 | "output_directory": "./builds/{{user `build_name`}}", 46 | "ssh_username": "vagrant", 47 | "ssh_password": "vagrant", 48 | "ssh_wait_timeout": "20m", 49 | "shutdown_command": "sudo shutdown -P now" 50 | }], 51 | "post-processors": [{ 52 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 53 | "type": "vagrant", 54 | "keep_input_artifact": true, 55 | "only": ["virtualbox"] 56 | }] 57 | } 58 | -------------------------------------------------------------------------------- /ubuntu-desktop-ros.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "desktop-ros", 4 | "base_box": "desktop/desktop.ovf", 5 | "aws_source_ami": "ami-3244d45a", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "g2.2xlarge", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/ros-indigo.sh" 20 | ], 21 | "pause_before": "4s" 22 | }], 23 | "builders": [{ 24 | "name": "aws", 25 | "type": "amazon-ebs", 26 | "access_key": "{{user `aws_access_key`}}", 27 | "secret_key": "{{user `aws_secret_key`}}", 28 | "region": "{{user `aws_region`}}", 29 | "source_ami": "{{user `aws_source_ami`}}", 30 | "instance_type": "{{user `aws_instance_type`}}", 31 | "ssh_username": "ubuntu", 32 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 33 | "ami_groups": ["all"], 34 | "security_group_id": "{{user `aws_security_group`}}", 35 | "tags": { 36 | "Name": "packer", 37 | "Name": "{{user `build_name`}}" 38 | }, 39 | "user_data": "" 40 | },{ 41 | "name": "virtualbox", 42 | "type": "virtualbox-ovf", 43 | "vm_name": "{{user `build_name`}}", 44 | "source_path": "./builds/{{user `base_box`}}", 45 | "output_directory": "./builds/{{user `build_name`}}", 46 | "ssh_username": "vagrant", 47 | "ssh_password": "vagrant", 48 | "ssh_wait_timeout": "20m", 49 | "shutdown_command": "sudo shutdown -P now" 50 | }], 51 | "post-processors": [{ 52 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 53 | "type": "vagrant", 54 | "keep_input_artifact": true, 55 | "only": ["virtualbox"] 56 | }] 57 | } 58 | -------------------------------------------------------------------------------- /ubuntu-devops.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "devops", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-22a2504a", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/packer.sh", 20 | "packer-shell-scripts/docker.sh", 21 | "packer-shell-scripts/go-lang.sh" 22 | ], 23 | "pause_before": "4s" 24 | }], 25 | "builders": [{ 26 | "name": "aws", 27 | "type": "amazon-ebs", 28 | "access_key": "{{user `aws_access_key`}}", 29 | "secret_key": "{{user `aws_secret_key`}}", 30 | "region": "{{user `aws_region`}}", 31 | "source_ami": "{{user `aws_source_ami`}}", 32 | "instance_type": "{{user `aws_instance_type`}}", 33 | "ssh_username": "ubuntu", 34 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 35 | "ami_groups": ["all"], 36 | "security_group_id": "{{user `aws_security_group`}}", 37 | "tags": { 38 | "Name": "packer", 39 | "Name": "{{user `build_name`}}" 40 | }, 41 | "user_data": "" 42 | },{ 43 | "name": "virtualbox", 44 | "type": "virtualbox-ovf", 45 | "vm_name": "{{user `build_name`}}", 46 | "source_path": "./builds/{{user `base_box`}}", 47 | "output_directory": "./builds/{{user `build_name`}}", 48 | "ssh_username": "{{user `username`}}", 49 | "ssh_password": "{{user `password`}}", 50 | "ssh_wait_timeout": "20m", 51 | "shutdown_command": "sudo shutdown -P now" 52 | }], 53 | "post-processors": [{ 54 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}-virtualbox.box", 55 | "type": "vagrant", 56 | "keep_input_artifact": true, 57 | "only": ["virtualbox"] 58 | },{ 59 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}-aws.box", 60 | "type": "vagrant", 61 | "keep_input_artifact": true, 62 | "only": ["aws"] 63 | }] 64 | } 65 | -------------------------------------------------------------------------------- /thegeec.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "thegeec", 4 | "base_box": "ubuntu/ubuntu.ovf", 5 | "aws_source_ami": "ami-66008e0e", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "inline": ["sudo apt-get install -y xvfb libqtwebkit-dev libevent-pthreads-2.0-5 libstdc++6"], 19 | "pause_before": "4s" 20 | },{ 21 | "type": "shell", 22 | "scripts": [ 23 | "packer-shell-scripts/upgrade.sh", 24 | "packer-shell-scripts/docker.sh" 25 | ], 26 | "pause_before": "4s" 27 | }], 28 | "builders": [{ 29 | "name": "aws", 30 | "type": "amazon-ebs", 31 | "access_key": "{{user `aws_access_key`}}", 32 | "secret_key": "{{user `aws_secret_key`}}", 33 | "region": "{{user `aws_region`}}", 34 | "source_ami": "{{user `aws_source_ami`}}", 35 | "instance_type": "{{user `aws_instance_type`}}", 36 | "ssh_username": "ubuntu", 37 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 38 | "ami_groups": ["all"], 39 | "security_group_id": "{{user `aws_security_group`}}", 40 | "tags": { 41 | "Name": "packer", 42 | "Name": "{{user `build_name`}}" 43 | }, 44 | "user_data": "" 45 | },{ 46 | "name": "virtualbox", 47 | "type": "virtualbox-ovf", 48 | "vm_name": "{{user `build_name`}}", 49 | "source_path": "./builds/{{user `base_box`}}", 50 | "output_directory": "./builds/{{user `build_name`}}", 51 | "ssh_username": "vagrant", 52 | "ssh_password": "vagrant", 53 | "ssh_wait_timeout": "20m", 54 | "shutdown_command": "sudo shutdown -P now" 55 | }], 56 | "post-processors": [{ 57 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 58 | "type": "vagrant", 59 | "keep_input_artifact": true, 60 | "only": ["virtualbox"] 61 | }] 62 | } 63 | -------------------------------------------------------------------------------- /microservices.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "microservices", 4 | "base_box": "ruby-mysql/ruby-mysql.ovf", 5 | "aws_source_ami": "ami-4279e02a", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "inline": ["sudo apt-get install -y xvfb libqtwebkit-dev libevent-pthreads-2.0-5 libstdc++6"], 19 | "pause_before": "4s" 20 | },{ 21 | "type": "shell", 22 | "scripts": [ 23 | "packer-shell-scripts/go-lang.sh", 24 | "packer-shell-scripts/fleetctl.sh" 25 | ], 26 | "pause_before": "4s" 27 | }], 28 | "builders": [{ 29 | "name": "aws", 30 | "type": "amazon-ebs", 31 | "access_key": "{{user `aws_access_key`}}", 32 | "secret_key": "{{user `aws_secret_key`}}", 33 | "region": "{{user `aws_region`}}", 34 | "source_ami": "{{user `aws_source_ami`}}", 35 | "instance_type": "{{user `aws_instance_type`}}", 36 | "ssh_username": "ubuntu", 37 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 38 | "ami_groups": ["all"], 39 | "security_group_id": "{{user `aws_security_group`}}", 40 | "tags": { 41 | "Name": "packer", 42 | "Name": "{{user `build_name`}}" 43 | }, 44 | "user_data": "" 45 | },{ 46 | "name": "virtualbox", 47 | "type": "virtualbox-ovf", 48 | "vm_name": "{{user `build_name`}}", 49 | "source_path": "./builds/{{user `base_box`}}", 50 | "output_directory": "./builds/{{user `build_name`}}", 51 | "ssh_username": "vagrant", 52 | "ssh_password": "vagrant", 53 | "ssh_wait_timeout": "20m", 54 | "shutdown_command": "sudo shutdown -P now" 55 | }], 56 | "post-processors": [{ 57 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 58 | "type": "vagrant", 59 | "keep_input_artifact": true, 60 | "only": ["virtualbox"] 61 | }] 62 | } 63 | -------------------------------------------------------------------------------- /config/deploy.rb: -------------------------------------------------------------------------------- 1 | # config valid only for Capistrano 3.1 2 | #lock '3.1.0' 3 | 4 | # the repository url is set in config/environment_variables.rb 5 | set :repo_url, %W{#{ENV['REPOSITORY_URL']}} 6 | 7 | set :stages, %w(staging production) 8 | set :default_stage, 'staging' 9 | 10 | # Default branch is :master 11 | # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } 12 | 13 | # Default value for :scm is :git 14 | set :scm, :git 15 | 16 | # Default value for :format is :pretty 17 | set :format, :pretty 18 | 19 | # Default value for :log_level is :debug 20 | set :log_level, :debug 21 | 22 | # Default value for :pty is false 23 | # set :pty, true 24 | 25 | # Default value for :linked_files is [] 26 | set :linked_files, %w{.env} 27 | 28 | # Default value for linked_dirs is [] 29 | # set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} 30 | set :linked_dirs, %w{log} 31 | 32 | # Default value for default_env is {} 33 | # set :default_env, { path: "/opt/ruby/bin:$PATH" } 34 | 35 | # Default value for keep_releases is 5 36 | set :keep_releases, 5 37 | 38 | set :ssh_options, keys: ['~/.ssh/id_rsa'], forward_agent: true, user: %W{#{ENV['USER']}} 39 | 40 | namespace :deploy do 41 | desc 'Restart application' 42 | task :restart do 43 | on roles(:app), in: :sequence, wait: 5 do 44 | # Your restart mechanism here, for example: 45 | # execute :touch, release_path.join('tmp/restart.txt') 46 | end 47 | end 48 | 49 | after :publishing, :restart 50 | 51 | # after :restart, :clear_cache do 52 | # on roles(:web), in: :groups, limit: 3, wait: 10 do 53 | # # Here we can do anything such as: 54 | # # within release_path do 55 | # # execute :rake, 'cache:clear' 56 | # # end 57 | # end 58 | # end 59 | end 60 | 61 | after 'deploy', 'bundler:install' 62 | 63 | # runs the specified rake task on the server in the background, without blocking the ssh session 64 | def background_rake(task) 65 | on roles(:app) do 66 | execute "cd #{release_path}; ( ( nohup bundle exec rake RAILS_ENV=#{fetch(:rails_env)} #{task} &>/dev/null ) & )" 67 | end 68 | end 69 | 70 | # runs the specified rake task on the server in the foreground, blocking the ssh session 71 | def foreground_rake(task) 72 | on roles(:app) do 73 | execute "cd #{release_path} && bundle exec rake RAILS_ENV=#{fetch(:rails_env)} #{task}" 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /ubuntu.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "build_name": "ubuntu", 4 | "iso_url": "http://releases.ubuntu.com/14.04/ubuntu-14.04.2-server-amd64.iso", 5 | "aws_source_ami": "ami-c8cf3ba0", 6 | "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", 7 | "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", 8 | "aws_account_id": "884882099534", 9 | "aws_region": "us-east-1", 10 | "aws_instance_type": "c3.large", 11 | "aws_s3_bucket": "devops.cloudspace.com", 12 | "aws_security_group": "default", 13 | "username": "vagrant", 14 | "password": "vagrant" 15 | }, 16 | "provisioners": [{ 17 | "type": "shell", 18 | "scripts": [ 19 | "packer-shell-scripts/sudoers-nopasswd.sh", 20 | "packer-shell-scripts/install-virtualbox-guest-additions.sh", 21 | "packer-shell-scripts/add-vagrant-key.sh" 22 | ], 23 | "only": ["virtualbox"], 24 | "pause_before": "4s" 25 | }, 26 | { 27 | "type": "shell", 28 | "scripts": [ 29 | "packer-shell-scripts/base.sh", 30 | "packer-shell-scripts/redis.sh", 31 | "packer-shell-scripts/memcached.sh" 32 | ], 33 | "pause_before": "4s" 34 | }], 35 | "builders": [{ 36 | "name": "aws", 37 | "type": "amazon-ebs", 38 | "access_key": "{{user `aws_access_key`}}", 39 | "secret_key": "{{user `aws_secret_key`}}", 40 | "region": "{{user `aws_region`}}", 41 | "source_ami": "{{user `aws_source_ami`}}", 42 | "instance_type": "{{user `aws_instance_type`}}", 43 | "ssh_username": "ubuntu", 44 | "ami_name": "{{user `build_name`}}-{{timestamp}}", 45 | "ami_groups": ["all"], 46 | "security_group_id": "{{user `aws_security_group`}}", 47 | "tags": { 48 | "Name": "packer", 49 | "Name": "{{user `build_name`}}" 50 | }, 51 | "user_data": "" 52 | },{ 53 | "name": "virtualbox", 54 | "type": "virtualbox-iso", 55 | "vm_name": "{{user `build_name`}}", 56 | "output_directory": "./builds/{{user `build_name`}}", 57 | "iso_url": "{{user `iso_url`}}", 58 | "iso_checksum": "83aabd8dcf1e8f469f3c72fff2375195", 59 | "iso_checksum_type": "md5", 60 | "ssh_username": "{{user `username`}}", 61 | "ssh_password": "{{user `password`}}", 62 | "guest_os_type": "Ubuntu_64", 63 | "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", 64 | "virtualbox_version_file": ".vbox_version", 65 | "vboxmanage_post": [ 66 | [ 67 | "modifyvm", 68 | "{{.Name}}", 69 | "--memory", 70 | "2048" 71 | ], 72 | [ 73 | "modifyvm", 74 | "{{.Name}}", 75 | "--cpus", 76 | "2" 77 | ] 78 | ], 79 | "http_directory": "http", 80 | "ssh_wait_timeout": "45m", 81 | "boot_command": [ 82 | "", 83 | "/install/vmlinuz noapic ", 84 | "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", 85 | "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", 86 | "hostname={{user `build_name`}} ", 87 | "fb=false debconf/frontend=noninteractive ", 88 | "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", 89 | "keyboard-configuration/variant=USA console-setup/ask_detect=false ", 90 | "initrd=/install/initrd.gz -- " 91 | ], 92 | "shutdown_command": "sudo shutdown -P now" 93 | }], 94 | "post-processors": [{ 95 | "output": "./builds/{{user `build_name`}}/{{user `build_name`}}.box", 96 | "type": "vagrant", 97 | "keep_input_artifact": true, 98 | "only": ["virtualbox"] 99 | }] 100 | } 101 | -------------------------------------------------------------------------------- /http/nginx.conf: -------------------------------------------------------------------------------- 1 | # This is example contains the bare mininum to get nginx going with 2 | # Unicorn or Rainbows! servers. Generally these configuration settings 3 | # are applicable to other HTTP application servers (and not just Ruby 4 | # ones), so if you have one working well for proxying another app 5 | # server, feel free to continue using it. 6 | # 7 | # The only setting we feel strongly about is the fail_timeout=0 8 | # directive in the "upstream" block. max_fails=0 also has the same 9 | # effect as fail_timeout=0 for current versions of nginx and may be 10 | # used in its place. 11 | # 12 | # Users are strongly encouraged to refer to nginx documentation for more 13 | # details and search for other example configs. 14 | 15 | # you generally only need one nginx worker unless you're serving 16 | # large amounts of static files which require blocking disk reads 17 | worker_processes 1; 18 | 19 | # # drop privileges, root is needed on most systems for binding to port 80 20 | # # (or anything < 1024). Capability-based security may be available for 21 | # # your system and worth checking out so you won't need to be root to 22 | # # start nginx to bind on 80 23 | user nginx web; # for systems with a "nogroup" 24 | # user nobody nobody; # for systems with "nobody" as a group instead 25 | 26 | # Feel free to change all paths to suite your needs here, of course 27 | pid /tmp/pid/nginx.pid; 28 | error_log /log/nginx.error.log; 29 | 30 | events { 31 | worker_connections 1024; # increase if you have lots of clients 32 | accept_mutex off; # "on" if nginx worker_processes > 1 33 | # use epoll; # enable for Linux 2.6+ 34 | # use kqueue; # enable for FreeBSD, OSX 35 | } 36 | 37 | http { 38 | # nginx will find this file in the config directory set at nginx build time 39 | include mime.types; 40 | 41 | # fallback in case we can't determine a type 42 | default_type application/octet-stream; 43 | 44 | # click tracking! 45 | access_log /log/nginx.access.log combined; 46 | 47 | # you generally want to serve static files with nginx since neither 48 | # Unicorn nor Rainbows! is optimized for it at the moment 49 | sendfile on; 50 | 51 | tcp_nopush on; # off may be better for *some* Comet/long-poll stuff 52 | tcp_nodelay off; # on may be better for some Comet/long-poll stuff 53 | 54 | # we haven't checked to see if Rack::Deflate on the app server is 55 | # faster or not than doing compression via nginx. It's easier 56 | # to configure it all in one place here for static files and also 57 | # to disable gzip for clients who don't get gzip/deflate right. 58 | # There are other gzip settings that may be needed used to deal with 59 | # bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule 60 | gzip on; 61 | gzip_http_version 1.0; 62 | gzip_proxied any; 63 | gzip_min_length 500; 64 | gzip_disable "MSIE [1-6]\."; 65 | gzip_types text/plain text/html text/xml text/css 66 | text/comma-separated-values 67 | text/javascript application/x-javascript 68 | application/atom+xml; 69 | 70 | # this can be any application server, not just Unicorn/Rainbows! 71 | upstream app_server { 72 | # fail_timeout=0 means we always retry an upstream even if it failed 73 | # to return a good HTTP response (in case the Unicorn master nukes a 74 | # single worker for timing out). 75 | 76 | # for UNIX domain socket setups: 77 | server unix:/srv/www/current/tmp/pid/.unicorn.sock fail_timeout=0; 78 | 79 | # for TCP setups, point these to your backend servers 80 | # server 192.168.0.7:8080 fail_timeout=0; 81 | # server 192.168.0.8:8080 fail_timeout=0; 82 | # server 192.168.0.9:8080 fail_timeout=0; 83 | } 84 | 85 | server { 86 | # enable one of the following if you're on Linux or FreeBSD 87 | # listen 80 default deferred; # for Linux 88 | # listen 80 default accept_filter=httpready; # for FreeBSD 89 | 90 | # If you have IPv6, you'll likely want to have two separate listeners. 91 | # One on IPv4 only (the default), and another on IPv6 only instead 92 | # of a single dual-stack listener. A dual-stack listener will make 93 | # for ugly IPv4 addresses in $remote_addr (e.g ":ffff:10.0.0.1" 94 | # instead of just "10.0.0.1") and potentially trigger bugs in 95 | # some software. 96 | # listen [::]:80 ipv6only=on; # deferred or accept_filter recommended 97 | 98 | client_max_body_size 4G; 99 | server_name _; 100 | 101 | # ~2 seconds is often enough for most folks to parse HTML/CSS and 102 | # retrieve needed images/icons/frames, connections are cheap in 103 | # nginx so increasing this is generally safe... 104 | keepalive_timeout 5; 105 | 106 | # path for static files 107 | root /srv/www/current/public; 108 | 109 | # Prefer to serve static files directly from nginx to avoid unnecessary 110 | # data copies from the application server. 111 | # 112 | # try_files directive appeared in in nginx 0.7.27 and has stabilized 113 | # over time. Older versions of nginx (e.g. 0.6.x) requires 114 | # "if (!-f $request_filename)" which was less efficient: 115 | # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127 116 | try_files $uri/index.html $uri.html $uri @app; 117 | 118 | location @app { 119 | # an HTTP header important enough to have its own Wikipedia entry: 120 | # http://en.wikipedia.org/wiki/X-Forwarded-For 121 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 122 | 123 | # enable this if you forward HTTPS traffic to unicorn, 124 | # this helps Rack set the proper URL scheme for doing redirects: 125 | # proxy_set_header X-Forwarded-Proto $scheme; 126 | 127 | # pass the Host: header from the client right along so redirects 128 | # can be set properly within the Rack application 129 | proxy_set_header Host $http_host; 130 | 131 | # we don't want nginx trying to do something clever with 132 | # redirects, we set the Host: header above already. 133 | proxy_redirect off; 134 | 135 | # set "proxy_buffering off" *only* for Rainbows! when doing 136 | # Comet/long-poll/streaming. It's also safe to set if you're using 137 | # only serving fast clients with Unicorn + nginx, but not slow 138 | # clients. You normally want nginx to buffer responses to slow 139 | # clients, even with Rails 3.1 streaming because otherwise a slow 140 | # client can become a bottleneck of Unicorn. 141 | # 142 | # The Rack application may also set "X-Accel-Buffering (yes|no)" 143 | # in the response headers do disable/enable buffering on a 144 | # per-response basis. 145 | # proxy_buffering off; 146 | 147 | proxy_pass http://app_server; 148 | } 149 | 150 | # Rails error pages 151 | error_page 500 502 503 504 /500.html; 152 | location = /500.html { 153 | root /srv/www/current/public; 154 | } 155 | } 156 | } --------------------------------------------------------------------------------