feat(template): Refactor template standard variable and implement dockerfile
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Matthieu 'JP' DERASSE
2022-09-29 20:04:37 +00:00
parent edbd97705a
commit ac7df8be2d
16 changed files with 191 additions and 98 deletions

View File

@ -5,20 +5,43 @@ Copyright © 2022 Matthieu Derasse <git@derasse.fr>
package cmd
import (
"fmt"
"git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
// dockerCmd represents the docker command.
var dockerCmd = &cobra.Command{
Use: "docker",
Short: "Generate Dockerfile for API & Workers",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("docker called")
},
Short: "Generate Dockerfile & co for API, Crons and Workers",
Run: runGenerateDockerAction,
}
func init() {
generateCmd.AddCommand(dockerCmd)
}
// runGenerateDockerAction will generate the Dockerfile & co for the current project.
func runGenerateDockerAction(cmd *cobra.Command, args []string) {
log.Debugf("Starting command GenerateDocker")
currentPath, config, err := loadProjectAndConfig()
if err != nil {
return
}
apiType, err := api_types.GetAPIType(config.ProjectType)
if err != nil {
log.Error("Impossible to load that API Type generator")
return
}
// Generate Dockerfile
log.Info("Generating Dockerfile")
err = apiType.GenerateDockerfile(currentPath, config)
if err != nil {
log.Errorf("Fail to generate Dockerfile. The following error happen: %s", err.Error())
return
}
}

View File

@ -131,13 +131,13 @@ func runInitAction(cmd *cobra.Command, args []string) {
// ask project contact
config.ProjectContact = models.ProjectContactStruct{}
log.Info("Mail address of the developer team:")
config.ProjectContact.Email = input.Mail(true)
log.Info("Name of the team:")
config.ProjectContact.Name = input.String(true)
log.Info("URL of the contact informatino of the team:")
log.Info("Mail address of the developer team:")
config.ProjectContact.Email = input.Mail(true)
log.Info("URL of the contact information of the team:")
config.ProjectContact.URL = input.String(false)
// launch GetInitializeUserInput from selected api type
@ -193,6 +193,14 @@ func runInitAction(cmd *cobra.Command, args []string) {
return
}
// Create API Skeleton
log.Info("Creating API skeleton")
err = apiType.CreateProjectSkeleton(projectDirPath, config)
if err != nil {
log.Errorf("Fail to create the project skeleton. The following error happen: %s", err.Error())
return
}
// Generate Makefile
log.Info("Generating Makefile")
err = apiType.GenerateMakefile(projectDirPath, config)
@ -209,11 +217,11 @@ func runInitAction(cmd *cobra.Command, args []string) {
return
}
// Create API Skeleton
log.Info("Creating API skeleton")
err = apiType.CreateProjectSkeleton(projectDirPath, config)
// Generate Launcher
log.Info("Generating Launcher")
err = apiType.GenerateLauncher(projectDirPath, config)
if err != nil {
log.Errorf("Fail to create the project skeleton. The following error happen: %s", err.Error())
log.Errorf("Fail to generate launcher.sh. The following error happen: %s", err.Error())
return
}
}