Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Multi-Environment Git Deployment with CodeIgniter
Search
Ben Edmunds
May 09, 2012
Technology
2
660
Multi-Environment Git Deployment with CodeIgniter
A presentation given by Ben Edmunds at CICON 2011 in NYC.
Ben Edmunds
May 09, 2012
Tweet
Share
More Decks by Ben Edmunds
See All by Ben Edmunds
Longhorn PHP 2021 - Passing the Technical Interview Workshop
benedmunds
0
120
DevOpsDays Boston 2020 - Passing the Technical Interview
benedmunds
0
61
Midwest PHP 2020 - Web Scale System Design and Architecture
benedmunds
1
140
Modern and Secure PHP (SoutheastPHP 2018)
benedmunds
0
97
Level Up Your Career - PHP South Africa Keynote
benedmunds
0
860
Modern PHP, Standards, and Community (phpDay 2017)
benedmunds
1
840
Lone Star PHP 2017 - More Than Just a Hammer
benedmunds
0
500
Lone Star PHP 2017 - Your API is Bad and You Should Feel Bad
benedmunds
0
210
Intro to Laravel 5
benedmunds
1
490
Other Decks in Technology
See All in Technology
Amazon ECS & AWS Fargate 運用アーキテクチャ2025 / Amazon ECS and AWS Fargate Ops Architecture 2025
iselegant
16
5.5k
Wasm元年
askua
0
140
Node-RED × MCP 勉強会 vol.1
1ftseabass
PRO
0
140
「Chatwork」の認証基盤の移行とログ活用によるプロダクト改善
kubell_hr
1
150
PostgreSQL 18 cancel request key長の変更とRailsへの関連
yahonda
0
120
M3 Expressiveの思想に迫る
chnotchy
0
100
あなたの声を届けよう! 女性エンジニア登壇の意義とアウトプット実践ガイド #wttjp / Call for Your Voice
kondoyuko
4
440
2年でここまで成長!AWSで育てたAI Slack botの軌跡
iwamot
PRO
4
700
Model Mondays S2E02: Model Context Protocol
nitya
0
220
Amazon Bedrockで実現する 新たな学習体験
kzkmaeda
2
540
Snowflake Summit 2025全体振り返り / Snowflake Summit 2025 Overall Review
mtpooh
2
400
AWS CDK 実践的アプローチ N選 / aws-cdk-practical-approaches
gotok365
6
740
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Writing Fast Ruby
sferik
628
61k
Bash Introduction
62gerente
614
210k
How to Ace a Technical Interview
jacobian
277
23k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Transcript
Multi-Environment Git Deployment with CodeIgniter -Ben Edmunds
• What is Git? • Distributed Version Control • Why
use version control? • Change tracking and roll-back • Multi-developer projects • Deployment
• Why use Git? • Branching • Feature branches •
Environment deployment with branches
• What is Deployment? • Automated update and setup of
code • Why use deployments? • FTP = nasty • Humans suck • Ease of use
Local Staging Production (Development) (QA) (Live) Basic Deployment Scenario
Local Development Setup $ git init $ git remote add
origin yourRepo.git $ git pull origin master $ git checkout -b staging $ git push origin staging $ git checkout -b production $ git push origin master
Branch Setup $ git checkout -b staging $ git push
origin staging $ git checkout -b production $ git push origin master
Deployment Code <?php define('ENV', 'production'); define('ENV_BASE_PATH', '/home/benedmunds/domains/benedmunds.com/'); class Deployment extends
CI_Controller { function post_receive() { ... } } ?>
Deployment Code post_receive() { ... } • json_decode($_POST[‘payload’]) • Check
payload ref against ENV • Execute Git commands to clean and pull the correct branch
Deployment Code function post_receive() { if (isset($_POST['payload']) && !empty($_POST['payload'])) {
$payload = json_decode($_POST['payload']); //make sure this is the correct environment if ($payload->ref == 'refs/heads/' . ENV) { log_message('debug', 'DEPLOYMENT: Post-receive hook - '. ENV); //reset, clean and pull shell_exec('/usr/bin/git --git-dir="' . ENV_BASE_PATH . '.git" ‘ . ‘--work-tree="' . ENV_BASE_PATH . '" ‘ . ‘reset --hard HEAD'); shell_exec('/usr/bin/git --git-dir="' . ENV_BASE_PATH . '.git" ‘ . ‘--work-tree="' . ENV_BASE_PATH . '" clean -f'); shell_exec('/usr/bin/git --git-dir="' . ENV_BASE_PATH . '.git" ‘ . ‘--work-tree="' . ENV_BASE_PATH . '" ‘ . ‘pull origin ' . ENV); } } }
class Migration_Create_accounts extends Migration { function up() { $this->migrations->verbose AND
print "Creating table accounts..."; if ( ! $this->db->table_exists('accounts')) { // Setup Keys $this->dbforge->add_key('id', TRUE); $this->dbforge->add_field(array( 'id' => array('type' => 'INT', 'constraint' => 5, 'unsigned' => TRUE, 'auto_increment' => TRUE), 'company_name' => array('type' => 'VARCHAR', 'constraint' => '200', 'null' => FALSE), 'first_name' => array('type' => 'VARCHAR', 'constraint' => '200', 'null' => FALSE), 'last_name' => array('type' => 'VARCHAR', 'constraint' => '200', 'null' => FALSE), 'phone' => array('type' => 'TEXT', 'null' => FALSE), 'email' => array('type' => 'TEXT', 'null' => FALSE), 'address' => array('type' => 'TEXT', 'null' => FALSE), 'Last_Update' => array('type' => 'DATETIME', 'null' => FALSE) )); $this->dbforge->add_field("Created_At TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"); $this->dbforge->create_table('accounts', TRUE); } } function down() { $this->dbforge->drop_table('accounts'); } } Migrations https://github.com/philsturgeon/codeigniter-migrations
if ( ! $this->migration->latest()) { show_error($this->migration->error); } Migrations https://github.com/philsturgeon/codeigniter-migrations
Staging Server Setup $ git init $ git remote add
origin yourRepo.git $ git pull origin staging
Production Server Setup $ git init $ git remote add
origin yourRepo.git $ git pull origin production
Github Post Receive Hook
Pushing to Master $git checkout master $ git commit -am
‘Made code change’ $ git push origin master Local Github
Pushing to Staging $ git checkout staging $ git merge
master $ git push origin staging Local Github Staging
Pushing to Production $ git checkout production $ git merge
staging $ git push origin production Local Github Production
Local Staging Production (Development) (QA) (Live)
Multi-Environment Git Deployment with CodeIgniter -Ben Edmunds