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 FTTH', "git@bitbucket.org:ikflowdat/ftth.git") ->addOption('ftth-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Ftth ', "master") ->addOption('mapas-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Mapas', "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('cablemodem-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app cablemodem', "git@bitbucket.org:ikflowdat/cablemodem.git") ->addOption('cablemodem-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the cablemodem app', "master") ->addOption('radius-repo',null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app radius', "git@bitbucket.org:ikflowdat/radius.git") ->addOption('radius-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the radius 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") ->addOption('docker-tag', null, InputOption::VALUE_REQUIRED, 'Docker tag to be used', "latest") ; } protected function execute(InputInterface $input, OutputInterface $output) { $dir = $input->getArgument('dir'); $domain = $input->getOption("domain"); $docker_tag = $input->getOption("docker-tag"); $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"), ), "radius" => array( 'url' => $input->getOption("radius-repo"), 'branch' => $input->getOption("radius-ref"), ), "cablemodem" => array( 'url' => $input->getOption("cablemodem-repo"), 'branch' => $input->getOption("cablemodem-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( $docker_tag, "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); foreach(array("ftth", "mapas", "stats") as $app){ $dObj->file($app.'.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_GRAFANA" => "grafana.".$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 addBase($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("base") ->image($registry."fd3/base:" . $version) ->build("./base/") ->restart("always") ->addLinks("mysql") ->addLinks("amqp") ->addEnviroment("VIRTUAL_HOST", "base.".$domain) ->addEnviroment("HOST_FTTH", "ftth.".$domain) ->addEnviroment("HOST_STATS", "stats.".$domain) ->addEnviroment("HOST_MAPAS", "mapas.".$domain) ->addEnviroment("HOST_BASE", "base." .$domain) ->addVolumes("./base/", "/opt/base") ; } function addFtth($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("ftth") ->image($registry."fd3/ftth:" . $version) ->build("./ftth/") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "base.".$domain) ->addEnv_file("ftth.oauth.env") ->addEnviroment("VIRTUAL_HOST", "ftth.".$domain) ->addEnviroment("HOST_FTTH", "ftth.".$domain) ->addEnviroment("HOST_STATS", "stats.".$domain) ->addEnviroment("HOST_MAPAS", "mapas.".$domain) ->addEnviroment("HOST_BASE", "base.".$domain) //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client) //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret) //->addEnviroment("HTTPS_METHOD", "nohttps") ->addVolumes("./ftth/", "/opt/ftth") ; } function addCablemodem($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("cablemodem") ->image($registry."fd3/cablemodem:" . $version) ->build("./cablemodem/") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "base.".$domain) ->addEnv_file("cablemodem.oauth.env") ->addEnviroment("VIRTUAL_HOST", "cablemodem.".$domain) ->addEnviroment("HOST_FTTH", "ftth.".$domain) ->addEnviroment("HOST_STATS", "stats.".$domain) ->addEnviroment("HOST_MAPAS", "mapas.".$domain) ->addEnviroment("HOST_BASE", "base.".$domain) ->addEnviroment("HOST_CABLEMODEM", "cablemodem.".$domain) //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client) //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret) //->addEnviroment("HTTPS_METHOD", "nohttps") ->addVolumes("./cablemodem/", "/opt/cablemodem") ; } function addRadius($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("radius") ->image($registry."fd3/radius:" . $version) ->build("./radius/") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "base.".$domain) ->addEnv_file("radius.oauth.env") ->addEnviroment("VIRTUAL_HOST", "radius.".$domain) ->addEnviroment("HOST_FTTH", "ftth.".$domain) ->addEnviroment("HOST_STATS", "stats.".$domain) ->addEnviroment("HOST_MAPAS", "mapas.".$domain) ->addEnviroment("HOST_BASE", "base.".$domain) ->addEnviroment("HOST_CABLEMODEM", "cablemodem.".$domain) //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client) //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret) //->addEnviroment("HTTPS_METHOD", "nohttps") ->addVolumes("./cablemodem/", "/opt/cablemodem") ; } function addStats($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("stats") ->image($registry."fd3/stats:" . $version) ->build("./stats/") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "base.".$domain) //->addLinks("jsendpoint", "endpoint") //->addLinks("statsd", "statsd") ->addVolumes("./stats/", "/opt/stats") ->addEnv_file("stats.oauth.env") ->addEnviroment("VIRTUAL_HOST", "stats.".$domain) ->addEnviroment("HOST_FTTH", "ftth.".$domain) ->addEnviroment("HOST_STATS", "stats.".$domain) ->addEnviroment("HOST_MAPAS", "mapas.".$domain) ->addEnviroment("HOST_BASE", "base.".$domain) //->addEnviroment("OAUTH_CLIENT_ID", $oauth_client) //->addEnviroment("OAUTH_CLIENT_SECRET", $oauth_client_secret) //->addEnviroment("HTTPS_METHOD", "nohttps") ; } function addMapas($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("mapas") ->image($registry."fd3/mapas:" . $version) ->build("./mapas/") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "base.".$domain) ->addEnv_file("mapas.oauth.env") ->addEnviroment("VIRTUAL_HOST", "mapas.".$domain) ->addEnviroment("HOST_FTTH", "ftth.".$domain) ->addEnviroment("HOST_STATS", "stats.".$domain) ->addEnviroment("HOST_MAPAS", "mapas.".$domain) ->addEnviroment("HOST_BASE", "base.".$domain) ->addVolumes("./mapas/", "/opt/mapas") ->addVolumes("./mapas/web/uploads", "/opt/mapas/web/uploads") ; } function addNginx($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; $host_env_file = "host.env"; extract($config); $composer->addService("nginx")->build("extra/nginx/") ->image($registry."fd3/nginx:".$version) ->addEnv_file($host_env_file) ->restart("always") ->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") ; } function addMongDb($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; $mongdb_version = "3.4"; extract($config); $composer->addService("mongodb") ->image("mongo:". $mongdb_version) ->addVolumes("./mongodb", "/data/db") ; } function addSupervisord($composer, $config = array(), $flavor = "dev"){ $version = "latest"; extract($config); $composer->addService("supervisord")->build("./extra/supervisord") ->image($registry."fd3/supervisord:$version") ->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") ; } function addMySql($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("mysql")->image($registry."fd3/mysql:". $version) ->build("./extra/mysql") ->addVolumes("./mysql/", "/var/lib/mysql/") ->addEnviroment("MYSQL_ROOT_PASSWORD", $mysql_root_pass) ->addEnviroment("MYSQL_USER", $mysql_user) ->addEnviroment("MYSQL_PASSWORD", $mysql_pass) ; } function addRedis($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("redis") ->image("redis:latest") ->command("redis-server --appendonly yes") //->addPorts("6379", "6379") ->restart("always") ; } function addGenieACS($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("genieacs") ->image("thebinary/genieacs:latest") ->addLinks("mongodb") ->addLinks("redis") ->addPorts("7777", "7777") ->restart("always") ; } function addFreeradius($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("freeradius") ->image($registry . "fd3/freeradius:". $version) ->addLinks("mysql") ->addEnviroment("MYSQL_ROOT_PASSWORD", $mysql_root_pass) ->addEnviroment("MYSQL_USER", $mysql_user) ->addEnviroment("MYSQL_HOST", "mysql") ->addEnviroment("MYSQL_PASSWORD", $mysql_pass) ->addPorts("1812", "1812/udp") ->addPorts("1813", "1813/udp") ->addPorts("3799", "3799/udp") ; } function addGrafana($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("grafana")->image("grafana/grafana") //->addLinks("jsendpoint","endpoint") ->addLinks("mysql") ->restart("always") ->addEnviroment("VIRTUAL_HOST", "grafana.".$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_DEFAULT_THEME", "light") ->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.".$domain."/") ; } function addJsonEndPoints($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("statsd")->build("./extra/statsd/statsd") ->image($registry."fd3/statsd:$version") ->addPorts("8125", "8125/udp") ->addLinks("mysql") ->addLinks("mongodb") ->restart("always") ->addVolumes("./extra/statsd/statsd/statsd.config.js", "/opt/config/statsd.config.js") ; $composer->addService("jsendpoint") ->build("./extra/statsd/endpoint/json") ->image($registry."fd3/jsonep:$version") ->addVolumes("./extra/statsd/endpoint/json", "/opt/datasource") ->addLinks("jsonep_mysql") ->addLinks("jsonep_mongo") ->restart("always") ; $composer->addService("jsonep_mysql") ->build("./extra/statsd/endpoint/mysql") ->image($registry."fd3/jsonep_mysql:$version") ->addVolumes("./extra/statsd/endpoint/mysql", "/opt/datasource") ->addLinks("mysql") ->addEnviroment("MYSQL_ROOT_PASSWORD", $mysql_root_pass) ->restart("always") ; $composer->addService("jsonep_mongo") ->build("./extra/statsd/endpoint/mongodb") ->image($registry."fd3/jsonep_mongo:$version") ->addVolumes("./extra/statsd/endpoint/mongodb", "/opt/datasource") ->addLinks("mongodb") ->restart("always") ; } function addCommandWorkers($composer, $config = array(), $flavor = "dev"){ $version = "latest"; $domain = "fd3.flowdat.com"; extract($config); $composer->addService("base_log_worker")->image($registry."fd3/base:" . $version) ->build("./base/") ->command("bin/console rabbitmq:consumer log_consumer") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("nginx", "base.".$domain) ->addVolumes("./base/", "/opt/base") ; $composer->addService("ftth_command_worker")->image($registry."fd3/ftth:" . $version) ->build("./ftth/") ->command("bin/console rabbitmq:consumer command_consumer") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("nginx", "base.".$domain) ->addVolumes("./ftth/", "/opt/ftth") ; $composer->addService("ftth_tasklogger_worker")->image($registry."fd3/ftth:" . $version) ->build("./ftth/") ->command("bin/console rabbitmq:consumer flowdat_tasklogger") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("nginx", "base.".$domain) ->addVolumes("./ftth/", "/opt/ftth") ; $composer->addService("stats_command_worker")->image($registry."fd3/ftth:" . $version) ->build("./stats/") ->command("bin/console rabbitmq:consumer command_consumer") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("nginx", "base.".$domain) ->addVolumes("./stats/", "/opt/stats") ; } function getDockerComposer( $version = "latest", $host_env_file = "host.env", $registry = "docker.infra.flowdat.com/", $fd_domain = "fd3.flowdat.com") { $mysql_root_pass="235r2342gtfsw"; $mysql_user="iksop"; $mysql_pass="235r2342gtfsw"; $oauth_client = "1_3323sq6urn8kwccg8s4ok848ggwwgkw4c08wsc4cwkc08osocc"; $oauth_client_secret = "5w7gx6ptdoo4g8cwwo88o8gowosgco84sso08ssow0osg88g8k"; $composer = new FileFormat2("../"); $base_vars = array("version" => $version, "host_env_file" => $host_env_file, "domain" => $fd_domain, "registry" => $registry); $this->addNginx($composer, $base_vars); /**************************************************************************************/ /* Apps / Web UI */ /**************************************************************************************/ $this->addBase($composer, $base_vars); $this->addFtth($composer, $base_vars); $this->addStats($composer, $base_vars); $this->addCablemodem($composer, $base_vars); $this->addRadius($composer, $base_vars); $this->addMapas($composer, $base_vars); /**************************************************************************************/ /* Servicios */ /**************************************************************************************/ $this->addMySql($composer, $base_vars + array( 'mysql_root_pass' => $mysql_root_pass, 'mysql_user' => $mysql_user, 'mysql_pass' => $mysql_pass, )); $composer->addService("amqp")->image("rabbitmq:3-management") ->restart("always") ; $this->addMongDb($composer, $base_vars); $this->addRedis($composer); $this->addFreeradius($composer, $base_vars + array( 'mysql_root_pass' => $mysql_root_pass, 'mysql_user' => $mysql_user, 'mysql_pass' => $mysql_pass, )); /**************************************************************************************/ /* Grafana y compoenentes de las estadisticas*/ /**************************************************************************************/ $this->addGrafana($composer, $base_vars + array( 'mysql_user' => $mysql_user, 'mysql_pass' => $mysql_pass, 'mysql_root_pass' => $mysql_root_pass, )); $this->addJsonEndPoints($composer, $base_vars + array( 'mysql_root_pass' => $mysql_root_pass, )); /**************************************************************************************/ /* Workers */ /**************************************************************************************/ $this->addSupervisord($composer, $base_vars); $this->addCommandWorkers($composer, $base_vars); //$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") //; return $composer->render(); } }