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") ->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"), ), "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); $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 getDockerComposer( $v = "latest", $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("base", "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("base", "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") ->addVolumes("./mapas/web/uploads", "/opt/mapas/web/uploads") ; $composer->addService("stats") ->image($registry."fd3/stats:" . $v) ->build("./stats/") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "base.".$fd_domain) ->addLinks("jsendpoint", "endpoint") ->addLinks("statsd", "statsd") ->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") ; /**************************************************************************************/ /* Workers */ /**************************************************************************************/ $composer->addService("ftth_worker")->image($registry."fd3/ftth:" . $v) ->build("./ftth/") ->restart("always") ->addLinks("mysql") ->addLinks("base") ->addLinks("amqp") ->addLinks("base", "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_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.".$fd_domain."/") ; $composer->addService("jsendpoint") ->build("./extra/statsd/endpoint/json") ->image($registry."fd3/jsonep:$v") ->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:$v") ->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:$v") ->addVolumes("./extra/statsd/endpoint/mongodb", "/opt/datasource") ->addLinks("mongodb") ->restart("always") ; $composer->addService("mongodb") ->image("mongo:3.4") ->addVolumes("./mongodb", "/data/db") ; $composer->addService("statsd")->build("./extra/statsd/statsd") ->image($registry."fd3/statsd:$v") ->addPorts("8125", "8125/udp") ->addLinks("mysql") ->addLinks("mongodb") ->restart("always") ->addVolumes("./extra/statsd/statsd/statsd.config.js", "/opt/config/statsd.config.js") ; $composer->addService("supervisord")->build("./extra/supervisord") ->image($registry."fd3/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")->build("extra/nginx/") ->image($registry."fd3/nginx:".$v) ->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") ; return $composer->render(); } }