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
650
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
99
DevOpsDays Boston 2020 - Passing the Technical Interview
benedmunds
0
52
Midwest PHP 2020 - Web Scale System Design and Architecture
benedmunds
1
110
Modern and Secure PHP (SoutheastPHP 2018)
benedmunds
0
82
Level Up Your Career - PHP South Africa Keynote
benedmunds
0
810
Modern PHP, Standards, and Community (phpDay 2017)
benedmunds
1
800
Lone Star PHP 2017 - More Than Just a Hammer
benedmunds
0
480
Lone Star PHP 2017 - Your API is Bad and You Should Feel Bad
benedmunds
0
190
Intro to Laravel 5
benedmunds
1
460
Other Decks in Technology
See All in Technology
まだ間に合う! エンジニアのための生成AIアプリ開発入門 on AWS
minorun365
PRO
4
580
WAF に頼りすぎない AWS WAF 運用術 meguro sec #1
izzii
0
460
偶然 × 行動で人生の可能性を広げよう / Serendipity × Action: Discover Your Possibilities
ar_tama
1
740
滅・サービスクラス🔥 / Destruction Service Class
sinsoku
6
1.5k
10分で紹介するAmazon Bedrock利用時のセキュリティ対策 / 10-minutes introduction to security measures when using Amazon Bedrock
hideakiaoyagi
0
170
Ask! NIKKEI RAG検索技術の深層
hotchpotch
13
2.8k
オブザーバビリティの観点でみるAWS / AWS from observability perspective
ymotongpoo
7
1k
[2025-02-07]生成AIで変える問い合わせの未来 〜チームグローバル化の香りを添えて〜
tosite
1
290
Larkご案内資料
customercloud
PRO
0
600
関東Kaggler会LT: 人狼コンペとLLM量子化について
nejumi
3
460
APIファーストで実現する運用性の高い IoT プラットフォーム: SORACOMのアプローチ
soracom
PRO
0
240
Postmanを使いこなす!2025年ぜひとも押さえておきたいPostmanの10の機能
nagix
2
120
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
171
14k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
GitHub's CSS Performance
jonrohan
1030
460k
For a Future-Friendly Web
brad_frost
176
9.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Typedesign – Prime Four
hannesfritz
40
2.5k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.2k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Code Review Best Practice
trishagee
66
17k
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