Skip to content
Snippets Groups Projects
Commit 63636c9d authored by hahn's avatar hahn
Browse files

initial - temp checkin 4

parent 9576b875
No related branches found
No related tags found
No related merge requests found
Showing
with 170 additions and 65 deletions
<?php
require_once("../config/inc_projects_config.php");
require_once("../classes/project.class.php");
require_once("../classes/formgen.class.php");
require_once("inc_functions.php");
$sOut='<h1>Build</h1>';
$sError='';
// --- Checks
if (!array_key_exists("prj", $_GET)){
$sError.='<li>Es wurde kein Projekt angegeben.</li>';
}
if ($sError){
$sOut.='<i class="icon-exclamation-sign"></i> FEHLER:<ul>'.$sError.'</ul>';
} else {
$oPrj=new project($_GET["prj"]);
$sNext=$oPrj->getNextPhase();
$sOut='
<h1>Build '.$oPrj->getLabel().'</h1>
<p>' . $oPrj->getDescription() . '</p>
<hr>
<p>
Es wird ein neues Paket erstellt und auf die Phase <em class="'.$sNext.'">'.$sNext.'</em> installiert.<br>
Du kannst einen Kommentar zu diesem Deployment angeben und darin beschreiben, worin das Update
besteht (Fix, neue Funktion, ...).
</p>
';
// Eingabe Kommentare zum Deployment
//$oForm=new formgen();
$sOut.='
<hr>
' . enterDeployinfos() . '
<hr>
Aktionen
';
}
$sOut.=aHome();
// -- Ausgabe
$sPhpOut=$sOut;
?>
File moved
......@@ -8,11 +8,18 @@ class project {
// ----------------------------------------------------------------------
// CONFIG
// ----------------------------------------------------------------------
protected $_aConfig = array();
protected $_aData = array();
protected $_sPackageDir = false;
protected $_aPhases=array();
protected $_sCfgfile="../config/inc_projects_config.php";
private $_aConfig = array();
private $_aData = array();
private $_sWorkDir = false;
private $_sPackageDir = false;
private $_aPhases=array();
private $_sCfgfile="../config/inc_projects_config.php";
private $_aPlaces=array(
"onhold"=>"Queue",
"ready4deployment"=>"Repo",
"deployed"=>"Installiert",
);
// ----------------------------------------------------------------------
// constructor
......@@ -39,7 +46,8 @@ class project {
*/
private function _readConfig() {
require($this->_sCfgfile);
$this->_sPackageDir = $aConfig['packageDir'];
$this->_sWorkDir = $aConfig['workDir'];
$this->_sPackageDir = $this->_sWorkDir.'/packages';
$this->_aPhases=$aConfig["phases"];
return true;
}
......@@ -61,10 +69,99 @@ class project {
return true;
}
private function _execAndSend($sCommand){
$sReturn='';
$bUseHtml=$_SERVER?true:false;
ob_implicit_flush(true);ob_end_flush();
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
flush();
$process = proc_open($sCommand, $descriptorspec, $pipes, realpath('./'), array());
$sReturn.="[".date("H:i:s d.m.Y")."] $sCommand";
$sReturn.=$bUseHtml?"<br><pre>":"\n";
if (is_resource($process)) {
$oStatus = proc_get_status($process);
while ($s = fgets($pipes[1])) {
$sReturn.=$s;
flush();
}
}
$sReturn.=$bUseHtml?"</pre>":"\n";
$sReturn.="[".date("H:i:s d.m.Y")."] finished; rc=".$oStatus['exitcode'];
$sReturn.=$bUseHtml?"<hr>":"\n---------\n";
return $sReturn;
}
// ----------------------------------------------------------------------
// GETTER
// ----------------------------------------------------------------------
private function _getTempDir(){
$s=$this->_sWorkDir."/build/".$this->_aConfig["fileprefix"]."_".date("Ymd-His");
// TODO: auskommentieren
$s=$this->_sWorkDir."/build/".$this->_aConfig["fileprefix"]."_temp";
return $s;
}
/**
* get base of filename for infofile and package (without extension)
* @param string $sPhase one of preview|stage|live ...
* @param string $sPlace one of onhold|ready4deployment|deployed
* @return string
*/
private function _getFileBase($sPhase, $sPlace){
if (!array_key_exists($sPhase, $this->_aPhases)){
die("ERROR: _getFileBase - this phase does not exist: $sPhase.");
}
if (!array_key_exists($sPlace, $this->_aPlaces)){
die("ERROR: _getFileBase - this place does not exist: $sPhase.");
}
// local file for onhold|ready4deployment
$sBase=$this->_sPackageDir."/".$sPhase."/".$this->_aConfig["fileprefix"];
if ($sPlace=="onhold") $sBase.="_onhold";
// url for deployed
if ($sPlace=="deployed"){
if ($this->isActivePhase($sPhase) && array_key_exists("url", $this->_aConfig["phases"][$sPhase])){
$sBase=$this->_aConfig["phases"][$sPhase]["url"].$this->_aConfig["fileprefix"];
} else {
$sBase='';
}
}
return $sBase;
}
/**
* get filename for info file
* @param string $sPhase one of preview|stage|live ...
* @param string $sPlace one of onhold|ready4deployment|deployed
* @return string
*/
private function _getInfofile($sPhase, $sPlace){
$sBase=$this->_getFileBase($sPhase, $sPlace);
return $sBase?$sBase.".json":false;
}
/**
* get filename for package file
* @param string $sPhase one of preview|stage|live ...
* @param string $sPlace one of onhold|ready4deployment|deployed
* @return string
*/
private function _getPackagefile($sPhase, $sPlace){
$sBase=$this->_getFileBase($sPhase, $sPlace);
return $sBase?$sBase.".tgz":false;
}
/**
* get conmplete config of the project
* @return array
......@@ -120,8 +217,7 @@ class project {
// a blocked package is waiting for deployment timeslot?
$sKey="onhold";
$sBaseFilename=$this->_sPackageDir."/".$sPhase."/".$this->_aConfig["fileprefix"];
$sJsonfile=$sBaseFilename."_onhold.json";
$sJsonfile=$this->_getInfofile($sPhase, $sKey);
$aTmp[$sKey]=array();
if (file_exists($sJsonfile)){
$aJson=json_decode(file_get_contents($sJsonfile), true);
......@@ -138,11 +234,10 @@ class project {
// package for puppet
$sKey="ready4deployment";
$sBaseFilename=$this->_sPackageDir."/".$sPhase."/".$this->_aConfig["fileprefix"];
$sJsonfile=$sBaseFilename.".json";
$sJsonfile=$this->_getInfofile($sPhase, $sKey);
$aTmp[$sKey]=array();
if (file_exists($sJsonfile)){
$sPkgfile=$sBaseFilename.".tgz";
$sPkgfile=$this->_getPackagefile($sPhase, $sKey);
if (file_exists($sPkgfile)){
$aJson=json_decode(file_get_contents($sJsonfile), true);
if (array_key_exists("timestamp", $aJson)){
......@@ -162,6 +257,7 @@ class project {
// published data
$sKey="deployed";
$sJsonfile=$this->_getInfofile($sPhase, $sKey);
$aTmp[$sKey]=array();
if ($this->isActivePhase($sPhase)){
$sJsonUrl=$this->_aConfig["phases"][$sPhase]["url"].$this->_aConfig["fileprefix"].".json";
......@@ -305,6 +401,42 @@ class project {
// ----------------------------------------------------------------------
// ACTIONS
// ----------------------------------------------------------------------
public function build(){
$sReturn=false;
switch ($this->_aConfig["build"]["type"]) {
case "git":
$sTempDir=$this->_getTempDir();
$sFirstLevel=$this->getNextPhase();
// $this->_execAndSend($sCommand);
$sReturn.="TODO:<br>";
@mkdir($sTempDir);
$this->_execAndSend("");
$sReturn.="* GIT PULL ".$this->_aConfig["build"]["url"]."<br>";
$sReturn.="* wenn Hook-Skript im Projekt, dann ausfuehren<br>";
$sReturn.="* Check: gibt es ein public_html - wenn nein: abbrechen<br>";
$sReturn.="* <br>";
$sReturn.="* Info-JSON erstellen und in public_html ablegen<br>";
$sReturn.="* Verzeichnis komprimieren zu [Paketarchiv]/[prj].tgz<br>";
$sReturn.="* Infofilezu [Paketarchiv]/[prj].json<br>";
$sReturn.="* Temdir loeschen ".$sTempDir."<br>";
$sReturn.="* <br>";
$sReturn.="* Move [Paketarchiv]/[prj].[tgz+json] zu [RepoDir-von-".$sFirstLevel."]<br>";
$sReturn.="<br>";
break;
default:
die("Build Type not supported: " . $this->_aConfig["build"]["type"]);
break;
}
return $sReturn;
}
}
?>
\ No newline at end of file
......@@ -29,6 +29,28 @@ $aConfig=array(
// Projekte
// ----------------------------------------------------------------------
$aProjects=array(
"ci"=>array(
"label"=>"CI Webgui",
"fileprefix"=>"ci-webgui",
"description" => 'Webgui zum Deployen von Web-Projekten',
"contact" => 'axel.hahn@iml.unibe.ch',
"build"=>array(
"type"=>"git", // one of git, svn, ...
"url"=>"gitlab.iml.unibe.ch:admins/imldeployment.git",
),
"phases"=>array(
"preview"=>array(
// "url"=>"http://preview.scrudu.iml.unibe.ch/",
"url"=>"http://ci.iml.unibe.ch/deployment/",
),
"stage"=>array(
),
"live"=>array(
// "url"=>"http://www.scrudu.iml.unibe.ch/"
),
),
),
"scrudu"=>array(
"label"=>"SCRUDU",
"fileprefix"=>"scrudu",
......@@ -42,10 +64,9 @@ $aProjects=array(
"phases"=>array(
"preview"=>array(
// "url"=>"http://preview.scrudu.iml.unibe.ch/",
"url"=>"http://ci.iml.unibe.ch/deployment/",
),
"stage"=>array(
"url"=>"http://stage.scrudu.iml.unibe.ch/"
// "url"=>"http://stage.scrudu.iml.unibe.ch/"
),
"live"=>array(
// "url"=>"http://www.scrudu.iml.unibe.ch/"
......@@ -97,7 +118,8 @@ $aTypeAbstraction=array(
switch ($_SERVER["SERVER_NAME"]) {
case "localhost":
$aConfig['workDir']="D:/imldeployment";
case "dev.ci.iml.unibe.ch":
$aConfig['workDir']="D:\imldeployment";
$aProjects["scrudu"]["phases"]["preview"]["url"]="http://localhost/deployment/";
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment