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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ben Edmunds
May 09, 2012
Technology
660
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Multi-Environment Git Deployment with CodeIgniter
A presentation given by Ben Edmunds at CICON 2011 in NYC.
Ben Edmunds
May 09, 2012
More Decks by Ben Edmunds
See All by Ben Edmunds
Longhorn PHP 2021 - Passing the Technical Interview Workshop
benedmunds
0
170
DevOpsDays Boston 2020 - Passing the Technical Interview
benedmunds
0
110
Midwest PHP 2020 - Web Scale System Design and Architecture
benedmunds
1
160
Modern and Secure PHP (SoutheastPHP 2018)
benedmunds
0
140
Level Up Your Career - PHP South Africa Keynote
benedmunds
0
960
Modern PHP, Standards, and Community (phpDay 2017)
benedmunds
1
910
Lone Star PHP 2017 - More Than Just a Hammer
benedmunds
0
550
Lone Star PHP 2017 - Your API is Bad and You Should Feel Bad
benedmunds
0
270
Intro to Laravel 5
benedmunds
1
540
Other Decks in Technology
See All in Technology
Breaking the Seal: Static Deobfuscation of Compiled V8 JavaScript Bytecode Malware
hshrzd
0
760
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
180
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
5.3k
[ChatGPT Work LT]事務作業が苦手な人のための バックオフィスの「半」自動化
chimaki_iot
0
280
JavaScript 研修 (2026)
recruitengineers
PRO
2
540
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
19k
生成 AI の基礎 〜 サンプル実装で学ぶ基本原理
enakai00
7
4.4k
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
250
AIエージェントを前提としたプラットフォーム エンジニアリング:GKEで作るAgent-Ready Golden Path
legalontechnologies
PRO
2
240
20260804_Q4AzureUpdateBite_FabricDataAgentの精度を高める設計.pdf
matayuuu
1
130
【CEDEC2026】専門性の高いデフォルメチームが挑んだ人材育成戦略 〜Cygames Academiaの企画から実施まで〜
cygames
PRO
0
610
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.2k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
480
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
The SEO identity crisis: Don't let AI make you average
varn
0
530
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
390
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
330
Evolving SEO for Evolving Search Engines
ryanjones
0
250
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
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