$30 off During Our Annual Pro Sale. View Details »
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
140
DevOpsDays Boston 2020 - Passing the Technical Interview
benedmunds
0
78
Midwest PHP 2020 - Web Scale System Design and Architecture
benedmunds
1
150
Modern and Secure PHP (SoutheastPHP 2018)
benedmunds
0
120
Level Up Your Career - PHP South Africa Keynote
benedmunds
0
910
Modern PHP, Standards, and Community (phpDay 2017)
benedmunds
1
860
Lone Star PHP 2017 - More Than Just a Hammer
benedmunds
0
520
Lone Star PHP 2017 - Your API is Bad and You Should Feel Bad
benedmunds
0
240
Intro to Laravel 5
benedmunds
1
510
Other Decks in Technology
See All in Technology
多様なデジタルアイデンティティを攻撃からどうやって守るのか / 20251212
ayokura
0
500
打 造 A I 驅 動 的 G i t H u b ⾃ 動 化 ⼯ 作 流 程
appleboy
0
370
SREには開発組織全体で向き合う
koh_naga
0
390
AI との良い付き合い方を僕らは誰も知らない
asei
0
170
Identity Management for Agentic AI 解説
fujie
0
210
子育てで想像してなかった「見えないダメージ」 / Unforeseen "hidden burdens" of raising children.
pauli
2
300
AgentCoreとStrandsで社内d払いナレッジボットを作った話
motojimayu
1
210
Databricks向けJupyter Kernelでデータサイエンティストの開発環境をAI-Readyにする / Data+AI World Tour Tokyo After Party
genda
1
610
Power of Kiro : あなたの㌔はパワステ搭載ですか?
r3_yamauchi
PRO
0
200
NIKKEI Tech Talk #41: セキュア・バイ・デザインからクラウド管理を考える
sekido
PRO
0
170
100以上の新規コネクタ提供を可能にしたアーキテクチャ
ooyukioo
0
140
シニアソフトウェアエンジニアになるためには
kworkdev
PRO
3
200
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
740
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
320
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Navigating Team Friction
lara
191
16k
Chasing Engaging Ingredients in Design
codingconduct
0
75
The Cult of Friendly URLs
andyhume
79
6.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Six Lessons from altMBA
skipperchong
29
4.1k
Building Applications with DynamoDB
mza
96
6.8k
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