소스 검색

Reformateo de tools/src/DockerInventory-GetSource-MergeHostFile-Release

Se agrego al Release.php la creacion del  directorio

Se agrego el Release.php un log y la pregunta si se desea reutilizar el log para la nueva creacion

Se creo un contenedor para ejecutar el codigo

Se creo el archivo tools/execute.sh como entrypont del docker
gabriel 7 년 전
부모
커밋
bb32b58a95
8개의 변경된 파일857개의 추가작업 그리고 592개의 파일을 삭제
  1. 34 0
      tools/Dockerfile
  2. 5 3
      tools/composer.json
  3. BIN
      tools/composer.phar
  4. 13 0
      tools/execute.sh
  5. 39 43
      tools/src/DockerInventory.php
  6. 37 41
      tools/src/GetSource.php
  7. 41 45
      tools/src/MergeHostsFile.php
  8. 688 460
      tools/src/Release.php

+ 34 - 0
tools/Dockerfile

@@ -0,0 +1,34 @@
+FROM debian:9
+EXPOSE 8000
+
+## install app
+RUN apt-get update && apt-get install -yq wget apt-transport-https lsb-release ca-certificates software-properties-common
+RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
+RUN sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
+RUN apt-get update && apt-get install -yq python curl git vim tmux zip build-essential php7.1
+# mysql-client php7.1 php7.1-mysql php7.1-curl php7.1-xml php7.1-zip php7.1-bcmath php7.1-mbstring php7.1-dom php7.1-amqp php7.1-soap php7.1-snmp
+## install composer
+RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
+RUN php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
+RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
+RUN php -r "unlink('composer-setup.php');"
+
+## install ansible
+RUN echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | tee /etc/apt/sources.list.d/ansible.list
+RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
+RUN apt-get update && apt-get install -yq ansible
+
+## add keys ssh from hosts
+RUN mkdir ~/.ssh
+RUN ssh-keyscan -H -p 22  bitbucket.org >> ~/.ssh/known_hosts
+## add key to container
+COPY keys /opt/keys
+RUN chmod 0600 /opt/keys/*
+
+## contains file to execute
+RUN mkdir /opt/installation
+RUN chmod -R 777 /opt/installation
+ADD . /opt/installation
+WORKDIR /opt/installation
+
+ENTRYPOINT ["/opt/installation/execute.sh"]

+ 5 - 3
tools/composer.json

@@ -3,19 +3,21 @@
         "lucciano/php-docker-lib": "dev-master",
         "kzykhys/git": "^0.1.2",
         "docker-php/docker-php": "^1.24",
-	"symfony/console": "^3.3",
+        "symfony/console": "^3.3",
         "magicalex/write-ini-file": "^1.2",
         "rlanvin/php-ip": "1.*",
         "guzzlehttp/guzzle": "~6.0",
         "maxakawizard/json-collection-parser": "^1.1"
     },
     "autoload": {
-        "psr-4": {"FD3\\": "src/"}
+        "psr-4": {
+            "FD3\\": "src/"
+        }
     },
     "repositories": [
         {
             "type": "vcs",
-            "url":  "https://github.com/lucciano/php-docker-lib.git"
+            "url": "https://github.com/lucciano/php-docker-lib.git"
         }
     ]
 }

BIN
tools/composer.phar


+ 13 - 0
tools/execute.sh

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+COMMAND="php cmd.php"
+
+if [ "$#" -ne 0 ];
+then
+  for word in "$@" 
+  do 
+    COMMAND="$COMMAND $word" 
+  done
+fi
+
+eval $COMMAND

+ 39 - 43
tools/src/DockerInventory.php

@@ -12,57 +12,53 @@ use Docker\Docker;
 
 use FD3\DevOps\FileSystem;
 
-class DockerInventory extends Command{
+class DockerInventory extends Command
+{
     protected function configure()
     {
-        $this 
-        ->setName('docker:inventory')
-
-        ->setDescription('Get a ansible inventory based on the running container and the docker .')
-
-        ->setHelp('...')
-
-	 ->addArgument('dir', InputArgument::REQUIRED, 'The dir where the docker-composer.yml files is located.')
-	// ->addOption('source-name', null, InputOption::VALUE_REQUIRED, 'Rename the source to this name.', "upstream")
-    ;
+        $this
+            ->setName('docker:inventory')
+            ->setDescription('Get a ansible inventory based on the running container and the docker .')
+            ->setHelp('...')
+            ->addArgument('dir', InputArgument::REQUIRED, 'The dir where the docker-composer.yml files is located.')// ->addOption('source-name', null, InputOption::VALUE_REQUIRED, 'Rename the source to this name.', "upstream")
+        ;
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-	$dir = $input->getArgument("dir");
-	$projname = basename(realpath($dir));
-	$docker = new Docker();
-	$containerManager = $docker->getContainerManager();
-	$containers = $containerManager->findAll();
+        $dir = $input->getArgument("dir");
+        $projname = basename(realpath($dir));
+        $docker = new Docker();
+        $containerManager = $docker->getContainerManager();
+        $containers = $containerManager->findAll();
+        $groups = array();
+        foreach ($containers as $container) {
+            $labels = $container->getLabels();
+            if (strcmp($labels["com.docker.compose.project"], $projname) === 0) {
+                if (!isset($groups[$labels["com.docker.compose.service"]])) {
+                    $groups[$labels["com.docker.compose.service"]] = array();
+                }
+                foreach ($container->getNames() as $names) {
+                    if (strpos($names, "/") === 0) {
+                        $name = substr($names, 1);
+                    }
+                    $groups[$labels["com.docker.compose.service"]][] = $name;
+                }
+            }
+        }
 
-	$groups = array();
-	foreach($containers as $container){
-		$labels = $container->getLabels();
-		if(strcmp($labels["com.docker.compose.project"], $projname)===0){
-			if(!isset($groups[$labels["com.docker.compose.service"]])){
-				$groups[$labels["com.docker.compose.service"]] = array();
-			}
-			foreach($container->getNames() as $names){
-				if(strpos($names, "/") === 0){
-					$name = substr($names,1);
-				}
-				$groups[$labels["com.docker.compose.service"]][] = $name;
-			}
-		}
-	}
+        $contAll = "";
+        $cont = "";
+        foreach ($groups as $name => $group) {
 
-	$contAll = "";
-	$cont = "";
-	foreach($groups as $name => $group){
-		
-		$cont .= "\n[".$name."]\n";
-		foreach($group as $host){
-			$cont .= $host."\n";
-			$contAll .= $host."\n";
-		}
-	}
+            $cont .= "\n[" . $name . "]\n";
+            foreach ($group as $host) {
+                $cont .= $host . " ansible_connection=docker\n";
+                $contAll .= $host . " ansible_connection=docker\n";
+            }
+        }
 
-	$dirObj = new FileSystem($dir);
-	$dirObj->file("inventory.ini")->content($cont . "\n[all]\n".$contAll);
+        $dirObj = new FileSystem($dir);
+            $dirObj->file("inventory.ini")->content($cont . "\n[all]\n" . $contAll);
     }
 }

+ 37 - 41
tools/src/GetSource.php

@@ -15,51 +15,47 @@ class GetSource extends Command
 {
     protected function configure()
     {
-        $this 
-        ->setName('get:source')
-
-        ->setDescription('Get the source using a ini file.')
-
-        ->setHelp('This command allows you to fetch code based on the git.ini file configuration...')
-
-	 ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
-	 ->addOption('source-name', null, InputOption::VALUE_REQUIRED, 'Rename the source to this name.', "upstream")
-    ;
+        $this
+            ->setName('get:source')
+            ->setDescription('Get the source using a ini file.')
+            ->setHelp('This command allows you to fetch code based on the git.ini file configuration...')
+            ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
+            ->addOption('source-name', null, InputOption::VALUE_REQUIRED, 'Rename the source to this name.', "upstream");
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-	$file = $input->getArgument("ini_file");
-	
-	$realpath = realpath($file);
-	$dirname = dirname($realpath);
-	if(!chdir($dirname)){
-		throw new \Exception("Can't change working directory to ".$dirname);
-	}
-	
-	$content = parse_ini_file($realpath, true);
-	foreach($content as $sec => $conf){
-		$git = new Git();
-		$git_path = $dirname.'/'.$sec;
-
-		try{
-			$output->writeln($conf["url"]. " -> " . $git_path);
-			$git->clone($conf["url"], $git_path);
-		}catch (GitException $e){
-			throw $e;
-			$output->write("repo $sec exists \n");
-		}
-		$git->setRepository($git_path);
-
-		try{
-			$git->remote->rm($input->getOption("source-name"));
-		}catch (GitException $e){
-			
-		}
-		$git->remote->add($input->getOption("source-name"), $conf["url"]);
+        $file = $input->getArgument("ini_file");
+
+        $realpath = realpath($file);
+        $dirname = dirname($realpath);
+        if (!chdir($dirname)) {
+            throw new \Exception("Can't change working directory to " . $dirname);
+        }
+
+        $content = parse_ini_file($realpath, true);
+        foreach ($content as $sec => $conf) {
+            $git = new Git();
+            $git_path = $dirname . '/' . $sec;
+
+            try {
+                $output->writeln($conf["url"] . " -> " . $git_path);
+                $git->clone($conf["url"], $git_path);
+            } catch (GitException $e) {
+                throw $e;
+                $output->write("repo $sec exists \n");
+            }
+            $git->setRepository($git_path);
+
+            try {
+                $git->remote->rm($input->getOption("source-name"));
+            } catch (GitException $e) {
+
+            }
+            $git->remote->add($input->getOption("source-name"), $conf["url"]);
+
+            $git->checkout($conf["branch"]);
+        }
 
-		$git->checkout($conf["branch"]);
-	}
-	
     }
 }

+ 41 - 45
tools/src/MergeHostsFile.php

@@ -12,58 +12,54 @@ class MergeHostsFile extends Command
 {
     protected function configure()
     {
-        $this 
-        ->setName('merge:hostsfile')
-
-        ->setDescription('Merge (or remove) two hostfiles to /etc/hosts.')
-
-        ->setHelp('This command allows you to a new installation...')
-
-	 ->addArgument('file', InputArgument::REQUIRED, 'The file to use.')
-	 ->addOption('dest',null, InputOption::VALUE_REQUIRED, 'The /etc/hosts file where to write', "/etc/hosts")
-	 ->addOption('ref', null, InputOption::VALUE_REQUIRED, 'The reference to add as a comment to simplify the remove', "handled by fd3")
-	 ->addOption('del', 'd', InputOption::VALUE_NONE, 'Remove the merged values based on the ref parameter')
-    ;
+        $this
+            ->setName('merge:hostsfile')
+            ->setDescription('Merge (or remove) two hostfiles to /etc/hosts.')
+            ->setHelp('This command allows you to a new installation...')
+            ->addArgument('file', InputArgument::REQUIRED, 'The file to use.')
+            ->addOption('dest', null, InputOption::VALUE_REQUIRED, 'The /etc/hosts file where to write', "/etc/hosts")
+            ->addOption('ref', null, InputOption::VALUE_REQUIRED, 'The reference to add as a comment to simplify the remove', "handled by fd3")
+            ->addOption('del', 'd', InputOption::VALUE_NONE, 'Remove the merged values based on the ref parameter');
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
     {
         $file = $input->getArgument('file');
-	$dest = $input->getOption("dest");
-	$id   = $input->getOption("ref");
-	$del = $input->getOption("del");
-	$dest_content = explode("\n",file_get_contents($dest));
-	$orig_content = explode("\n",file_get_contents($file));
+        $dest = $input->getOption("dest");
+        $id = $input->getOption("ref");
+        $del = $input->getOption("del");
+        $dest_content = explode("\n", file_get_contents($dest));
+        $orig_content = explode("\n", file_get_contents($file));
+
+        foreach ($dest_content as $k => $spect) {
+            if (strpos($spect, $id) !== false) {
+                unset($dest_content[$k]);
+            }
+        }
+        foreach ($orig_content as $k => $spect) {
+            $spect = trim($spect);
+            preg_match("|[^\s]*|", $spect, $match);
+            if (isset($match[0])) {
+                try {
+                    $ip = \IP::create($match[0]);
+                    $orig_content[$k] = $spect . "\t#$id";
+                } catch (\InvalidArgumentException $e) {
+                }
+            }
+        }
+        $content = "";
+        foreach ($dest_content as $line) {
+            $content .= $line . "\n";
+        }
+        if (!$del) {
+
+            foreach ($orig_content as $line) {
+                $content .= $line . "\n";
+            }
+        }
 
-	foreach($dest_content as $k => $spect){
-		if(strpos($spect, $id) !== false){
-			unset($dest_content[$k]);
-		}
-	}
-	foreach($orig_content as $k => $spect){
-		$spect = trim($spect);
-		preg_match("|[^\s]*|", $spect, $match);
-		if(isset($match[0])){
-			try{
-				$ip= \IP::create($match[0]);
-				$orig_content[$k] = $spect . "\t#$id";
-			}catch(\InvalidArgumentException $e){
-			}
-		}
-	}
-	$content = "";
-	foreach($dest_content as $line){
-		$content .= $line . "\n";
-	}
-	if(!$del){	
+        file_put_contents($dest, $content);
 
-		foreach($orig_content as $line){
-			$content .= $line . "\n";
-		}
-	}
 
-	file_put_contents($dest, $content);
-	
-	
     }
 }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 688 - 460
tools/src/Release.php