Skip to content

mjacobus/capistrano-demo

Repository files navigation

Capistrano deploy demo - PHP App

This is a simple PHP app for demonstrating Capistrano deployment. Provides a vagrant box to deploy to, and a few exercises. See this box.

About Capistrano

Capistrano is a deployment tool build on top of a ruby ssh wrapper and rake (ruby task runner).

Given the target folder is: set :deploy_to, '/var/www/my_app_name', the following would be the structure of the folders on the target server(s):

├── current -> /var/www/my_app_name/releases/20150120114500/ # this is a symlink to a release
├── releases            # here are the releases. Each release is an attempt of deploy
│   ├── 20150080072500
│   ├── 20150090083000
│   ├── 20150100093500
│   ├── 20150110104000
│   └── 20150120114500
├── repo                # git repo
├── revisions.log       # log with user who deployed/rolled back, release, and time
└── shared
    └── <linked_files and linked_dirs>

Config files (on this customized folder structure)

Gemfile               # ruby dependencies, such as rake and capistrano
Capfile               # file that capistrano will read in order to deploy
deploy                # custom folder for deployment config (by default it is config)
├── config.rb         # general config
├── environments      # configs per environment, such as servers to deploy to
│   ├── production.rb
│   └── staging.rb
├── README.md
└── tasks             # tasks separated by namespace. They do not have to be there, but it is more organized
    ├── foo.rake
    └── bar.rake

This box

The VM

How Capistrano was set

bundle install            # install dependencies
bundle exec cap install   # creates files for initial capistrano setup

Exercises:

Before you start the exercises, make sure you can get your environment up and running:

vagrant up                      # starts target server
bundle install                  # install dependencies
bundle exec cap vagrant deploy  # install dependencies

The above means you need vagrant and blundler, and of course, ruby.

Then, navigate to http://localhost:9000/ and make sure you can see a web app with some pictures and view count. It was made slow on purpose in a way that you can fix by only going throw the exercises.

  1. Change deployment so the assets folder is the same after every single deployment
  • Make sure assets folder is created on deploy
  • Add it to the symlink folders
bundle exec cap vagant assets:create_folder
  • for resolution see branch ex-01
  1. Create a task to list assets folders
bundle exec cap vagant assets:list
  • for resolution see branch ex-02
  1. Make page count persist over deploys
  • for resolution see branch ex-03
  1. Create a task to clear page count
bundle exec cap vagant page_views:clear
  • for resolution see branch ex-04

About

Capistrano demo with PHP application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published