55use JTMcC \AtomicDeployments \Events \DeploymentSuccessful ;
66use JTMcC \AtomicDeployments \Helpers \ConsoleOutput ;
77use JTMcC \AtomicDeployments \Models \AtomicDeployment ;
8- use JTMcC \AtomicDeployments \Services \AtomicDeployments ;
8+ use JTMcC \AtomicDeployments \Services \AtomicDeploymentService ;
9+ use JTMcC \AtomicDeployments \Services \Deployment ;
910use JTMcC \AtomicDeployments \Services \Output ;
1011
1112class DeployCommand extends BaseCommand
@@ -21,48 +22,47 @@ public function handle()
2122 {
2223 Output::alert ('Running Atomic Deployment ' );
2324
24- $ buildPath = config ('atomic-deployments.build-path ' );
25- $ deploymentLink = config ('atomic-deployments.deployment-link ' );
26- $ deploymentsPath = config ('atomic-deployments.deployments-path ' );
2725 $ migrate = config ('atomic-deployments.migrate ' , []);
28-
29- $ atomicDeployment = (new AtomicDeployments (
30- $ deploymentLink ,
31- $ deploymentsPath ,
32- $ buildPath ,
33- $ migrate ,
34- $ this ->option ('dry-run ' )
35- ));
26+ $ dryRun = $ this ->option ('dry-run ' );
3627
3728 if ($ hash = $ this ->option ('hash ' )) {
3829 Output::info ("Updating symlink to previous build: {$ hash }" );
3930
40- $ deploymentModel = AtomicDeployment::successful ()->where ('commit_hash ' , $ hash )->orderBy ( ' id ' , ' desc ' )-> first ();
31+ $ deploymentModel = AtomicDeployment::successful ()->where ('commit_hash ' , $ hash )->first ();
4132
4233 if (!$ deploymentModel || !$ deploymentModel ->hasDeployment ) {
4334 Output::warn ("Build not found for hash: {$ hash }" );
4435 } else {
36+ $ atomicDeployment = AtomicDeploymentService::create (
37+ new Deployment ($ deploymentModel ),
38+ $ migrate ,
39+ $ dryRun
40+ );
41+
4542 try {
46- $ atomicDeployment ->linkDeployment (
47- $ deploymentModel ->deployment_link ,
48- $ deploymentModel ->deployment_path
49- );
50- $ atomicDeployment ->confirmSymbolicLink ($ deploymentModel ->deployment_path );
43+ $ atomicDeployment ->getDeployment ()->linkDeployment ();
44+ $ atomicDeployment ->confirmSymbolicLink ();
5145 DeploymentSuccessful::dispatch ($ atomicDeployment , $ deploymentModel );
5246 } catch (\Throwable $ e ) {
47+ $ atomicDeployment ->failed ();
5348 Output::throwable ($ e );
54- $ atomicDeployment ->rollback ();
5549 }
5650 }
5751 } else {
52+ $ atomicDeployment = AtomicDeploymentService::create ($ migrate , $ dryRun );
53+
5854 Output::info ('Running Deployment... ' );
5955
60- if ($ deployDir = trim ($ this ->option ('directory ' ))) {
61- Output::info ("Deployment directory option set. Deployment will use {$ deployDir }" );
62- $ atomicDeployment ->setDeploymentDirectory ($ deployDir );
56+ try {
57+ if ($ deployDir = trim ($ this ->option ('directory ' ))) {
58+ Output::info ("Deployment directory option set - Deployment will use directory: {$ deployDir } " );
59+ $ atomicDeployment ->getDeployment ()->setDeploymentDirectory ($ deployDir );
60+ }
61+ $ atomicDeployment ->deploy (fn () => $ atomicDeployment ->cleanBuilds (config ('atomic-deployments.build-limit ' )));
62+ } catch (\Throwable $ e ) {
63+ $ atomicDeployment ->failed ();
64+ Output::throwable ($ e );
6365 }
64-
65- $ atomicDeployment ->deploy (fn () => $ atomicDeployment ->cleanBuilds (config ('atomic-deployments.build-limit ' )));
6666 }
6767
6868 Output::info ('Finished ' );
0 commit comments