This is a simple PHP app for demonstrating Capistrano deployment. Provides a vagrant box to deploy to, and a few exercises. See this box.
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>
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
- It is a ubuntu box running nginx and PHP FPM serving /var/www/apps/app_demo/current/public
bundle install # install dependencies
bundle exec cap install # creates files for initial capistrano setup
- Changed its default config - see diff
- Enabled plugins - see diff
- Added vagrant environment and repo source - see diff
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.
- 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
- Create a task to list assets folders
bundle exec cap vagant assets:list
- for resolution see branch ex-02
- Make page count persist over deploys
- for resolution see branch ex-03
- Create a task to clear page count
bundle exec cap vagant page_views:clear
- for resolution see branch ex-04