Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Add template my sql for docker-compose.yml generation (#366)
Browse files Browse the repository at this point in the history
Signed-off-by: idnilson <[email protected]>
  • Loading branch information
idnilsonmoraisjr authored May 18, 2021
1 parent 76a4b76 commit f3605df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docker/generate/compose/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ func main() {
var selectItems []string
selectItem := ""
var extParams = make(map[string]string)
items := []string{"awsclivl", "consul", "dynamoDB", "jaeger", "kafka", "mongo", "postgres", "redis", "stubby4j", "rabbitmq", "finish!"}
items := []string{"awsclivl", "consul", "dynamoDB", "jaeger", "kafka", "mongo", "postgres", "mysql", "redis", "stubby4j", "rabbitmq", "finish!"}
for selectItem != "finish!" {
selectItem, _ = prompt.List("Select docker image: ", items)
if selectItem == "postgres" {
extParams["postgresDB"], _ = prompt.String("Type DB name: ", true)
extParams["postgresUser"], _ = prompt.String("Type DB user: ", true)
extParams["postgresPassword"], _ = prompt.StringPwd("Type DB password: ")
}
if selectItem == "mysql" {
extParams["mysqlDB"], _ = prompt.String("Type DB name: ", true)
extParams["mysqlUser"], _ = prompt.String("Type DB user: ", true)
extParams["mysqlPassword"], _ = prompt.StringPwd("Type DB password: ")
}
if selectItem == "mongo" {
extParams["mongoWebClientUser"], _ = prompt.String("Type Mongo WebClient user: ", true)
extParams["mongoWebClientPassword"], _ = prompt.StringPwd("Type Mongo WebClient password: ")
Expand Down
15 changes: 15 additions & 0 deletions docker/generate/compose/src/pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ services:`
- POSTGRES_PASSWORD={{POSTGRES_PASSWORD}}
- MAX_CONNECTIONS=300`

mysqlYml = ` mysql:
image: mysql:8.0
ports:
- "3307:3306"
environment:
- MYSQL_DATABASE={{MYSQL_DB}}
- MYSQL_USER={{MYSQL_USER}}
- MYSQL_ROOT_PASSWORD={{MYSQL_PASSWORD}}`

mongoYml = ` mongo:
image: mongo
restart: always
Expand Down Expand Up @@ -163,6 +172,12 @@ func GenerateYml(items []string, extParams map[string]string) {
postgresYmlString = strings.Replace(postgresYmlString, "{{POSTGRES_USER}}", extParams["postgresUser"], -1)
postgresYmlString = strings.Replace(postgresYmlString, "{{POSTGRES_PASSWORD}}", extParams["postgresPassword"], -1)
ymlString = fmt.Sprintf("%s%s\n\n", ymlString, postgresYmlString)
case "mysql":
mysqlYmlString := mysqlYml
mysqlYmlString = strings.Replace(mysqlYmlString, "{{MYSQL_DB}}", extParams["mysqlDB"], -1)
mysqlYmlString = strings.Replace(mysqlYmlString, "{{MYSQL_USER}}", extParams["mysqlUser"], -1)
mysqlYmlString = strings.Replace(mysqlYmlString, "{{MYSQL_PASSWORD}}", extParams["mysqlPassword"], -1)
ymlString = fmt.Sprintf("%s%s\n\n", ymlString, mysqlYmlString)
case "mongo":
mongoYmlString := mongoYml
mongoYmlString = strings.Replace(mongoYmlString, "{{MONGO_WEBCLIENT_USER}}", extParams["mongoWebClientUser"], -1)
Expand Down

0 comments on commit f3605df

Please sign in to comment.