code reformat, init fixes
This commit is contained in:
parent
da41b5820b
commit
1071695e87
@ -34,4 +34,3 @@ var CmdDocker = cli.Command{
|
|||||||
func runDockerDefault(ctx *cli.Context) error {
|
func runDockerDefault(ctx *cli.Context) error {
|
||||||
return docker.RunComposePs(ctx)
|
return docker.RunComposePs(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,5 +19,3 @@ func RunComposeBuild(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerBuild(ctx)
|
compose.ExecComposerBuild(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ func RunComposeDebug(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerDebug(ctx)
|
compose.ExecComposerDebug(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ func RunComposeDown(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerDown(ctx)
|
compose.ExecComposerDown(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,4 +19,3 @@ func RunComposeLogs(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerLogs(ctx, cmd.Args())
|
compose.ExecComposerLogs(ctx, cmd.Args())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ func RunComposePull(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerPull(ctx)
|
compose.ExecComposerPull(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ func RunComposeRestart(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerRestart(ctx)
|
compose.ExecComposerRestart(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,4 +23,3 @@ func RunComposeRun(cmd *cli.Context) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,4 +19,3 @@ func RunComposeShell(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerShell(ctx)
|
compose.ExecComposerShell(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,5 +18,3 @@ func RunComposeStop(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerStop(ctx)
|
compose.ExecComposerStop(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,4 +20,3 @@ func RunComposeUp(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerLogs(ctx, cmd.Args())
|
compose.ExecComposerLogs(ctx, cmd.Args())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ func RunComposeUpOnce(cmd *cli.Context) error {
|
|||||||
compose.ExecComposerUpOnce(ctx)
|
compose.ExecComposerUpOnce(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"ledo/app/helper"
|
||||||
|
"ledo/app/modules/compose"
|
||||||
"ledo/app/modules/context"
|
"ledo/app/modules/context"
|
||||||
|
"ledo/app/modules/dockerfile"
|
||||||
"ledo/app/modules/interact"
|
"ledo/app/modules/interact"
|
||||||
"ledo/app/templates"
|
"ledo/app/templates"
|
||||||
"log"
|
"log"
|
||||||
@ -21,20 +23,88 @@ var CmdInit = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runInitLedo(cmd *cli.Context) error {
|
func runInitLedo(cmd *cli.Context) error {
|
||||||
config, _ := context.LoadConfigFile()
|
var advRun bool
|
||||||
data, err := interact.InitLedoProject(config.Docker)
|
config, err := context.LoadConfigFile()
|
||||||
tpl, err := template.New("tpl").Parse(templates.LedoConfigurationFileTemplate)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
err = tpl.Execute(os.Stdout, data)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
advRun := interact.InitAdvancedConfigurationAsk()
|
|
||||||
fmt.Printf("%v", advRun)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data, err := interact.InitLedoProject(config.Docker)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tpl, err := template.New("tpl").Parse(templates.LedoConfigurationFileTemplate)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create("./.ledo.yml")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tpl.Execute(f, data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
advRun = false
|
||||||
|
// advRun := interact.InitAdvancedConfigurationAsk("Run advanced docker mode configuration?")
|
||||||
|
if advRun == true {
|
||||||
|
ctx := context.InitCommand(cmd)
|
||||||
|
dConf, _ := interact.InitDocker()
|
||||||
|
err = dockerfile.CreateDockerFile(dConf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
projectComposeConfig := helper.DockerProjectCfg{}
|
||||||
|
projectComposeConfig.DockerBaseImage = dConf.DockerBaseImage
|
||||||
|
|
||||||
|
var dockerComposeServices []helper.DockerProjectAdditionalServiceCfg
|
||||||
|
var dockerComposeModeConfig []helper.DockerComposeModeCfg
|
||||||
|
|
||||||
|
|
||||||
|
for _, composeMode := range interact.PredefinedDockerComposeModes {
|
||||||
|
var configMode bool
|
||||||
|
|
||||||
|
if composeMode == "base" {
|
||||||
|
configMode = true
|
||||||
|
} else {
|
||||||
|
configMode = interact.InitAdvancedConfigurationAsk("Configure "+composeMode+" stack?")
|
||||||
|
}
|
||||||
|
|
||||||
|
if configMode == true {
|
||||||
|
for {
|
||||||
|
serviceCfg, _ := interact.CreateDockerService()
|
||||||
|
serviceCfg.DockerServiceMode = composeMode
|
||||||
|
dockerComposeServices = append(dockerComposeServices, serviceCfg)
|
||||||
|
addAnother := interact.InitAdvancedConfigurationAsk("Add another service do " + composeMode + " stack?")
|
||||||
|
if addAnother == false {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeFilename := "./docker/docker-compose.yml"
|
||||||
|
if composeMode != "base" {
|
||||||
|
composeFilename = "./docker/docker-compose."+composeMode+".yml"
|
||||||
|
}
|
||||||
|
mdCfg := helper.DockerComposeModeCfg{
|
||||||
|
DockerComposeName: composeFilename,
|
||||||
|
DockerComposeServices: dockerComposeServices,
|
||||||
|
}
|
||||||
|
dockerComposeModeConfig = append(dockerComposeModeConfig, mdCfg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
projectComposeConfig.DockerComposeModes = dockerComposeModeConfig
|
||||||
|
|
||||||
|
err = compose.CreateComposeFile(ctx, projectComposeConfig, "base")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -21,4 +21,3 @@ var CmdMode = cli.Command{
|
|||||||
func runModeDefault(cmd *cli.Context) error {
|
func runModeDefault(cmd *cli.Context) error {
|
||||||
return mode.RunSelectMode(cmd)
|
return mode.RunSelectMode(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,3 @@ func RunModeList(cmd *cli.Context) error {
|
|||||||
ctx.Mode.PrintListModes()
|
ctx.Mode.PrintListModes()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,5 +24,3 @@ func RunSelectMode(cmd *cli.Context) error {
|
|||||||
interact.SelectMode(ctx, "")
|
interact.SelectMode(ctx, "")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
77
app/helper/docker_configuration.go
Normal file
77
app/helper/docker_configuration.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
type DockerServiceEnvironment struct {
|
||||||
|
EnvironmentName string `yaml:"environment_name,omitempty" json:"environmentName"`
|
||||||
|
EnvironmentValue string `yaml:"environment_value,omitempty" json:"environmentValue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DockerProjectAdditionalServiceCfg struct {
|
||||||
|
DockerServiceMode string `yaml:"docker_service_mode,omitempty" json:"dockerServiceMode"`
|
||||||
|
DockerServiceType string `yaml:"docker_service_type,omitempty" json:"dockerServiceType"`
|
||||||
|
DockerServiceImage string `yaml:"docker_service_image,omitempty" json:"dockerServiceImage"`
|
||||||
|
DockerServiceTag string `yaml:"docker_service_tag,omitempty" json:"dockerServiceTag"`
|
||||||
|
DockerServiceEnvironment []DockerServiceEnvironment `yaml:"docker_service_environment,omitempty" json:"dockerServiceEnvironment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DockerComposeModeCfg struct {
|
||||||
|
DockerComposeName string `yaml:"docker_compose_name,omitempty" json:"dockerComposeName"`
|
||||||
|
DockerComposeServices []DockerProjectAdditionalServiceCfg `yaml:"docker_compose_services,omitempty" json:"dockerComposeServices"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DockerProjectCfg struct {
|
||||||
|
HasDockerRegistry bool `yaml:"has_docker_registry,omitempty" json:"hasDockerRegistry"`
|
||||||
|
DockerBaseImage string `yaml:"docker_base_image,omitempty" json:"dockerBaseImage"`
|
||||||
|
DockerBaseTag string `yaml:"docker_base_tag,omitempty" json:"dockerBaseTag"`
|
||||||
|
DockerComposeModes []DockerComposeModeCfg `yaml:"docker_compose_modes,omitempty" json:"dockerComposeModes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//var PredefinedAdditionalService = []DockerProjectAdditionalServiceCfg{
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "base",
|
||||||
|
// DockerServiceType: "database",
|
||||||
|
// DockerServiceImage: "mariadb",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// DockerServiceEnvironment: []DockerServiceEnvironment{
|
||||||
|
// {
|
||||||
|
// EnvironmentName: "DB_NAME",
|
||||||
|
// EnvironmentValue: "dev",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "dev",
|
||||||
|
// DockerServiceType: "tools",
|
||||||
|
// DockerServiceImage: "dbgate/dbgate",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "dev",
|
||||||
|
// DockerServiceType: "tools",
|
||||||
|
// DockerServiceImage: "mailhog/mailhog",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "dev",
|
||||||
|
// DockerServiceType: "tools",
|
||||||
|
// DockerServiceImage: "minio/minio",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "base",
|
||||||
|
// DockerServiceType: "security",
|
||||||
|
// DockerServiceImage: "authelia/authelia",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "base",
|
||||||
|
// DockerServiceType: "infrastructure",
|
||||||
|
// DockerServiceImage: "traefik",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// DockerServiceMode: "base",
|
||||||
|
// DockerServiceType: "infrastructure",
|
||||||
|
// DockerServiceImage: "portainer",
|
||||||
|
// DockerServiceTag: "",
|
||||||
|
// },
|
||||||
|
//}
|
@ -1,2 +0,0 @@
|
|||||||
package helper
|
|
||||||
|
|
@ -107,7 +107,6 @@ func ExecComposerBuild(ctx *context.LedoContext) {
|
|||||||
ctx.ExecCmd("docker-compose", args[0:])
|
ctx.ExecCmd("docker-compose", args[0:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ExecComposerDown(ctx *context.LedoContext) {
|
func ExecComposerDown(ctx *context.LedoContext) {
|
||||||
args := ctx.ComposeArgs
|
args := ctx.ComposeArgs
|
||||||
args = append(args, "down")
|
args = append(args, "down")
|
||||||
@ -166,7 +165,3 @@ func ExecComposerUpOnce(ctx *context.LedoContext) {
|
|||||||
args = append(args, "up", "--force-recreate", "--renew-anon-volumes", "--abort-on-container-exit", "--exit-code-from", ctx.Config.Docker.MainService)
|
args = append(args, "up", "--force-recreate", "--renew-anon-volumes", "--abort-on-container-exit", "--exit-code-from", ctx.Config.Docker.MainService)
|
||||||
ctx.ExecCmd("docker-compose", args[0:])
|
ctx.ExecCmd("docker-compose", args[0:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
42
app/modules/compose/create_compose.go
Normal file
42
app/modules/compose/create_compose.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package compose
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"ledo/app/helper"
|
||||||
|
"ledo/app/modules/context"
|
||||||
|
"ledo/app/templates"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateComposeFile(ctx *context.LedoContext, dockerProject helper.DockerProjectCfg, composeMode string) error {
|
||||||
|
if _, err := os.Stat("./docker"); os.IsNotExist(err) {
|
||||||
|
err := os.Mkdir("./docker", 0755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%v", dockerProject)
|
||||||
|
|
||||||
|
templateName := templates.LedoDockerComposeBaseFileTemplate_base
|
||||||
|
|
||||||
|
tpl, err := template.New("dockercompose").Parse(templateName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
composeFilename := "./docker/docker-compose.yml"
|
||||||
|
|
||||||
|
if composeMode != "base" {
|
||||||
|
composeFilename = "./docker/docker-compose."+composeMode+".yml"
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create(composeFilename)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("create file: ", err)
|
||||||
|
}
|
||||||
|
err = tpl.Execute(f, ctx)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
@ -39,8 +39,8 @@ func InitCommand(ctx *cli.Context) *LedoContext {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
mode := mode.InitMode(modeYml, configYml)
|
ledoMode := mode.InitMode(modeYml, configYml)
|
||||||
c.Mode = mode
|
c.Mode = ledoMode
|
||||||
|
|
||||||
c.Output = ctx.String("output")
|
c.Output = ctx.String("output")
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ func InitCommand(ctx *cli.Context) *LedoContext {
|
|||||||
args := []string{"--env-file", ".env"}
|
args := []string{"--env-file", ".env"}
|
||||||
args = append(args, "--project-name", strings.ToLower(strings.Replace(c.Config.Docker.Name, "/", "-", -1)))
|
args = append(args, "--project-name", strings.ToLower(strings.Replace(c.Config.Docker.Name, "/", "-", -1)))
|
||||||
|
|
||||||
composes, _ := mode.GetModeConfig()
|
composes, _ := ledoMode.GetModeConfig()
|
||||||
for _, element := range composes {
|
for _, element := range composes {
|
||||||
args = append(args, "-f")
|
args = append(args, "-f")
|
||||||
args = append(args, element)
|
args = append(args, element)
|
||||||
|
57
app/modules/docker_hub/docker_hub_images.go
Normal file
57
app/modules/docker_hub/docker_hub_images.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package docker_hub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DockerSearchResponse struct {
|
||||||
|
NumPages int `json:"num_pages"`
|
||||||
|
NumResults int `json:"num_results"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
Query string `json:"query"`
|
||||||
|
Results []DockerImage `json:"results"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DockerImage struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
StarCount int `json:"star_count"`
|
||||||
|
IsTrusted bool `json:"is_trusted"`
|
||||||
|
IsAutomated bool `json:"is_automated"`
|
||||||
|
IsOfficial bool `json:"is_official"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var urlSearch = "https://registry.hub.docker.com/v1/search"
|
||||||
|
|
||||||
|
func GetImage(image string) []DockerImage {
|
||||||
|
var resp DockerSearchResponse
|
||||||
|
searchString := url.QueryEscape(image)
|
||||||
|
urlSearch = urlSearch + "/?q=" + searchString
|
||||||
|
fmt.Printf("%v", urlSearch)
|
||||||
|
res, _ := http.Get(urlSearch)
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
bytes, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
json.Unmarshal(bytes, &resp)
|
||||||
|
|
||||||
|
return resp.Results
|
||||||
|
}
|
||||||
|
|
||||||
|
func DockerImageToArray(images []DockerImage) []string {
|
||||||
|
n := len(images)
|
||||||
|
arrTags := make([]string, n)
|
||||||
|
for idx, image := range images {
|
||||||
|
arrTags[idx] = image.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrTags
|
||||||
|
}
|
@ -11,11 +11,11 @@ type DockerImageTag struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = "https://registry.hub.docker.com/v1/repositories"
|
var urlTags = "https://registry.hub.docker.com/v1/repositories"
|
||||||
|
|
||||||
func GetImageTags(image string) []DockerImageTag {
|
func GetImageTags(image string) []DockerImageTag {
|
||||||
url = url + "/" + image + "/tags"
|
urlTags = urlTags + "/" + image + "/tags"
|
||||||
res, _ := http.Get(url)
|
res, _ := http.Get(urlTags)
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(res.Body)
|
bytes, err := ioutil.ReadAll(res.Body)
|
33
app/modules/dockerfile/dockerfile.go
Normal file
33
app/modules/dockerfile/dockerfile.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package dockerfile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"ledo/app/helper"
|
||||||
|
"ledo/app/templates"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateDockerFile(cfg helper.DockerProjectCfg) error {
|
||||||
|
if _, err := os.Stat("./Dockerfile"); err == nil {
|
||||||
|
log.Printf("Dockerfile exists!")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
templateName := templates.DockerFileTemplate_default
|
||||||
|
if cfg.DockerBaseImage == "paramah/php" {
|
||||||
|
templateName = templates.DockerFileTemplate_php
|
||||||
|
}
|
||||||
|
tpl, err := template.New("dockerfile").Parse(templateName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create("./Dockerfile")
|
||||||
|
if err != nil {
|
||||||
|
log.Println("create file: ", err)
|
||||||
|
}
|
||||||
|
err = tpl.Execute(f, cfg)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
64
app/modules/interact/docker_hub.go
Normal file
64
app/modules/interact/docker_hub.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package interact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"ledo/app/modules/docker_hub"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SelectDockerHubTag(dockerImage string) (string, error) {
|
||||||
|
dockerImageTags := docker_hub.GetImageTags(dockerImage)
|
||||||
|
selectedTag := "latest"
|
||||||
|
|
||||||
|
var qs = []*survey.Question{
|
||||||
|
{
|
||||||
|
Name: "tags",
|
||||||
|
Prompt: &survey.Select{
|
||||||
|
Message: "Select available docker image tag",
|
||||||
|
PageSize: 10,
|
||||||
|
Options: docker_hub.ImageTagsToArray(dockerImageTags),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := survey.Ask(qs, &selectedTag)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedTag, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnterDockerImage() (string, error) {
|
||||||
|
dockerImage := ""
|
||||||
|
prompt := &survey.Input{
|
||||||
|
Message: "Enter docker base image: ",
|
||||||
|
Help: "This is base Dockerfile image (FROM image)",
|
||||||
|
}
|
||||||
|
survey.AskOne(prompt, &dockerImage)
|
||||||
|
return dockerImage, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SearchDockerImage(image string) (string, error) {
|
||||||
|
dockerImages := docker_hub.GetImage(image)
|
||||||
|
selectedImage := ""
|
||||||
|
|
||||||
|
var qs = []*survey.Question{
|
||||||
|
{
|
||||||
|
Name: "image",
|
||||||
|
Prompt: &survey.Select{
|
||||||
|
Message: "Select available docker image",
|
||||||
|
PageSize: 100,
|
||||||
|
Options: docker_hub.DockerImageToArray(dockerImages),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := survey.Ask(qs, &selectedImage)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedImage, err
|
||||||
|
}
|
@ -1,30 +0,0 @@
|
|||||||
package interact
|
|
||||||
|
|
||||||
import (
|
|
||||||
survey "github.com/AlecAivazis/survey/v2"
|
|
||||||
"ledo/app/modules/docker_hub"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SelectDockerHubTag(dockerImage string) (string, error) {
|
|
||||||
dockerImageTags := docker_hub.GetImageTags(dockerImage)
|
|
||||||
selectedTag := "latest"
|
|
||||||
|
|
||||||
var qs = []*survey.Question{
|
|
||||||
{
|
|
||||||
Name: "tags",
|
|
||||||
Prompt: &survey.Select{
|
|
||||||
Message: "Select available docker image tag",
|
|
||||||
PageSize: 10,
|
|
||||||
Options: docker_hub.ImageTagsToArray(dockerImageTags),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := survey.Ask(qs, &selectedTag)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return selectedTag, err
|
|
||||||
}
|
|
24
app/modules/interact/docker_init.go
Normal file
24
app/modules/interact/docker_init.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package interact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ledo/app/helper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitDocker() (helper.DockerProjectCfg, error) {
|
||||||
|
dockerConfig := helper.DockerProjectCfg{}
|
||||||
|
|
||||||
|
image, err := EnterDockerImage()
|
||||||
|
if err != nil {
|
||||||
|
return dockerConfig, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tag, err := SelectDockerHubTag(image)
|
||||||
|
if err != nil {
|
||||||
|
return dockerConfig, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerConfig.DockerBaseImage = image
|
||||||
|
dockerConfig.DockerBaseTag = tag
|
||||||
|
|
||||||
|
return dockerConfig, err
|
||||||
|
}
|
51
app/modules/interact/docker_service.go
Normal file
51
app/modules/interact/docker_service.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package interact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"ledo/app/helper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var PredefinedDockerComposeModes = []string{
|
||||||
|
"base",
|
||||||
|
"dev",
|
||||||
|
"test",
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateDockerService() (helper.DockerProjectAdditionalServiceCfg, error) {
|
||||||
|
dockerServiceConfig := helper.DockerProjectAdditionalServiceCfg{}
|
||||||
|
|
||||||
|
var qs = []*survey.Question{
|
||||||
|
//{
|
||||||
|
// Name: "DockerServiceType",
|
||||||
|
// Prompt: &survey.Select{
|
||||||
|
// Message: "Select type of service",
|
||||||
|
// PageSize: 10,
|
||||||
|
// Options: []string{"database", "development", "tools"},
|
||||||
|
// },
|
||||||
|
//},
|
||||||
|
//{
|
||||||
|
// Name: "DockerServiceMode",
|
||||||
|
// Prompt: &survey.Select{
|
||||||
|
// Message: "Select docker-compose mode (file)",
|
||||||
|
// PageSize: 10,
|
||||||
|
// Options: PredefinedDockerComposeModes,
|
||||||
|
// },
|
||||||
|
//},
|
||||||
|
{
|
||||||
|
Name: "DockerServiceImage",
|
||||||
|
Prompt: &survey.Input{Message: "Enter image name: "},
|
||||||
|
Validate: survey.Required,
|
||||||
|
Transform: survey.ToLower,
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
err := survey.Ask(qs, &dockerServiceConfig)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return dockerServiceConfig, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dockerServiceConfig, err
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,13 @@
|
|||||||
|
|
||||||
package interact
|
package interact
|
||||||
|
|
||||||
import (
|
import (
|
||||||
survey "github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"ledo/app/modules/config"
|
"ledo/app/modules/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitLedoProject(dockerConfig config.DockerMap) (config.DockerMap, error) {
|
func InitLedoProject(dockerConfig config.DockerMap) (config.DockerMap, error) {
|
||||||
if dockerConfig.Registry == "" {
|
if dockerConfig.Registry == "" {
|
||||||
dockerConfig.Registry = "hub.docker.com"
|
dockerConfig.Registry = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if dockerConfig.Shell == "" {
|
if dockerConfig.Shell == "" {
|
||||||
@ -56,7 +55,6 @@ func InitLedoProject(dockerConfig config.DockerMap) (config.DockerMap, error) {
|
|||||||
Validate: survey.Required,
|
Validate: survey.Required,
|
||||||
Transform: survey.ToLower,
|
Transform: survey.ToLower,
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := survey.Ask(qs, &dockerConfig)
|
err := survey.Ask(qs, &dockerConfig)
|
||||||
@ -68,9 +66,9 @@ func InitLedoProject(dockerConfig config.DockerMap) (config.DockerMap, error) {
|
|||||||
return dockerConfig, err
|
return dockerConfig, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitAdvancedConfigurationAsk() (bool) {
|
func InitAdvancedConfigurationAsk(question string) bool {
|
||||||
runAdv := false
|
runAdv := false
|
||||||
prompt := &survey.Confirm{Message: "Run advanced docker mode configuration?"}
|
prompt := &survey.Confirm{Message: question}
|
||||||
survey.AskOne(prompt, &runAdv)
|
survey.AskOne(prompt, &runAdv)
|
||||||
return runAdv
|
return runAdv
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package interact
|
package interact
|
||||||
|
|
||||||
import (
|
import (
|
||||||
survey "github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/thoas/go-funk"
|
"github.com/thoas/go-funk"
|
||||||
"ledo/app/modules/context"
|
"ledo/app/modules/context"
|
||||||
)
|
)
|
||||||
|
@ -58,7 +58,7 @@ func (c *Mode) GetMode() string {
|
|||||||
|
|
||||||
func (c *Mode) PrintListModes() {
|
func (c *Mode) PrintListModes() {
|
||||||
fmt.Printf("Available modes:\n")
|
fmt.Printf("Available modes:\n")
|
||||||
for m, _ := range c.availableModes {
|
for m := range c.availableModes {
|
||||||
fmt.Printf("- %v\n", m)
|
fmt.Printf("- %v\n", m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func (c *Mode) SetMode(modeName string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Mode) GetModeConfig() ([]string, error) {
|
func (c *Mode) GetModeConfig() ([]string, error) {
|
||||||
_, err := c.CheckMode(c.CurrentMode);
|
_, err := c.CheckMode(c.CurrentMode)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
composes := strings.Fields(c.availableModes[c.CurrentMode])
|
composes := strings.Fields(c.availableModes[c.CurrentMode])
|
||||||
@ -105,5 +105,3 @@ func (c *Mode) GetModeConfig() ([]string, error) {
|
|||||||
|
|
||||||
return nil, errors.New("Selected mode not exists in config file")
|
return nil, errors.New("Selected mode not exists in config file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
var LedoDockerComposeBaseFileTemplate = `
|
var LedoDockerComposeBaseFileTemplate_base = `
|
||||||
|
version: '3.7'
|
||||||
|
services:
|
||||||
|
|
||||||
|
{{.Config.Docker.MainService}}:
|
||||||
|
image: {{.Config.Docker.Registry}}
|
||||||
|
networks:
|
||||||
|
- network-{{.Config.Docker.Namespace}}
|
||||||
|
env_file: ${PWD}/.env
|
||||||
|
|
||||||
|
networks:
|
||||||
|
nestork-{{.Config.Docker.Namespace}}: {}
|
||||||
`
|
`
|
@ -1,7 +1,7 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
var default_DockerFileTemplate = `
|
var DockerFileTemplate_default = `
|
||||||
FROM {{.Image}}/{{.Tag}}
|
FROM {{.DockerBaseImage}}:{{.DockerBaseTag}}
|
||||||
|
|
||||||
ENV DIR /usr/local
|
ENV DIR /usr/local
|
||||||
WORKDIR ${DIR}
|
WORKDIR ${DIR}
|
||||||
@ -10,13 +10,13 @@ WORKDIR ${DIR}
|
|||||||
COPY docker/docker-entrypoint.sh /bin/docker-entrypoint.sh
|
COPY docker/docker-entrypoint.sh /bin/docker-entrypoint.sh
|
||||||
|
|
||||||
# Copy project content
|
# Copy project content
|
||||||
COPY {{.ContainerContent}} $DIR
|
COPY ./app $DIR
|
||||||
|
|
||||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
CMD [""]
|
CMD [""]
|
||||||
`
|
`
|
||||||
var php_DockerFileTemplate = `
|
var DockerFileTemplate_php = `
|
||||||
FROM paramah/{{.Tag}}
|
FROM {{.DockerBaseImage}}:{{.DockerBaseTag}}
|
||||||
ARG ENVIRONMENT=production
|
ARG ENVIRONMENT=production
|
||||||
|
|
||||||
RUN ngxconfig sf.conf
|
RUN ngxconfig sf.conf
|
||||||
|
31
app/templates/entrypoint_template.go
Normal file
31
app/templates/entrypoint_template.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package templates
|
||||||
|
|
||||||
|
var DockerEntrypointTemplate_bash = `
|
||||||
|
#!/bin/bash
|
||||||
|
set -eo pipefail
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
h1() {
|
||||||
|
declare border padding text
|
||||||
|
border='\e[1;34m'"$(printf '=%.0s' $(seq 1 "$term_width"))"'\e[0m'
|
||||||
|
padding="$(printf ' %.0s' $(seq 1 $(((term_width - $(wc -m <<<"$*")) / 2))))"
|
||||||
|
text="\\e[1m$*\\e[0m"
|
||||||
|
echo -e "$border"
|
||||||
|
echo -e "${padding}${text}${padding}"
|
||||||
|
echo -e "$border"
|
||||||
|
}
|
||||||
|
|
||||||
|
h2() {
|
||||||
|
printf '\e[1;33m==>\e[37;1m %s\e[0m\n' "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 "Project init"
|
||||||
|
|
||||||
|
###
|
||||||
|
### Your code here
|
||||||
|
###
|
||||||
|
|
||||||
|
h1 "End of init"
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
|
`
|
@ -11,8 +11,7 @@ docker:
|
|||||||
username: {{.Username}}
|
username: {{.Username}}
|
||||||
{{end}}
|
{{end}}
|
||||||
modes:
|
modes:
|
||||||
normal: docker/docker-compose.yml
|
base: docker/docker-compose.yml
|
||||||
dev: docker/docker-compose.yml docker/docker-compose.dev.yml
|
dev: docker/docker-compose.yml docker/docker-compose.dev.yml
|
||||||
traefik: docker/docker-compose.yml docker/docker-compose.traefik.yml
|
test: docker/docker-compose.yml docker/docker-compose.test.yml
|
||||||
`
|
`
|
||||||
|
|
||||||
|
4
main.go
4
main.go
@ -25,13 +25,13 @@ func main() {
|
|||||||
app.Usage = "LeadDocker helper for docker-compose work"
|
app.Usage = "LeadDocker helper for docker-compose work"
|
||||||
app.Description = appDescription
|
app.Description = appDescription
|
||||||
app.CustomAppHelpTemplate = helpTemplate
|
app.CustomAppHelpTemplate = helpTemplate
|
||||||
app.Version = version
|
app.Version = GetCurrentVersion()
|
||||||
app.Commands = []*cli.Command{
|
app.Commands = []*cli.Command{
|
||||||
&cmd.CmdInit,
|
&cmd.CmdInit,
|
||||||
&cmd.CmdDocker,
|
&cmd.CmdDocker,
|
||||||
&cmd.CmdMode,
|
&cmd.CmdMode,
|
||||||
&cmd.CmdAutocomplete,
|
&cmd.CmdAutocomplete,
|
||||||
&CmdSelfupdate,
|
// &CmdSelfupdate,
|
||||||
}
|
}
|
||||||
app.EnableBashCompletion = true
|
app.EnableBashCompletion = true
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
|
Loading…
Reference in New Issue
Block a user