|
@@ -0,0 +1,355 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FD3;
|
|
|
+
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+use Docker\Composer\FileFormat2;
|
|
|
+
|
|
|
+use Symfony\Component\Yaml\Yaml;
|
|
|
+
|
|
|
+class Release extends Command
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('make:install')
|
|
|
+
|
|
|
+ ->setDescription('Create a new install.')
|
|
|
+
|
|
|
+ ->setHelp('This command allows you to create a new installation...')
|
|
|
+
|
|
|
+ ->addArgument('dir', InputArgument::REQUIRED, 'The directory where to create the installation.')
|
|
|
+ ->addOption('base-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/base.git")
|
|
|
+ ->addOption('base-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Base app', "master")
|
|
|
+
|
|
|
+ ->addOption('ftth-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/ftth.git")
|
|
|
+ ->addOption('ftth-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Ftth appFtth', "master")
|
|
|
+
|
|
|
+ ->addOption('mapas-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/mapas.git")
|
|
|
+ ->addOption('mapas-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Mapas app', "master")
|
|
|
+
|
|
|
+ ->addOption('stats-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/stats.git")
|
|
|
+ ->addOption('stats-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Stats app', "master")
|
|
|
+
|
|
|
+ ->addOption('extra-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/extra.git")
|
|
|
+ ->addOption('extra-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Extra files and apps', "master")
|
|
|
+
|
|
|
+ ->addOption('host-ip', null, InputOption::VALUE_REQUIRED, 'Ip of the runnning host to be added to the /etc/hosts file, eventually', "127.0.1.1")
|
|
|
+
|
|
|
+ ->addOption('domain', null, InputOption::VALUE_REQUIRED, 'Domain where the flowdat will be installed', "fd3.flowdat.com")
|
|
|
+
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ $dir = $input->getArgument('dir');
|
|
|
+ $domain = $input->getOption("domain");
|
|
|
+ $dObj = new DevOps\FileSystem($dir);
|
|
|
+ $dObj->dirExists()->realpath();
|
|
|
+
|
|
|
+ $install_config = array(
|
|
|
+ "base" => array(
|
|
|
+ 'url' => $input->getOption("base-repo"),
|
|
|
+ 'branch' => $input->getOption("base-ref"),
|
|
|
+ ),
|
|
|
+ "ftth" => array(
|
|
|
+ 'url' => $input->getOption("ftth-repo"),
|
|
|
+ 'branch' => $input->getOption("ftth-ref"),
|
|
|
+ ),
|
|
|
+ "mapas" => array(
|
|
|
+ 'url' => $input->getOption("mapas-repo"),
|
|
|
+ 'branch' => $input->getOption("mapas-ref"),
|
|
|
+ ),
|
|
|
+ "stats" => array(
|
|
|
+ 'url' => $input->getOption("stats-repo"),
|
|
|
+ 'branch' => $input->getOption("stats-ref"),
|
|
|
+ ),
|
|
|
+ "extra" => array(
|
|
|
+ 'url' => $input->getOption("extra-repo"),
|
|
|
+ 'branch' => $input->getOption("extra-ref"),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ $dObj->file("git.ini")->writeIniConfig($install_config);
|
|
|
+
|
|
|
+ $dObj->file("docker-compose.yml")->content(
|
|
|
+ $this->getDockerComposer( "dev", "host.env", "docker.infra.flowdat.com/", $domain)
|
|
|
+ );
|
|
|
+
|
|
|
+ $config_ip = $input->getOption("host-ip");
|
|
|
+
|
|
|
+ $hostConfig = $this->getHostConfig($config_ip, $domain);
|
|
|
+ $hostfile_content = "";
|
|
|
+ foreach($hostConfig as $host => $ip){
|
|
|
+ $hostfile_content .= $ip . "\t". $host. "\n";
|
|
|
+ }
|
|
|
+ $dObj->file("hostsFile")->content($hostfile_content);
|
|
|
+ $hostEnvConfig = $this->getHostEnv($domain);
|
|
|
+ $env_content = "";
|
|
|
+ foreach($hostEnvConfig as $var => $val){
|
|
|
+ $env_content .= $var."=".$val."\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ $dObj->file('host.env')->content($env_content);
|
|
|
+ $dObj->file('mapas.oauth.env')->content("");
|
|
|
+ $dObj->file('ftth.oauth.env')->content("");
|
|
|
+ $dObj->file('stats.oauth.env')->content("");
|
|
|
+
|
|
|
+ $dObj->file('install.yml')->content(
|
|
|
+ yaml::dump(array(
|
|
|
+ "install_dir" => realpath($dir),
|
|
|
+ 'docker_apps' => array('base', 'stats', 'ftth', 'mapas'),
|
|
|
+ 'domain' => $domain,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $dObj->file('ansible.cfg')->content(
|
|
|
+ "[defaults]
|
|
|
+inventory=inventory.ini
|
|
|
+ "
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function getHostEnv($fd_domain = "fd3.flowdat.com"){
|
|
|
+ return array(
|
|
|
+ "HOST_BASE" => "base.". $fd_domain,
|
|
|
+ "HOST_FTTH" => "ftth.". $fd_domain,
|
|
|
+ "HOST_MAPAS" => "mapas.".$fd_domain,
|
|
|
+ "HOST_STATS" => "stats.".$fd_domain,
|
|
|
+ "HOST_PMA" => "pma.".$fd_domain,
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ function getHostConfig($config_ip, $fd_domain = "fd3.flowdat.com"){
|
|
|
+ return array(
|
|
|
+ "base.". $fd_domain => $config_ip,
|
|
|
+ "ftth.". $fd_domain => $config_ip,
|
|
|
+ "mapas.". $fd_domain => $config_ip,
|
|
|
+ "stats.". $fd_domain => $config_ip,
|
|
|
+ "grafana.". $fd_domain => $config_ip,
|
|
|
+ "pma.". $fd_domain => $config_ip,
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDockerComposer( $v = "dev", $host_env_file = "host.env", $registry = "docker.infra.flowdat.com/", $fd_domain = "fd3.flowdat.com")
|
|
|
+{
|
|
|
+
|
|
|
+$mysql_root_pass="235r2342gtfsw";
|
|
|
+$mysql_user="iksop";
|
|
|
+$mysq_pass="235r2342gtfsw";
|
|
|
+
|
|
|
+$oauth_client = "1_3323sq6urn8kwccg8s4ok848ggwwgkw4c08wsc4cwkc08osocc";
|
|
|
+$oauth_client_secret = "5w7gx6ptdoo4g8cwwo88o8gowosgco84sso08ssow0osg88g8k";
|
|
|
+
|
|
|
+ $composer = new FileFormat2("../");
|
|
|
+
|
|
|
+ $composer->addService("base")
|
|
|
+ ->image($registry."fd3_base:" . $v)
|
|
|
+ ->build("./base/")
|
|
|
+ ->restart("always")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->addLinks("amqp")
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "base.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_FTTH", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_STATS", "stats.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_MAPAS", "mapas.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_BASE", "base." .$fd_domain)
|
|
|
+ ->addVolumes("./base/", "/opt/base")
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("ftth")
|
|
|
+ ->image($registry."fd3_ftth:" . $v)
|
|
|
+ ->build("./ftth/")
|
|
|
+ ->restart("always")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->addLinks("base")
|
|
|
+ ->addLinks("amqp")
|
|
|
+ ->addLinks("nginx", "base.".$fd_domain)
|
|
|
+
|
|
|
+ ->addEnv_file("ftth.oauth.env")
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_FTTH", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_STATS", "stats.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_MAPAS", "mapas.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_BASE", "base.".$fd_domain)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret)
|
|
|
+ //->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
+
|
|
|
+ ->addVolumes("./ftth/", "/opt/ftth")
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("mapas")
|
|
|
+ ->image($registry."fd3_mapas:" . $v)
|
|
|
+ ->build("./mapas/")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->addLinks("base")
|
|
|
+ ->addLinks("amqp")
|
|
|
+ ->addLinks("nginx", "base.".$fd_domain)
|
|
|
+ ->addEnv_file("mapas.oauth.env")
|
|
|
+
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "mapas.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_FTTH", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_STATS", "stats.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_MAPAS", "mapas.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_BASE", "base.".$fd_domain)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret)
|
|
|
+ //->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
+
|
|
|
+ ->addVolumes("./mapas/", "/opt/mapas")
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
+ $composer->addService("stats")
|
|
|
+ ->image($registry."fd3_stats:" . $v)
|
|
|
+ ->build("./stats/")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->addLinks("base")
|
|
|
+ ->addLinks("amqp")
|
|
|
+ ->addLinks("nginx", "base.".$fd_domain)
|
|
|
+ ->addVolumes("./stats/", "/opt/stats")
|
|
|
+ ->addEnv_file("stats.oauth.env")
|
|
|
+
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "stats.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_FTTH", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_STATS", "stats.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_MAPAS", "mapas.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_BASE", "base.".$fd_domain)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret)
|
|
|
+ //->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
+
|
|
|
+ ;
|
|
|
+
|
|
|
+ /**************************************************************************************/
|
|
|
+ /* Servicios */
|
|
|
+ /**************************************************************************************/
|
|
|
+ $composer->addService("mysql")->image($registry."fd3_mysql:". $v)
|
|
|
+ ->build("./extra/mysql")
|
|
|
+ ->addVolumes("./mysql/", "/var/lib/mysql/")
|
|
|
+
|
|
|
+ ->addEnviroment("MYSQL_ROOT_PASSWORD", $mysql_root_pass)
|
|
|
+ ->addEnviroment("MYSQL_USER", $mysql_user)
|
|
|
+ ->addEnviroment("MYSQL_PASSWORD", $mysq_pass)
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("amqp")->image("rabbitmq:3-management")
|
|
|
+ ->restart("always")
|
|
|
+ ->addPorts(8072, 15672)
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
+ /**************************************************************************************/
|
|
|
+ /* Workers */
|
|
|
+ /**************************************************************************************/
|
|
|
+
|
|
|
+ $composer->addService("ftth_worker")->image($registry."fd3_ftth:" . $v)
|
|
|
+ ->build("./ftth/")
|
|
|
+ ->restart("always")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->addLinks("base")
|
|
|
+ ->addLinks("amqp")
|
|
|
+ ->addLinks("nginx", "base.".$fd_domain)
|
|
|
+
|
|
|
+
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
+ ->addEnviroment("HOST_FTTH", "ftth.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_STATS", "stats.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_MAPAS", "mapas.".$fd_domain)
|
|
|
+ ->addEnviroment("HOST_BASE", "base.".$fd_domain)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client)
|
|
|
+ //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret)
|
|
|
+
|
|
|
+ ->addVolumes("./ftth/", "/opt/ftth")
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
+ $composer->addService("phpmyadmin")->image("phpmyadmin/phpmyadmin")
|
|
|
+ ->restart("always")
|
|
|
+ ->addPorts(8080, 80)
|
|
|
+ ->addLinks("mysql", "db")
|
|
|
+
|
|
|
+ ->addEnviroment("MYSQL_ROOT_PASSWORD", $mysql_root_pass)
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "pma.".$fd_domain)
|
|
|
+ ->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
+ $composer->addService("grafana")->image("grafana/grafana")
|
|
|
+
|
|
|
+ ->addLinks("jsendpoint","endpoint")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->restart("always")
|
|
|
+ ->addEnviroment("VIRTUAL_HOST", "grafana.".$fd_domain)
|
|
|
+ ->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
+
|
|
|
+ ->addEnviroment("./statsd/grafana/lib", "/var/lib/grafana")
|
|
|
+ ->addEnviroment("GF_SECURITY_ADMIN_PASSWORD", "queRini6")
|
|
|
+ ->addEnviroment("GF_INSTALL_PLUGINS", "grafana-simple-json-datasource")
|
|
|
+ ->addEnviroment("GF_AUTH_ANONYMOUS_ORG_NAME", "Main Org.")
|
|
|
+ ->addEnviroment("GF_AUTH_ANONYMOUS_ORG_ROLE", "Viewer")
|
|
|
+ ->addEnviroment("GF_AUTH_ANONYMOUS_ENABLED", "true")
|
|
|
+ ->addEnviroment("GF_DATABASE_URL", "mysql://root:".$mysql_root_pass."@mysql:3306/grafana")
|
|
|
+ ->addEnviroment("GF_SERVER_ROOT_URL", "http://grafana.".$fd_domain."/")
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("jsendpoint")
|
|
|
+ ->image($registry."jsendpoint:$v")
|
|
|
+ ->build("./extra/statsd/endpoint/mysql")
|
|
|
+ ->addVolumes("./extra/statsd/endpoint/mysql", "/opt/datasource")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->addPorts(9000, 8000)
|
|
|
+ ->addEnviroment("MYSQL_ROOT_PASSWORD", $mysql_root_pass)
|
|
|
+ ->restart("always")
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("statsd")->build("./extra/statsd/statsd")
|
|
|
+ ->image($registry."statsd:$v")
|
|
|
+ ->addPorts("8125", "8125/udp")
|
|
|
+ ->addLinks("mysql")
|
|
|
+ ->restart("always")
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("supervisord")->build("./extra/supervisord")
|
|
|
+ ->image($registry."supervisord:$v")
|
|
|
+ ->privileged(true)
|
|
|
+ ->restart("always")
|
|
|
+ ->addEnviroment("./extra/supervisord/", "/etc/supervisord/")
|
|
|
+ ->addEnviroment("./extra/supervisord/var/", "/var/log/supervisor/")
|
|
|
+ ->addEnviroment("./extra/supervisord/sshd_config", "/etc/ssh/sshd_config")
|
|
|
+ ->addEnviroment("./extra/supervisord/bin/fiberhome", "/usr/bin/fiberhome")
|
|
|
+ ->addEnviroment("./extra/supervisord/bin/fiberlink", "/usr/bin/fiberlink")
|
|
|
+
|
|
|
+ ;
|
|
|
+
|
|
|
+ $composer->addService("nginx")->image($registry."fd3_nginx:".$v)
|
|
|
+ ->build("extra/nginx/")
|
|
|
+ ->addEnv_file($host_env_file)
|
|
|
+ ->restart("always")
|
|
|
+ //->addLinks("base")
|
|
|
+ //->addLinks("ftth")
|
|
|
+ //->addLinks("mapas")
|
|
|
+ //->addLinks("stats")
|
|
|
+ ->addPorts(80, 80)
|
|
|
+ ->addPorts(443, 443)
|
|
|
+ ->addVolumes("/var/run/docker.sock", "/tmp/docker.sock:ro")
|
|
|
+ ->addVolumes("./extra/nginx/certs", "/etc/nginx/certs:ro")
|
|
|
+ ->addVolumes("./extra/nginx/vhost.d", "/etc/nginx/vhost.d")
|
|
|
+ ->addVolumes("./extra/nginx/share", "/usr/share/nginx/html")
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
+ return $composer->render();
|
|
|
+ }
|
|
|
+}
|