From 108d5e5c34812ad1868e31cedaab37a04356591d Mon Sep 17 00:00:00 2001 From: Philip Kallberg Date: Mon, 14 Oct 2013 17:09:29 +0100 Subject: [PATCH] cloud66 easydeploy --- .cloud66/deploy_hooks.yml | 233 ++++++++++++++++++++++++++++++++ .cloud66/files/Procfile | 3 + .cloud66/files/production.rb | 69 ++++++++++ .cloud66/files/redis.yml | 23 ++++ .cloud66/files/thin.yml | 13 ++ .cloud66/manifest.yml | 19 +++ .cloud66/scripts/curl.sh | 14 ++ .cloud66/scripts/drop_create.sh | 11 ++ .cloud66/scripts/env_vars.sh | 2 + .cloud66/scripts/import_dev.sh | 10 ++ .cloud66/scripts/import_prod.sh | 10 ++ .cloud66/scripts/kill_db.sh | 10 ++ .cloud66/scripts/migrate.sh | 11 ++ .cloud66/scripts/permissions.sh | 2 + docs/INSTALL-cloud66.md | 17 +++ docs/INSTALL-ubuntu.md | 8 ++ 16 files changed, 455 insertions(+) create mode 100644 .cloud66/deploy_hooks.yml create mode 100644 .cloud66/files/Procfile create mode 100644 .cloud66/files/production.rb create mode 100644 .cloud66/files/redis.yml create mode 100644 .cloud66/files/thin.yml create mode 100644 .cloud66/manifest.yml create mode 100644 .cloud66/scripts/curl.sh create mode 100644 .cloud66/scripts/drop_create.sh create mode 100644 .cloud66/scripts/env_vars.sh create mode 100644 .cloud66/scripts/import_dev.sh create mode 100644 .cloud66/scripts/import_prod.sh create mode 100644 .cloud66/scripts/kill_db.sh create mode 100644 .cloud66/scripts/migrate.sh create mode 100644 .cloud66/scripts/permissions.sh create mode 100644 docs/INSTALL-cloud66.md diff --git a/.cloud66/deploy_hooks.yml b/.cloud66/deploy_hooks.yml new file mode 100644 index 00000000000..9279d0506ac --- /dev/null +++ b/.cloud66/deploy_hooks.yml @@ -0,0 +1,233 @@ +production: + first_thing: + # 1. Permissions on postgres box + - source: /.cloud66/scripts/permissions.sh + destination: /tmp/scripts/permissions.sh + target: postgresql + apply_during: build_only + execute: true + sudo: true + after_postgresql: + # 2. Copy SQL image to PSQL server + - source: /pg_dumps/production-image.sql + destination: /tmp/images/production-image.sql + target: postgresql + apply_during: build_only + owner: postgres + after_checkout: + # 3. Copy Procfile + - source: /.cloud66/files/Procfile + destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile + target: rails + # 4. Copy redis settings + - source: /.cloud66/files/redis.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/redis.yml + target: rails + parse: false + # 5. Copy production.rb file + - source: /.cloud66/files/production.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb + target: rails + # 6. Move thin config to server + - source: /.cloud66/files/thin.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/thin.yml + target: rails + after_rails: + # 7. Set environment variables and allow PSQL user to access them + - source: /.cloud66/scripts/env_vars.sh + destination: /tmp/scripts/env_vars.sh + target: rails + apply_during: build_only + execute: true + sudo: true + last_thing: + # 8. KILL DB + - source: /.cloud66/scripts/kill_db.sh + destination: /tmp/scripts/kill_db.sh + target: postgresql + apply_during: build_only + execute: true + sudo: true + # 9. DB:DROP & DB:CREATE + - source: /.cloud66/scripts/drop_create.sh + destination: /tmp/scripts/drop_create.sh + target: rails + apply_during: build_only + execute: true + sudo: true + # 10. Import database image + - source: /.cloud66/scripts/import_prod.sh + destination: /tmp/scripts/import_prod.sh + target: postgresql + apply_during: build_only + execute: true + owner: postgres + run_as: postgres + # 11. Migrate database + - source: /.cloud66/scripts/migrate.sh + destination: /tmp/migrate.sh + target: rails + apply_during: build_only + execute: true + sudo: true + # 12. Curl script + - source: /.cloud66/scripts/curl.sh + destination: /tmp/curl.sh + target: rails + apply_during: build_only + execute: true + sudo: true +staging: + first_thing: + # 1. Permissions on postgres box + - source: /.cloud66/scripts/permissions.sh + destination: /tmp/scripts/permissions.sh + target: postgresql + apply_during: build_only + execute: true + sudo: true + after_postgresql: + # 2. Copy SQL image to PSQL server + - source: /pg_dumps/production-image.sql + destination: /tmp/images/production-image.sql + target: postgresql + apply_during: build_only + owner: postgres + after_checkout: + # 3. Copy Procfile + - source: /.cloud66/files/Procfile + destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile + target: rails + # 4. Rename redis.yml.sample file + - source: /.cloud66/files/redis.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/redis.yml + target: rails + parse: false + # 5. Rename production.rb.sample file + - source: /.cloud66/files/production.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/environments/production.rb + target: rails + # 6. Move thin config to server + - source: /.cloud66/files/thin.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/thin.yml + target: rails + after_rails: + # 7. Set environment variables and allow PSQL user to access them + - source: /.cloud66/scripts/env_vars.sh + destination: /tmp/scripts/env_vars.sh + target: rails + apply_during: build_only + execute: true + sudo: true + last_thing: + # 8. KILL DB + - source: /.cloud66/scripts/kill_db.sh + destination: /tmp/scripts/kill_db.sh + target: postgresql + apply_during: build_only + execute: true + sudo: true + # 9. DB:DROP & DB:CREATE + - source: /.cloud66/scripts/drop_create.sh + destination: /tmp/scripts/drop_create.sh + target: rails + apply_during: build_only + execute: true + sudo: true + # 10. Import database image + - source: /.cloud66/scripts/import_prod.sh + destination: /tmp/scripts/import_prod.sh + target: postgresql + apply_during: build_only + execute: true + owner: postgres + run_as: postgres + # 11. Migrate database + - source: /.cloud66/scripts/migrate.sh + destination: /tmp/migrate.sh + target: rails + apply_during: build_only + execute: true + sudo: true + # 12. Curl script + - source: /.cloud66/scripts/curl.sh + destination: /tmp/curl.sh + target: rails + apply_during: build_only + execute: true + sudo: true +development: + first_thing: + # 1. Permissions on postgres box + - source: /.cloud66/scripts/permissions.sh + destination: /tmp/scripts/permissions.sh + target: postgresql + apply_during: build_only + execute: true + sudo: true + after_postgresql: + # 2. Copy SQL image to PSQL server + - source: /pg_dumps/development-image.sql + destination: /tmp/images/development-image.sql + target: postgresql + apply_during: build_only + owner: postgres + after_checkout: + # 3. Copy Procfile + - source: /.cloud66/files/Procfile + destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile + target: rails + # 4. Rename redis.yml.sample file + - source: /.cloud66/files/redis.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/redis.yml + target: rails + parse: false + # 5. Move thin config to server + - source: /.cloud66/files/thin.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/thin.yml + target: rails + after_rails: + # 6. Set environment variables and allow PSQL user to access them + - source: /.cloud66/scripts/env_vars.sh + destination: /tmp/scripts/env_vars.sh + target: rails + apply_during: build_only + execute: true + sudo: true + last_thing: + # 7. KILL DB + - source: /.cloud66/scripts/kill_db.sh + destination: /tmp/scripts/kill_db.sh + target: postgresql + apply_during: build_only + execute: true + sudo: true + # 8. DB:DROP & DB:CREATE + - source: /.cloud66/scripts/drop_create.sh + destination: /tmp/scripts/drop_create.sh + target: rails + apply_during: build_only + execute: true + sudo: true + # 9. Import database image + - source: /.cloud66/scripts/import_dev.sh + destination: /tmp/scripts/import_dev.sh + target: postgresql + apply_during: build_only + execute: true + owner: postgres + run_as: postgres + # 10. Migrate database + - source: /.cloud66/scripts/migrate.sh + destination: /tmp/migrate.sh + target: rails + apply_during: build_only + execute: true + sudo: true + # 11. Curl script + - source: /.cloud66/scripts/curl.sh + destination: /tmp/curl.sh + target: rails + apply_during: build_only + execute: true + sudo: true \ No newline at end of file diff --git a/.cloud66/files/Procfile b/.cloud66/files/Procfile new file mode 100644 index 00000000000..4f01d278d0b --- /dev/null +++ b/.cloud66/files/Procfile @@ -0,0 +1,3 @@ +web: bundle exec rails server -p $PORT +sidekiq: bundle exec sidekiq -e $RAILS_ENV +custom_web: bundle exec thin start -C config/thin.yml -e $RACK_ENV -d \ No newline at end of file diff --git a/.cloud66/files/production.rb b/.cloud66/files/production.rb new file mode 100644 index 00000000000..de0db349bb8 --- /dev/null +++ b/.cloud66/files/production.rb @@ -0,0 +1,69 @@ +Discourse::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.serve_static_assets = false + + # Compress JavaScripts and CSS + config.assets.compress = true + + # stuff should be pre-compiled + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true + + # Specifies the header that your server uses for sending files + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + + # you may use other configuration here for mail eg: sendgrid + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + :address => ENV['SMTP_ADDRESS'], + :port => ENV['SMTP_PORT'], + :domain => ENV['SMTP_DOMAIN'], + :user_name => ENV['SMTP_USERNAME'], + :password => ENV['SMTP_PASSWORD'], + :authentication => 'plain', + :enable_starttls_auto => true } + + #config.action_mailer.delivery_method = :sendmail + #config.action_mailer.sendmail_settings = {arguments: '-i'} + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify + + # this will cause all handlebars templates to be pre-compiles, making your page faster + config.handlebars.precompile = true + + # this setting enables rack_cache so it caches various requests in redis + config.enable_rack_cache = true + + # allows admins to use mini profiler + config.enable_mini_profiler = true + + # allows Cross-origin resource sharing (CORS) for API access in JavaScript (default to false for security). + # See the initializer and https://github.com/cyu/rack-cors for configuration documentation. + # + # config.enable_rack_cors = false + # config.rack_cors_origins = ['*'] + # config.rack_cors_resource = ['*', { :headers => :any, :methods => [:get, :post, :options] }] + + # Discourse strongly recommend you use a CDN. + # For origin pull cdns all you need to do is register an account and configure + # config.action_controller.asset_host = "http://YOUR_CDN_HERE" + +end diff --git a/.cloud66/files/redis.yml b/.cloud66/files/redis.yml new file mode 100644 index 00000000000..50771512a09 --- /dev/null +++ b/.cloud66/files/redis.yml @@ -0,0 +1,23 @@ +defaults: &defaults + uri: <%= uri = URI.parse( ENV['REDIS_ADDRESS'].nil? ? ENV['REDIS_PROVIDER_URL'] || "redis://localhost:6379" : "redis://#{ENV['REDIS_ADDRESS']}:6379") %> + host: <%= uri.host %> + port: <%= uri.port %> + password: <%= uri.password %> + db: 0 + cache_db: 2 + +development: + <<: *defaults + +profile: + <<: *defaults + +test: + <<: *defaults + db: 1 + +staging: + <<: *defaults + +production: + <<: *defaults diff --git a/.cloud66/files/thin.yml b/.cloud66/files/thin.yml new file mode 100644 index 00000000000..435d38b9483 --- /dev/null +++ b/.cloud66/files/thin.yml @@ -0,0 +1,13 @@ +address: localhost +port: 3000 +timeout: 30 +pid: /tmp/web_server.pid +socket: /tmp/web_server.sock +max_conns: 1024 +max_persistent_conns: 100 +require: [] +wait: 30 +daemonize: true +chdir: $STACK_PATH +environment: $RAILS_ENV +log: $STACK_PATH/log/thin.log \ No newline at end of file diff --git a/.cloud66/manifest.yml b/.cloud66/manifest.yml new file mode 100644 index 00000000000..7ef38955918 --- /dev/null +++ b/.cloud66/manifest.yml @@ -0,0 +1,19 @@ +production: + rails: + server: + unique_name: frontend + configuration: + ignore_missing_schema: true +staging: + rails: + server: + unique_name: frontend + configuration: + ignore_missing_schema: true +development: + rails: + server: + unique_name: frontend + configuration: + use_asset_pipeline: false + ignore_missing_schema: true \ No newline at end of file diff --git a/.cloud66/scripts/curl.sh b/.cloud66/scripts/curl.sh new file mode 100644 index 00000000000..3f84f89b696 --- /dev/null +++ b/.cloud66/scripts/curl.sh @@ -0,0 +1,14 @@ +#!/bin/bash +FILE=/tmp/curl_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + curl localhost + curl localhost + curl localhost + curl localhost + curl localhost + touch /tmp/curl_done +fi \ No newline at end of file diff --git a/.cloud66/scripts/drop_create.sh b/.cloud66/scripts/drop_create.sh new file mode 100644 index 00000000000..5c78f512676 --- /dev/null +++ b/.cloud66/scripts/drop_create.sh @@ -0,0 +1,11 @@ +#!/bin/bash +FILE=/tmp/drop_create_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + cd $RAILS_STACK_PATH + bundle exec rake db:drop db:create + touch /tmp/drop_create_done +fi \ No newline at end of file diff --git a/.cloud66/scripts/env_vars.sh b/.cloud66/scripts/env_vars.sh new file mode 100644 index 00000000000..eb6bec33480 --- /dev/null +++ b/.cloud66/scripts/env_vars.sh @@ -0,0 +1,2 @@ +#!/bin/bash +source /var/.cloud66_env \ No newline at end of file diff --git a/.cloud66/scripts/import_dev.sh b/.cloud66/scripts/import_dev.sh new file mode 100644 index 00000000000..f5b4c792af6 --- /dev/null +++ b/.cloud66/scripts/import_dev.sh @@ -0,0 +1,10 @@ +#!/bin/bash +FILE=/tmp/import_dev_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + psql $POSTGRESQL_DATABASE < /tmp/images/development-image.sql + touch /tmp/import_dev_done +fi \ No newline at end of file diff --git a/.cloud66/scripts/import_prod.sh b/.cloud66/scripts/import_prod.sh new file mode 100644 index 00000000000..9a20c98b6f1 --- /dev/null +++ b/.cloud66/scripts/import_prod.sh @@ -0,0 +1,10 @@ +#!/bin/bash +FILE=/tmp/import_prod_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + psql $POSTGRESQL_DATABASE < /tmp/images/production-image.sql + touch /tmp/import_prod_done +fi \ No newline at end of file diff --git a/.cloud66/scripts/kill_db.sh b/.cloud66/scripts/kill_db.sh new file mode 100644 index 00000000000..a43879158bd --- /dev/null +++ b/.cloud66/scripts/kill_db.sh @@ -0,0 +1,10 @@ +#!/bin/bash +FILE=/tmp/kill_db_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + ps xa | grep postgres: | grep $POSTGRESQL_DATABASE | grep -v grep | awk '{print $1}' | sudo xargs kill + touch /tmp/kill_db_done +fi \ No newline at end of file diff --git a/.cloud66/scripts/migrate.sh b/.cloud66/scripts/migrate.sh new file mode 100644 index 00000000000..d336ee30490 --- /dev/null +++ b/.cloud66/scripts/migrate.sh @@ -0,0 +1,11 @@ +#!/bin/bash +FILE=/tmp/migrate_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + cd $RAILS_STACK_PATH + bundle exec rake db:migrate db:seed_fu + touch /tmp/migrate_done +fi \ No newline at end of file diff --git a/.cloud66/scripts/permissions.sh b/.cloud66/scripts/permissions.sh new file mode 100644 index 00000000000..85763c0736c --- /dev/null +++ b/.cloud66/scripts/permissions.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo chmod 0644 -R /var/.cloud66_env \ No newline at end of file diff --git a/docs/INSTALL-cloud66.md b/docs/INSTALL-cloud66.md new file mode 100644 index 00000000000..da6322c259b --- /dev/null +++ b/docs/INSTALL-cloud66.md @@ -0,0 +1,17 @@ +# Deploying on Cloud 66 + +![Logo](http://cdn.cloud66.com/images/easy-deploy.png) + + +Simply follow 7 steps on [building your stack](https://www.cloud66.com/help/first_stack), sign up for a Sendgrid account (for sending emails) and set +the environment variables below to have your own fully functioning Discourse installation up and running. + +Note: Setting environment variables is done during step five, before you click 'deploy': +![Environment variables](http://cdn.cloud66.com/images/environment_variables.png) + +1. SMTP_ADDRESS = your SMTP host +2. SMTP_PORT = the port on your SMTP host +3. SMTP_DOMAIN = the domain you will be sending emails from +4. SMTP_USERNAME = your SMTP username +5. SMTP_PASSWORD = your SMTP password +6. HOST_NAME = the domain hosting your site \ No newline at end of file diff --git a/docs/INSTALL-ubuntu.md b/docs/INSTALL-ubuntu.md index 9d6169be21a..4159ac50b19 100644 --- a/docs/INSTALL-ubuntu.md +++ b/docs/INSTALL-ubuntu.md @@ -396,3 +396,11 @@ This change should also be made to your production file. We take security very seriously at Discourse, and all our code is 100% open source and peer reviewed. Please read [our security guide](https://github.com/discourse/discourse/blob/master/docs/SECURITY.md) for an overview of security measures in Discourse. + +## Deploying with Cloud 66 + +![Logo](http://cdn.cloud66.com/images/easy-deploy.png) + + +Deploying and maintaining a Discourse setup through Cloud 66 is extremely easy. +Click the badge and follow these [instructions](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud66.md) to deploy!