@@ -14,7 +14,7 @@ public static function freshInit(Connection $connection, $stage)
1414 {
1515 // Init fresh remote repo
1616 $ connection ->define ('init ' , [
17- 'cd ' . config ('laravel-deploy-helper.stages. ' . $ stage. '.remote.root ' ),
17+ 'cd ' . config ('laravel-deploy-helper.stages. ' . $ stage . '.remote.root ' ),
1818 'mkdir releases ' ,
1919 'mkdir patches ' ,
2020 'mkdir shared ' ,
@@ -35,11 +35,11 @@ public static function doDeploy($stage, $branch, $ldh)
3535 {
3636 // Some stuff that does not change in runtime
3737 $ releaseName = time ();
38- $ home = config ('laravel-deploy-helper.stages. ' . $ stage. '.remote.root ' );
39- $ shared = config ('laravel-deploy-helper.stages. ' . $ stage. '.shared ' );
40- $ commands = config ('laravel-deploy-helper.stages. ' . $ stage. '.commands ' );
41- $ versions = config ('laravel-deploy-helper.stages. ' . $ stage. '.config.dependencies ' );
42- $ keep = config ('laravel-deploy-helper.stages. ' . $ stage. '.config.keep ' );
38+ $ home = config ('laravel-deploy-helper.stages. ' . $ stage . '.remote.root ' );
39+ $ shared = config ('laravel-deploy-helper.stages. ' . $ stage . '.shared ' );
40+ $ commands = config ('laravel-deploy-helper.stages. ' . $ stage . '.commands ' );
41+ $ versions = config ('laravel-deploy-helper.stages. ' . $ stage . '.config.dependencies ' );
42+ $ keep = config ('laravel-deploy-helper.stages. ' . $ stage . '.config.keep ' );
4343
4444 // Check what releases are old and can be removed
4545 ksort ($ ldh );
@@ -52,67 +52,67 @@ public static function doDeploy($stage, $branch, $ldh)
5252
5353 // Check versions
5454 // Operators: http://php.net/manual/en/function.version-compare.php
55- verbose ('[ ' . $ stage. '] Checking dependencies. Migth take a minute. ' );
55+ verbose ('[ ' . $ stage . '] Checking dependencies. Migth take a minute. ' );
5656 foreach ($ versions as $ app => $ version ) {
5757 SSH ::checkAppVersion ($ connection , $ app , $ version );
5858 }
5959
6060 // Define the deploy
61- verbose ('[ ' . $ stage. '] Creating new release directory and pulling from remote ' );
61+ verbose ('[ ' . $ stage . '] Creating new release directory and pulling from remote ' );
6262 SSH ::execute ($ stage , [
63- 'mkdir ' . $ home. '/releases/ ' . $ releaseName ,
64- 'cd ' . $ home. '/releases/ ' . $ releaseName ,
65- 'git clone -b ' . $ branch. ' ' . config ('laravel-deploy-helper.stages. ' . $ stage. '.git.http ' ). ' . ' ,
63+ 'mkdir ' . $ home . '/releases/ ' . $ releaseName ,
64+ 'cd ' . $ home . '/releases/ ' . $ releaseName ,
65+ 'git clone -b ' . $ branch . ' ' . config ('laravel-deploy-helper.stages. ' . $ stage . '.git.http ' ) . ' . ' ,
6666 ]);
6767
6868 // Pre-flight for shared stuff
6969 $ items ['directories ' ] = [];
7070 foreach ($ shared ['directories ' ] as $ share ) {
71- verbose ('[ ' . $ stage. '] About to share direcroty " ' . $ home. '/current/ ' . $ share. '" ' );
72- $ items ['directories ' ][] = '[ -e ' . $ home. '/current/ ' . $ share. ' ] && cp -R -p ' . $ home. '/current/ '
73- .$ share. ' ' . $ home. '/shared/ ' . $ share ;
74- $ items ['directories ' ][] = '[ -e ' . $ home. '/shared/ ' . $ share. ' ] && cp -R -p ' . $ home. '/shared/ ' .
75- $ share. ' ' . $ home. '/releases/ ' . $ releaseName ;
71+ verbose ('[ ' . $ stage . '] About to share direcroty " ' . $ home . '/current/ ' . $ share . '" ' );
72+ $ items ['directories ' ][] = '[ -e ' . $ home . '/current/ ' . $ share . ' ] && cp -R -p ' . $ home . '/current/ '
73+ . $ share . ' ' . $ home . '/shared/ ' . $ share ;
74+ $ items ['directories ' ][] = '[ -e ' . $ home . '/shared/ ' . $ share . ' ] && cp -R -p ' . $ home . '/shared/ ' .
75+ $ share . ' ' . $ home . '/releases/ ' . $ releaseName ;
7676 }
7777 // Pre-flight for shared stuff
7878 $ items ['files ' ] = [];
7979 foreach ($ shared ['files ' ] as $ share ) {
80- verbose ('[ ' . $ stage. '] About to share file " ' . $ home. '/current/ ' . $ share. '" ' );
81- $ items ['files ' ][] = '[ -e ' . $ home. '/current/ ' . $ share. ' ] && cp -p ' . $ home. '/current/ ' . $ share
82- .' ' . $ home. '/shared/ ' . $ share ;
83- $ items ['files ' ][] = '[ -e ' . $ home. '/shared/ ' . $ share. ' ] && cp -p ' . $ home. '/shared/ ' . $ share .
84- ' ' . $ home. '/releases/ ' . $ releaseName. '/ ' . $ share ;
80+ verbose ('[ ' . $ stage . '] About to share file " ' . $ home . '/current/ ' . $ share . '" ' );
81+ $ items ['files ' ][] = '[ -e ' . $ home . '/current/ ' . $ share . ' ] && cp -p ' . $ home . '/current/ ' . $ share
82+ . ' ' . $ home . '/shared/ ' . $ share ;
83+ $ items ['files ' ][] = '[ -e ' . $ home . '/shared/ ' . $ share . ' ] && cp -p ' . $ home . '/shared/ ' . $ share .
84+ ' ' . $ home . '/releases/ ' . $ releaseName . '/ ' . $ share ;
8585 }
8686
8787 // Define shared files
88- verbose ('[ ' . $ stage. '] Syncing shared files ' );
88+ verbose ('[ ' . $ stage . '] Syncing shared files ' );
8989 SSH ::execute ($ stage , $ items ['files ' ]);
9090
9191 // Define shared directories
92- verbose ('[ ' . $ stage. '] Syncing shared directories ' );
92+ verbose ('[ ' . $ stage . '] Syncing shared directories ' );
9393 SSH ::execute ($ stage , $ items ['directories ' ]);
9494
9595 $ items = [];
9696 foreach ($ commands as $ command ) {
97- $ items [] = 'cd ' . $ home. '/releases/ ' . $ releaseName. ' && ' . $ command ;
97+ $ items [] = 'cd ' . $ home . '/releases/ ' . $ releaseName . ' && ' . $ command ;
9898 }
9999 // Define commands
100- verbose ('[ ' . $ stage. '] Executing custom commands ' );
100+ verbose ('[ ' . $ stage . '] Executing custom commands ' );
101101 SSH ::execute ($ stage , $ items );
102102
103103 // Define post deploy actions
104- verbose ('[ ' . $ stage. '] Linking new release to /current directory and removing temp ' );
104+ verbose ('[ ' . $ stage . '] Linking new release to /current directory and removing temp ' );
105105 SSH ::execute ($ stage , [
106- 'ln -sfn ' . $ home. '/releases/ ' . $ releaseName. ' ' . $ home. '/current ' ,
107- 'rm -rf ' . $ home. '/shared/* ' ,
106+ 'ln -sfn ' . $ home . '/releases/ ' . $ releaseName . ' ' . $ home . '/current ' ,
107+ 'rm -rf ' . $ home . '/shared/* ' ,
108108 ]);
109109
110110 // Remove old deploys
111111 $ items = [];
112112 foreach ($ toRemove as $ dir => $ val ) {
113- $ items [] = 'echo "Removing release ' . $ dir. '" && rm -rf ' . $ home. '/releases/ ' . $ dir ;
113+ $ items [] = 'echo "Removing release ' . $ dir . '" && rm -rf ' . $ home . '/releases/ ' . $ dir ;
114114 }
115- verbose ('[ ' . $ stage. '] Cleaning up old releases ' );
115+ verbose ('[ ' . $ stage . '] Cleaning up old releases ' );
116116 SSH ::execute ($ stage , $ items );
117117
118118 $ ldh [$ releaseName ] = true ;
@@ -125,15 +125,15 @@ public static function doDeploy($stage, $branch, $ldh)
125125 */
126126 public static function doRollback (Connection $ connection , $ stage , $ ldh , $ dirs )
127127 {
128- $ home = config ('laravel-deploy-helper.stages. ' . $ stage. '.remote.root ' );
128+ $ home = config ('laravel-deploy-helper.stages. ' . $ stage . '.remote.root ' );
129129
130130 // Define post deploy actions
131131 $ connection ->define ('preformRollback ' , [
132- 'ln -sfn ' . $ home. '/releases/ ' . $ dirs [1 ]. ' ' . $ home. '/current ' ,
133- 'rm -rf ' . $ home. '/releases/ ' . $ dirs [0 ],
132+ 'ln -sfn ' . $ home . '/releases/ ' . $ dirs [1 ] . ' ' . $ home . '/current ' ,
133+ 'rm -rf ' . $ home . '/releases/ ' . $ dirs [0 ],
134134 ]);
135135
136- verbose ("\t" . 'Hold my beer, We \'re rolling back ' );
136+ verbose ("\t" . 'Hold my beer, We \'re rolling back ' );
137137 $ connection ->task ('preformRollback ' );
138138
139139 unset($ dirs [0 ]);
@@ -147,20 +147,29 @@ public static function doRollback(Connection $connection, $stage, $ldh, $dirs)
147147 return $ ldhs ;
148148 }
149149
150- public static function doPatch (Connection $ connection , $ stage , $ branch )
150+ /**
151+ * @param $stage
152+ * @param $branch
153+ */
154+ public static function doPatch ($ stage , $ branch )
151155 {
152156 $ home = config ('laravel-deploy-helper.stages. ' . $ stage . '.remote.root ' );
153157
154- dd (Command:: builder ( ' git ' ,
155- [ ' apply ' , ' --reject ' , ' --whitespace=fix ' , ' --directory= ' . $ home . ' /patches/*.patch ' ]) );
158+ // setup ssh connection to remote
159+ $ connection = SSH :: instance ()-> into ( $ stage );
156160
157161 $ connection ->define ('preformPatch ' , [
158162 Command::builder ('cd ' , [$ home . '/current ' ]),
159163 Command::builder ('ls ' , ['-haml ' ]),
164+
165+ Command::builder ('git ' , ['config ' , 'user.email ' , 'git+LDH@localhost.ext ' ]),
166+ Command::builder ('git ' , ['config ' , 'user.name ' , 'LDH ' ]),
167+
160168 Command::builder ('git ' , ['fetch ' ]),
161- Command::builder ('git ' , ['format-patch ' , 'origin/ ' . $ branch , 'FETCH_HEAD ' , '-o ' , $ home . '/patches ' ]),
162169 Command::builder ('git ' ,
163- ['apply ' , '--reject ' , '--whitespace=fix ' , '--directory= ' . $ home . '/patches/*.patch ' ]),
170+ ['format-patch ' , '-1 ' , 'origin/ ' . $ branch , 'FETCH_HEAD ' , '-o ' , $ home . '/patches ' ]),
171+ 'git apply --reject --whitespace=fix ' . $ home . '/patches/* ' ,
172+ Command::builder ('rm ' , ['-rf ' , $ home . '/patches ' ])
164173 ]);
165174
166175 verbose ("\t" . 'Hold on tight, trying to patch! ' );
0 commit comments