Skip to content

Commit

Permalink
Merge pull request #62 from create-go-app/dev
Browse files Browse the repository at this point in the history
Add new param `backend_port` to CLI config
  • Loading branch information
Vic Shóstak authored Mar 5, 2021
2 parents c38f11d + a816fdd commit 8cee171
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</h1>
<p align="center">Create a new production-ready project with <b>backend</b> (Golang), <b>frontend</b> (JavaScript, TypeScript)<br/>and <b>deploy automation</b> (Ansible, Docker) by running one CLI command.<br/><br/>Focus on <b>writing</b> code and <b>thinking</b> of business-logic! The CLI will take care of the rest.</p>

<p align="center"><a href="https://github.com/create-go-app/cli/releases" target="_blank"><img src="https://img.shields.io/badge/version-v1.7.1-blue?style=for-the-badge&logo=none" alt="cli version" /></a>&nbsp;<a href="https://pkg.go.dev/github.com/create-go-app/cli?tab=doc" target="_blank"><img src="https://img.shields.io/badge/Go-1.16+-00ADD8?style=for-the-badge&logo=go" alt="go version" /></a>&nbsp;<a href="https://gocover.io/github.com/create-go-app/cli/pkg/cgapp" target="_blank"><img src="https://img.shields.io/badge/Go_Cover-94%25-success?style=for-the-badge&logo=none" alt="go cover" /></a>&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/cli" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a>&nbsp;<img src="https://img.shields.io/badge/license-apache_2.0-red?style=for-the-badge&logo=none" alt="license" /></p>
<p align="center"><a href="https://github.com/create-go-app/cli/releases" target="_blank"><img src="https://img.shields.io/badge/version-v1.7.2-blue?style=for-the-badge&logo=none" alt="cli version" /></a>&nbsp;<a href="https://pkg.go.dev/github.com/create-go-app/cli?tab=doc" target="_blank"><img src="https://img.shields.io/badge/Go-1.16+-00ADD8?style=for-the-badge&logo=go" alt="go version" /></a>&nbsp;<a href="https://gocover.io/github.com/create-go-app/cli/pkg/cgapp" target="_blank"><img src="https://img.shields.io/badge/Go_Cover-94%25-success?style=for-the-badge&logo=none" alt="go cover" /></a>&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/cli" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a>&nbsp;<img src="https://img.shields.io/badge/license-apache_2.0-red?style=for-the-badge&logo=none" alt="license" /></p>

## ⚡️ Quick start

Expand Down Expand Up @@ -115,8 +115,6 @@ project:
# String:
# - `net/http`
# - `fiber`
# - `echo`
# - `gin`
# User template: supported, set to URL (without protocol),
# like `github.com/user/template`
- backend: fiber
Expand Down Expand Up @@ -171,6 +169,10 @@ roles:
# (Required)
network: cgapp_network

# Port for backend Docker container (both in and out).
# (Required)
backend_port: 5000

# Filename of Ansible playbook in the root of the Create Go App project.
# If you want to rename it, do it, but not to change destination of file!
# (Required)
Expand Down
6 changes: 4 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
username = strings.ToLower(rolesConfig["username"].(string))
host = strings.ToLower(rolesConfig["host"].(string))
network = strings.ToLower(rolesConfig["network"].(string))
port = strings.ToLower(rolesConfig["port"].(string))
askBecomePass = rolesConfig["become"].(bool)
} else {
// Start survey.
Expand All @@ -79,6 +80,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
username = deployAnswers.Username
host = deployAnswers.Host
network = deployAnswers.Network
port = deployAnswers.BackendPort
askBecomePass = deployAnswers.AskBecomePass
}

Expand All @@ -92,7 +94,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
options := []string{
playbook,
"-u", username,
"-e", "host=" + host + " network_name=" + network,
"-e", "host=" + host + " network_name=" + network + " backend_port=" + port,
}

// Check, if need to ask password for username.
Expand All @@ -101,7 +103,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
options = []string{
playbook,
"-u", username,
"-e", "host=" + host + " network_name=" + network,
"-e", "host=" + host + " network_name=" + network + " backend_port=" + port,
"--ask-become-pass",
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
rolesConfig map[string]interface{} // parse Ansible roles config
backend, frontend, webserver, database string // define project variables
installAnsibleRoles, askBecomePass bool // install Ansible roles, ask become pass
username, host, network string // define deploy variables
username, host, network, port string // define deploy variables
playbook string = "deploy-playbook.yml" // default Ansible playbook
createAnswers registry.CreateAnswers // define answers variable for `create` command
deployAnswers registry.DeployAnswers // define answers variable for `deploy` command
Expand Down
2 changes: 1 addition & 1 deletion pkg/cgapp/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGitClone(t *testing.T) {
"successfully cloned project",
args{
rootFolder: "../../tmp",
templateName: "github.com/create-go-app/postgres-docker",
templateName: "github.com/create-go-app/fiber-go-template",
},
false,
},
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/configs/.cgapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ project:
# String:
# - `net/http`
# - `fiber`
# - `echo`
# - `gin`
# User template: supported, set to URL (without protocol),
# like `github.com/user/template`
- backend: fiber
Expand Down Expand Up @@ -65,6 +63,10 @@ roles:
# (Required)
network: cgapp_network

# Port for backend Docker container (both in and out).
# (Required)
backend_port: 5000

# Filename of Ansible playbook in the root of the Create Go App project.
# If you want to rename it, do it, but not to change destination of file!
# (Required)
Expand Down
11 changes: 1 addition & 10 deletions pkg/registry/configs/deploy-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
path: ./backend
register: backend_folder

- name: Check, if ./frontend directory is exists (for static files)
stat:
path: ./frontend
register: frontend_folder

- name: Check, if ./webserver directory is exists
stat:
path: ./webserver
Expand All @@ -52,12 +47,8 @@
recreate: yes
networks:
- name: "{{ network_name }}"
volumes:
# If ./frontend folder is exists, playbook will include a `dist` folder to container,
# or include a default placeholder webpage (to sure, what everything is working).
- "{{ './frontend/dist:/static:ro' if frontend_folder.stat.exists else './backend/static:/static:ro' }}"
ports:
- "5000:5000"
- "{{ backend_port }}:{{ backend_port }}"
state: started
# Run block only if ./backend is a folder and exists.
when: backend_folder.stat.exists and backend_folder.stat.isdir
Expand Down
11 changes: 10 additions & 1 deletion pkg/registry/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

const (
// CLIVersion version of Create Go App CLI.
CLIVersion = "1.7.1"
CLIVersion = "1.7.2"
// RegexpAnsiblePattern pattern for Ansible roles.
RegexpAnsiblePattern = "^(deploy)$"
// RegexpBackendPattern pattern for backend.
Expand Down Expand Up @@ -78,6 +78,7 @@ type DeployAnswers struct {
Username string
Host string
Network string
BackendPort string
AskBecomePass bool `survey:"become"`
AgreeDeployment bool `survey:"agree"`
}
Expand Down Expand Up @@ -244,6 +245,14 @@ var (
},
Validate: survey.Required,
},
{
Name: "port",
Prompt: &survey.Input{
Message: "Enter port of backend Docker container:",
Default: "5000",
},
Validate: survey.Required,
},
{
Name: "agree",
Prompt: &survey.Confirm{
Expand Down

0 comments on commit 8cee171

Please sign in to comment.