mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	Allow a release to be zipped
If you enable the parameter 'releases: compressreleases: true', every release except the current wil be added to a tar.gz. This is to preserve diskspace on the remote host.
This commit is contained in:
		
							parent
							
								
									d3c8cf5767
								
							
						
					
					
						commit
						82c5305137
					
				@ -247,4 +247,64 @@ abstract class AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		return $command;
 | 
							return $command;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @param $releasesDirectory
 | 
				
			||||||
 | 
						 * @param $releaseId
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						protected function tarRelease($releaseId)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$result = true;
 | 
				
			||||||
 | 
							// for given release, check if tarred
 | 
				
			||||||
 | 
							$output = '';
 | 
				
			||||||
 | 
							$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
 | 
							$currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
 | 
				
			||||||
 | 
							$currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
 | 
				
			||||||
 | 
							$this->runCommandRemote($command, $output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// if not, do so
 | 
				
			||||||
 | 
							if (!$output) {
 | 
				
			||||||
 | 
								$commands = array();
 | 
				
			||||||
 | 
								$commands[] = 'mv ' . $currentReleaseDirectory . ' ' . $currentReleaseDirectoryTemp;
 | 
				
			||||||
 | 
								$commands[] = 'mkdir ' . $currentReleaseDirectory;
 | 
				
			||||||
 | 
								$commands[] = 'tar cfz ' . $currentRelease . ' ' . $currentReleaseDirectoryTemp;
 | 
				
			||||||
 | 
								$commands[] = 'rm -rf ' . $currentReleaseDirectoryTemp;
 | 
				
			||||||
 | 
								$command = implode(' && ', $commands);
 | 
				
			||||||
 | 
								$result = $this->runCommandRemote($command, $output);
 | 
				
			||||||
 | 
								return $result;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return $result;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected function untarRelease($releaseId)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$result = true;
 | 
				
			||||||
 | 
							// for given release, check if tarred
 | 
				
			||||||
 | 
							$output = '';
 | 
				
			||||||
 | 
							$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
 | 
							$currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
 | 
				
			||||||
 | 
							$currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
 | 
				
			||||||
 | 
							$this->runCommandRemote($command, $output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// if tarred, untar now
 | 
				
			||||||
 | 
							if ($output) {
 | 
				
			||||||
 | 
								$commands = array();
 | 
				
			||||||
 | 
								$commands[] = 'tar xfz ' . $currentRelease;
 | 
				
			||||||
 | 
								$commands[] = 'rm -rf ' . $currentReleaseDirectory;
 | 
				
			||||||
 | 
								$commands[] = 'mv ' .$currentReleaseDirectoryTemp . ' ' . $currentReleaseDirectory;
 | 
				
			||||||
 | 
								$command = implode(' && ', $commands);
 | 
				
			||||||
 | 
								$result = $this->runCommandRemote($command, $output);
 | 
				
			||||||
 | 
								return $result;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return $result;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -44,7 +44,16 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
 | 
				
			|||||||
				$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
 | 
									$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
 | 
								$releaseId = $this->getConfig()->getReleaseId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if ($this->getConfig()->release('compressreleases', false) == true) {
 | 
				
			||||||
 | 
									// Tar.gz releases
 | 
				
			||||||
 | 
									$result = $this->tarReleases() && $result;
 | 
				
			||||||
 | 
									// Untar new release
 | 
				
			||||||
 | 
									$result = $this->untarRelease($releaseId) && $result;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$currentCopy = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Check if target user:group is specified
 | 
								//Check if target user:group is specified
 | 
				
			||||||
			$userGroup = $this->getConfig()->deployment('owner');
 | 
								$userGroup = $this->getConfig()->deployment('owner');
 | 
				
			||||||
 | 
				
			|||||||
@ -130,6 +130,13 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
 | 
				
			|||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										if ($this->getConfig()->release('compressreleases', false) == true) {
 | 
				
			||||||
 | 
											// Tar the current
 | 
				
			||||||
 | 
											$result = $this->tarReleases() && $result;
 | 
				
			||||||
 | 
											// Untar the rollbackto
 | 
				
			||||||
 | 
											$result = $this->untarRelease($releaseId) && $result;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					// Changing Release
 | 
										// Changing Release
 | 
				
			||||||
					Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
 | 
										Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user