Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Multi-Environment Git Deployment with CodeIgniter
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
170
Modern and Secure PHP (SoutheastPHP 2018)
benedmunds
0
140
Level Up Your Career - PHP South Africa Keynote
benedmunds
0
970
Modern PHP, Standards, and Community (phpDay 2017)
benedmunds
1
920
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
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
3
920
全員がプロダクトへ向き合う組織を持続成長させるために——組織づくりのフライホイールと4象限 / The Flywheel Model and Four Quadrants for Organizational Design
hiro_torii
4
970
WAF 運用改善の承認サイクル/SRE_BizReach_MIXI_1
visional_engineering_and_design
2
440
Snowflakeで実現する全社横断の顧客の声(VOC)分析・活用基盤@Snowflake World Tour Tokyo 2026
yuto16
0
170
リージョンの壁を越える、 ちょっと変わったAWSサービスの話
falken
PRO
1
300
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
4
1k
Snowflakeのコスト最適化を支えるアーキテクチャ設計
ktatsuya
1
1.5k
『止めない』を設計する — 制約の中で、事業の根幹を支える判断
hiroyaterui
0
270
作り直せるコードは迅速に 作り直せないDBは慎重に - AI時代のプロダクトエンジニアが「判断の不可逆性」で開発速度を変える話
kinosuke01
0
310
Tab5をRubyで動くパソコンにする
kishima
2
340
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
810
Code4Lib JAPANカンファレンス2026 開会挨拶 / Code4Lib JAPAN Conference 2026: Opening Remarks
ykiyota
0
330
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
700
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
890
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
440
A Modern Web Designer's Workflow
chriscoyier
699
190k
Facilitating Awesome Meetings
lara
57
7.1k
Docker and Python
trallard
47
4.2k
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