Commit 835a0f18 authored by Manuel Pinzón 's avatar Manuel Pinzón

Inicializando envpops

parents
################################################
############### .gitignore ##################
################################################
################################################
# Local Configuration
################################################
.env
################################################
# Dependencies
################################################
.bowerrc
assets/bower
bower
bower_components
node_modules
################################################
# Sails.js / Waterline / Grunt
################################################
.tmp
dump.rdb
################################################
# Node.js / NPM
################################################
lib-cov
*.seed
*.log
*.out
*.pid
npm-debug.log
################################################
# Miscellaneous
################################################
*~
*#
.DS_STORE
.netbeans
nbproject
.idea
.node_history
# EnvPops
EnvPops es un sistema de despliegue de aplicaciones automatizadas y pre-configuradas.
Nuestro propósito es proporcionar una forma rápida y sencilla de generar sistemas estructurados, escalables y con buenas practicas. Sin tener que ser el proyecto mas grande o contar con el apoyo de múltiples expertos para poder implementarlo.
## Instalación
1. Descargar envpops.
wget https://arch.envpops.io/installers/<os>/envpops
2. Dale permisos de escritura.
chmod a+x envpops
## Commandos
| |Comando |Descripción |
|----------------|-------------------------------|-----------------------------|
|Git |`'envpops git <command>'` |Genera un entorno git privado |
|Init |`envpops init [name]` |Despliega un sistema devops |
|-v, --version |`envpops -v`|Mostrara la versión actual|
## Infraestructura
### Proxys
- Nginx
Comando:
envpops init [project] --services proxy
En caso de configurar un sistema con certificados auto-firmados, la contraseña de la entidad de firma es **asdfgh**
## Información
EnvPops es un proyecto de software libre.
Puedes apoyar el proyecto en:
- [Buy me an coffe](https://www.buymeacoffee.com/ingeniomaps)
O si eres conocedor de alguna tecnología y te gustaría ayudarnos a implementarla, copia el repositorio y ayúdanos con la integración.
package architecture
import (
"strconv"
"gitlab.com/mifori/envpops/config/configuration"
"gitlab.com/mifori/envpops/programs/git"
)
// Automation instala un contenedor a utilizar
func Automation(selection string) {
ContainerInit("automation", selection)
config := configuration.GetConfig()
config.Architecture.Automation = selection
configuration.SetConfig(config)
}
// Backend instala un contenedor a utilizar
func Backend(selection string) {
switch selection {
case "gestor":
Gestor()
case "node":
Node()
}
}
//Container Instala un contenedor a utilizar dentro de un proyecto
func Container(selection string) {
configuration.Install(selection)
config := configuration.GetConfig()
config.Architecture.Container = selection
configuration.SetConfig(config)
}
//Database Instala una base de datos
func Database(selection string) {
ContainerInit("database", selection)
config := configuration.GetConfig()
config.Databases = append(config.Databases, selection)
configuration.SetConfig(config)
}
// Git inicializa la configuracion de git en linux
func Git(selection string) {
configuration.Install("git")
git.ConfigGit()
switch selection {
case "local":
ContainerInit("git", "git")
case "remote":
git.Remote()
}
}
// Proxy instala un contenedor a utilizar
func Proxy(selection string) {
ContainerInit("proxy", selection)
config := configuration.GetConfig()
config.Architecture.Proxy = selection
config.Server.Domain = configuration.ARCH_VARS["domain"]
config.Server.HTTPS, _ = strconv.ParseBool(configuration.ARCH_VARS["https"])
config.Server.Provider = configuration.ARCH_VARS["provider"]
configuration.SetConfig(config)
}
package architecture
import (
"gitlab.com/mifori/envpops/config/configuration"
"gitlab.com/mifori/envpops/programs/docker"
)
//ContainerInit inicializa el instalador de programa en el contenedor
func ContainerInit(arch, program string) {
config := configuration.GetConfig()
switch config.Architecture.Container {
case "docker":
docker.Architecture(arch, program)
}
}
package architecture
import (
"gitlab.com/mifori/envpops/config/configuration"
"gitlab.com/mifori/envpops/config/tools"
"gitlab.com/mifori/envpops/messages"
)
var installer = map[string]func(string){
"automation": Automation,
"backend": Backend,
"container": Container,
"database": Database,
"git": Git,
"proxy": Proxy,
}
var options = map[string][]string{
"automation": []string{"jenkins"},
"backend": []string{"gestor", "node"},
"container": []string{"docker"},
"database": []string{"mysql", "mariadb", "postgres", "mongo"},
"git": []string{"local", "remote"},
"proxy": []string{"nginx"},
}
var depend = map[string][]string{
"git": []string{"proxy"},
"automation": []string{"proxy"},
"backend": []string{"proxy"},
}
//Add genera una infraestructura completa
func Add(arch string) {
depends := depend[arch]
config := configuration.GetConfig()
if config.Architecture.Container == "" {
create("container")
}
for i := 0; i < len(depends); i++ {
createConfirmation(depends[i])
}
create(arch)
}
//create crea la infraestructura solicitada
func create(arch string) {
messages.Show("architecture/" + arch)
selection := tools.SelectOption(options[arch])
installer[arch](selection)
}
//createConfirmation crea la infraestructura solicitada si el usuario acepta
func createConfirmation(arch string) {
config := configuration.GetConfig().Architecture
stored := map[string]string{
"proxy": config.Proxy,
}
if stored[arch] == "" {
messages.Println("architecture/install/" + arch)
confirmation := tools.Scanf()
if confirmation == "s" || confirmation == "y" {
Add(arch)
}
}
}
package architecture
import (
"fmt"
"os"
"gitlab.com/mifori/envpops/config/cmdi"
"gitlab.com/mifori/envpops/config/configuration"
"gitlab.com/mifori/envpops/config/execi"
"gitlab.com/mifori/envpops/config/tools"
"gitlab.com/mifori/envpops/messages"
)
// DatabaseWP instala un contenedor a utilizar
func DatabaseWP() {
messages.Show("architecture/database_wp")
list := []string{"mysql", "mariadb"}
selection := tools.SelectOption(list)
Database(selection)
}
// Node busca el la infraestructura a utilizar
func Node() {
configuration.Install("node")
folder := configuration.FOLDER + "/backend/node/"
src := folder + configuration.PROGRAM
if _, err := os.Stat(src); os.IsNotExist(err) {
cmdi.MkdirAll(src)
}
execi.CommandDir(src, "npm", "init")
messages.Show("architecture/node")
list := []string{"express", "sails"}
selection := tools.SelectOption(list)
switch selection {
case "sails":
execi.CommandDir("npm", selection, "-g")
execi.CommandDir(folder, "sails", "new", configuration.PROGRAM)
case "express":
selectNode(
folder,
"architecture/node_test",
[]string{"jest"},
)
selectNode(
folder,
"architecture/node_db",
[]string{"sequelize"},
)
}
}
//selectNode selecciona el paquete npm a instalar
func selectNode(src, message string, list []string) string {
messages.Show(message)
selection := tools.SelectOption(list)
return selection
}
// Gestor busca el gestor de contenido a instalar
func Gestor() {
var message messages.ArchGestor
messages.GetArch("gestor", &message)
messages.Show("architecture/gestor")
list := []string{"wordpress"}
selection := tools.SelectOption(list)
switch selection {
case "wordpress":
data := configuration.DATABASE
dataServer := data["server"]
if dataServer == "mysql" || dataServer == "mariadb" {
fmt.Print(message.Actual)
confirmation := tools.Scanf()
if confirmation == "s" {
configuration.DATABASE["exist"] = "true"
ContainerInit("gestor", selection)
return
}
} else {
fmt.Println(message.Databases)
fmt.Print(message.Installdb)
confirmation := tools.Scanf()
if confirmation == "s" {
configuration.DATABASE["exist"] = "true"
DatabaseWP()
}
}
ContainerInit("gestor", selection)
}
}
package commands
import (
"fmt"
"os"
"strings"
"gitlab.com/mifori/envpops/architecture"
"gitlab.com/mifori/envpops/config/cmdi"
"gitlab.com/mifori/envpops/config/configuration"
"gitlab.com/mifori/envpops/config/execi"
"gitlab.com/mifori/envpops/messages"
)
// Git depliega los sistemas necesarios para crear un sistema git
func Git(args []string) {
permitted := []string{"-p", "--help"}
commands, commandsArgs, initial := check(args, permitted)
path := configuration.POPSPATH + "/.gitpops"
configuration.FOLDER = path
configuration.PROJECT = "git"
if len(initial) == 0 && len(commands) == 0 {
if _, err := os.Stat(path); os.IsNotExist(err) {
cmdi.Mkdir(path)
}
architecture.Add("git")
return
}
if len(initial) > 0 {
if c := configuration.GetConfig(); c.RepositoryType != "local" {
messages.Exit("git/not_create")
}
gitActions(initial, commandsArgs)
} else {
gitCommand(commands)
}
}
//gitActions realiza las acciones permitidas por git
func gitActions(words []string, commandsArgs map[string][]string) {
switch words[0] {
case "add":
add(words, commandsArgs)
case "rm":
remove(words, commandsArgs)
default:
messages.Exit("git/unknown")
}
}
//gitCommand realiza las acciones relacionadas a un comando
func gitCommand(commands []string) {
switch commands[0] {
case "--help":
fmt.Printf(messages.Read("git/help")+"\n", configuration.PROGRAM)
os.Exit(0)
default:
messages.Exit("git/unknown")
}
}
//add crea los repositorios
func add(words []string, commands map[string][]string) {
typeF := "public"
private := commands["-p"]
if private != nil {
typeF = "private"
words = append(words, private...)
}
if len(words) == 1 {
messages.Exit("git/add")
}
if len(commands) > 1 {
messages.Exit("git/unknown")
}
folder := configuration.FOLDER + "/"
folders := words[1:]
repositorio := folder + typeF
for i := 0; i < len(folders); i++ {
f := strings.ToLower(folders[i])
if _, err := os.Stat(folder + "private/" + f + ".git"); !os.IsNotExist(err) {
fmt.Printf(messages.Read("git/exist"), f)
continue
}
if _, err := os.Stat(folder + "public/" + f + ".git"); !os.IsNotExist(err) {
fmt.Printf(messages.Read("git/exist"), f)
continue
}
cmdi.MkdirAll(repositorio + "/" + f)
generate(f, repositorio)
if typeF == "private" {
src := repositorio + "/" + f + ".git"
cmdi.Chown("-R", os.Getenv("USER"), src)
cmdi.Chmod("-R", "ug+rwX", src)
cmdi.Exec("find", src, "-type", "d", "-exec",
"chmod", "g+s", "{}", "+",
)
}
}
}
//remove elimina los repositorios
func remove(words []string, commands map[string][]string) {
if len(words) == 1 {
messages.Exit("git/rm")
}
if len(commands) > 0 {
messages.Exit("git/unknown")
}
folders := words[1:]
for i := 0; i < len(folders); i++ {
f := strings.ToLower(folders[i])
cmdi.ExecE("rm", "-r",
configuration.FOLDER+"/private/"+f+".git",
configuration.FOLDER+"/public/"+f+".git",
)
}
}
//generate crea un folder git para el servidor
func generate(name, repositorio string) {
name = strings.ToLower(name)
newRepository := repositorio + "/" + name
execi.CommandDir(newRepository, configuration.Permission(),
"git", "init", "--shared=true")
execi.CommandDir(newRepository, configuration.Permission(),
"git", "add", ".")
execi.CommandDir(newRepository, configuration.Permission(),
"git", "commit", "-m", "Iniciando Git")
execi.CommandDir(repositorio, configuration.Permission(),
"git", "clone", "--bare", name, name+".git")
cmdi.RemoveFolder(newRepository)
}
package commands
import (
"fmt"
"os"
"strings"
"gitlab.com/mifori/envpops/architecture"
"gitlab.com/mifori/envpops/config/cmdi"
"gitlab.com/mifori/envpops/config/configuration"
"gitlab.com/mifori/envpops/config/tools"
"gitlab.com/mifori/envpops/messages"
)
var actionsInit = []string{"proxy", "automation", "database", "backend"}
var commandsInit = []string{"--services", "--help"}
// Init crea un nuevo proyecto
func Init(args []string) {
var message messages.ArchInit
messages.GetArch("init", &message)
commands, commandsArgs, initial := extract(args)
validate(commands, commandsInit)
if len(commands) > 0 && commands[0] == "--help" {
fmt.Printf(messages.Read("init/help"), configuration.PROGRAM)
fmt.Println("")
os.Exit(0)
}
if len(initial) == 0 {
fmt.Println(message.Init)
os.Exit(0)
}
nombre := strings.Join(initial, " ")
if len(commands) == 0 {
fist(nombre, false)
actions(actionsInit)
return
}
switch commands[0] {
case "--services":
services := commandsArgs["--services"]
if len(services) == 0 {
fmt.Println(message.Indicar)
os.Exit(0)
}
fist(nombre, true)
actions(services)
}
}
// InitName crea un nuevo proyecto preguntando por un nombre al usuario
func InitName() {
var message messages.ArchInit
messages.GetArch("init", &message)
messages.Showln("init")
fmt.Print(message.Nombre)
nombre := tools.Scan()
fist(nombre, false)
actions(actionsInit)
}
//getName solicita el nombre del proyecto a inicializar
func getName() string {
var message messages.ArchInit
messages.GetArch("init", &message)
messages.Showln("init")
fmt.Print(message.Nombre)
nombre := tools.Scan()
return nombre
}
func actions(services []string) {
var list = make(map[string]bool)
length := len(services)
exists := map[string]bool{
"proxy": true,
"automation": true,
"database": true,
"backend": true,
}
for i := 0; i < length; i++ {
if !exists[services[i]] {
messages.Showln("init/unknown")
os.Exit(0)
}
list[services[i]] = true
}
if list["proxy"] {
architecture.Add("proxy")
}
if list["automation"] {
architecture.Add("automation")
}
if list["database"] {
architecture.Add("database")
}
if list["backend"] {
architecture.Add("backend")
}
last()
}
//fist inicia con el proceso de despliegue
func fist(nombre string, change bool) {
var message messages.ArchInit
messages.GetArch("init", &message)
src := strings.ToLower(strings.Replace(nombre, " ", "_", -1))
path := configuration.POPSPATH + "/" + src
_, err := os.Stat(path)
if !os.IsNotExist(err) && !change {
fmt.Println(message.Existe)
os.Exit(0)
}
configuration.PROJECT = src
configuration.FOLDER = path
if os.IsNotExist(err) {
cmdi.MkdirAll(path)
conf := configuration.GetConfigJSON()
config := configuration.GetConfig()
config.Project = src
config.Name = nombre
config.Repository = conf.Repository + "/" + src
config.Version = "0.0.1"
configuration.SetConfig(config)
}
}
//last muestra acciones para el usuario
func last() {
var message messages.ArchInit