Skip to content

Commit

Permalink
Extract templates to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriiklymiuk committed Oct 4, 2022
1 parent c320ba7 commit 334958f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
37 changes: 3 additions & 34 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"text/template"

"andriiklymiuk/corgi/templates"
"andriiklymiuk/corgi/utils"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -52,8 +53,8 @@ Please provided them in corgi-compose.yml file`)
}

filesToCreate := []FilenameForService{
{"docker-compose.yml", dockerComposeTemplate},
{"Makefile", makefileTemplate},
{"docker-compose.yml", templates.DockerComposePostgres},
{"Makefile", templates.MakefilePostgres},
}

for _, service := range databaseServices {
Expand Down Expand Up @@ -151,38 +152,6 @@ func createFileFromTemplate(
return nil
}

var dockerComposeTemplate = `version: "3.8"
services:
postgres:
image: postgres:11.5-alpine
container_name: postgres-{{.ServiceName}}
logging:
driver: none
environment:
- POSTGRES_USER={{.User}}
- POSTGRES_PASSWORD={{.Password}}
- POSTGRES_DB={{.DatabaseName}}
ports:
- "{{.Port}}:5432"
`

var makefileTemplate = `up:
docker compose up -d
down:
docker compose down
stop:
docker stop postgres-{{.ServiceName}}
id:
docker ps -aqf "name=postgres-{{.ServiceName}}" | awk '{print $1}'
seed:
cat dump.sql | docker exec -i $(c) psql -U {{.User}} -d {{.DatabaseName}}
help:
make -qpRr | egrep -e '^[a-z].*:$$' | sed -e 's~:~~g' | sort
.PHONY: up down stop id seed help
`

func init() {
rootCmd.AddCommand(initCmd)
}
33 changes: 33 additions & 0 deletions templates/postgres.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package templates

var DockerComposePostgres = `version: "3.8"
services:
postgres:
image: postgres:11.5-alpine
container_name: postgres-{{.ServiceName}}
logging:
driver: none
environment:
- POSTGRES_USER={{.User}}
- POSTGRES_PASSWORD={{.Password}}
- POSTGRES_DB={{.DatabaseName}}
ports:
- "{{.Port}}:5432"
`

var MakefilePostgres = `up:
docker compose up -d
down:
docker compose down
stop:
docker stop postgres-{{.ServiceName}}
id:
docker ps -aqf "name=postgres-{{.ServiceName}}" | awk '{print $1}'
seed:
cat dump.sql | docker exec -i $(c) psql -U {{.User}} -d {{.DatabaseName}}
help:
make -qpRr | egrep -e '^[a-z].*:$$' | sed -e 's~:~~g' | sort
.PHONY: up down stop id seed help
`

0 comments on commit 334958f

Please sign in to comment.