Skip to content
Max Ivak edited this page Mar 31, 2018 · 15 revisions

Overview

  • Architecture
  • Deploy code
  • Sync application data

Architecture

Application data

Application data can be divided as:

  • code - files with code (models, libs). Stored in git repo. Maintained by developer and uploaded to server. Cannot be changed on the server directly.
  • database - data in mysql.
  • config - files with settings.
  • content. Can be changed on the server. Includes:
    • text files for pages/templates content, views.
    • assets - CSS, JS files.
    • images - as part of site design.
  • user data - files uploaded by site users.

Read more about application data

Deploy code

Config

  • Code is stored in git repo

  • edit config/deploy.rb

  • specify directories which will be shared and not to be overwritten after deploy

# APP SETTINGS

SHARED_DIRS = %W{public/system app/views public/uploads public/img }


These dirs are pointed to corresponding dirs in shared folder on the server.

Deploy

  • copy config files to server
cap production deploy:copy_config_files
  • deploy code
cap production deploy

! NOTE ! Dirs specified in SHARED_DIRS (in deploy.rb) will not be deployed.

Tasks

  • Restart application on server
cap production deploy:restart
  • Show maintenance page while deploying
  • site will not be accessible in browser
cap production deploy:web:disable
  • enable site
cap production deploy:web:enable
  • config/deploy.rb
#
before "deploy", "deploy:web:disable"
after "deploy", "deploy:web:enable"

Sync app data

Synchronize data stored on the remote server with data storage.

Problems:

  • After deployment, data on the server can be changed. We want to get that data and to not lose data after next deployment.

Scenarios:

  • deploy code from local project to server
  • developer changes app data in local project and upload changes to remote repo.
  • developer (or webmaster) applies changes to server (from Admin Area).
  • webmaster (site administrator) changes data on site.
  • webmaster saves changes to remote repo from Admin Area.
  • developer can get changes from remote repo to local project.

Setup storages for content

We will have 3 storages for site content

Appdata Config

  • Settings for storages for app data

  • edit file config/appdata/appdata.yml


default: &default
  code:
    storage:
      remote_repo: "ssh://git@github.com/myuser/site.git"



development:
  <<: *default


  content:

    -
      name: "views"

      dirs:
        - app/assets
        - app/views


      storage:
        type: git
        remote_repo: "ssh://git@github.com/myuser/site-data.git"
        local_repo_dir: "/path/to/project/temp/prod/repo-data"
        remote_repo_ssh_key: "/path/to/key/id_rsa"


    -
      name: "images"

      dirs:
        - public/img

      exclude:
        - tmp


      storage:
        type: ssh
        host: "mystorage.com"
        ssh_port: 22
        path: "/data/mysite/repo-images"
        ssh_user: "myuser"
        ssh_key: "/path/to/key/id_rsa"


    -
      name: "uploads"

      dirs:
        - public/uploads


      storage:
        type: ssh
        host: "mystorage.com"
        ssh_port: 22
        path: "/data/mysite/repo-uploads"
        ssh_user: "myuser"
        ssh_key: "/path/to/key/id_rsa"





production:
  <<: *default

  content:
    -
      name: "views"

      dirs:
        - app/views
        - app/assets


      storage:
        type: git
        remote_repo: "ssh://git@github.com/myuser/site-data.git"
        local_repo_dir: "/path/to/site/temp/prod/repo-data"
        remote_repo_ssh_key: "/path/to/key/id_rsa"


    -
      name: "images"

      dirs:
        - public/img

      exclude:
        - tmp


      storage:
        type: ssh
        host: "mystorage.com"
        ssh_port: 22
        path: "/data/mysite/repo-images"
        ssh_user: "myuser"
        ssh_key: "/path/to/key/id_rsa"


      -
        name: "uploads"

        dirs:
          - public/uploads


        storage:
          type: ssh
          host: "mystorage.com"
          ssh_port: 22
          path: "/data/mysite/repo-uploads"
          ssh_user: "myuser"
          ssh_key: "/path/to/key/id_rsa"



see Examples for more examples.

init

  • run capistrano task to initialize server
cap production deploy:appdata:setup

which will

  • create necessary directories on server for each content storages defined in appdata.yml

Upload content changes from local project to remote repo

Scenario:

  • developer changes app data in local project
  • developer uploads changes from local project to remote repo

Steps:

  • upload changes from local project to remote repo for content 'views' (see appdata.yml)
RAILS_ENV=development rake appdata:save['CONTENT_NAME']

for example, for content 'views' run:

RAILS_ENV=development rake appdata:save['views']

Get content changes from remote repo to server

Scenario:

  • webmaster gets changes from remote repo to the site on server

Steps:

  • update app data on server from remote repo

three options to do this:

  • run capistrano task from local project:
name=CONTENT_NAME cap production deploy:appdata:server_update

which runs rake task rake appdata:update on production server.

  • or run rake task on server
RAILS_ENV=production rake appdata:update['CONTENT_NAME']
  • or run from Admin Area: System -> App data -> select the corresponding content and click "Get"

  • restart Rails application on server if needed

Upload content changes from server to remote storage

Scenario:

  • webmaster changes data on site on server
  • webmaster saves changes from server to remote storage

Steps:

  • save changes from server to remote repo

  • option1. run capistrano task from local project:

name=CONTENT_NAME cap production deploy:appdata:server_save
  • option2. or run rake task on server
RAILS_ENV=production rake appdata:save['CONTENT_NAME']
  • option3. or run from Admin Area: System -> App data -> select corresponding content and click "Save"

Get content changes from remote storage to local project

Scenario:

  • developer can get changes from remote repo to local project

Steps:

  • get changes from remote repo to local project
RAILS_ENV=development rake appdata:update['CONTENT_NAME']

For example,

RAILS_ENV=development rake appdata:update['views']
RAILS_ENV=development rake appdata:update['images']
RAILS_ENV=development rake appdata:update['uploads']

Clone this wiki locally