Skip to content

Commit 8cee171

Browse files
author
Vic Shóstak
authored
Merge pull request #62 from create-go-app/dev
Add new param `backend_port` to CLI config
2 parents c38f11d + a816fdd commit 8cee171

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</h1>
55
<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>
66

7-
<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>
7+
<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>
88

99
## ⚡️ Quick start
1010

@@ -115,8 +115,6 @@ project:
115115
# String:
116116
# - `net/http`
117117
# - `fiber`
118-
# - `echo`
119-
# - `gin`
120118
# User template: supported, set to URL (without protocol),
121119
# like `github.com/user/template`
122120
- backend: fiber
@@ -171,6 +169,10 @@ roles:
171169
# (Required)
172170
network: cgapp_network
173171

172+
# Port for backend Docker container (both in and out).
173+
# (Required)
174+
backend_port: 5000
175+
174176
# Filename of Ansible playbook in the root of the Create Go App project.
175177
# If you want to rename it, do it, but not to change destination of file!
176178
# (Required)

cmd/deploy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
5555
username = strings.ToLower(rolesConfig["username"].(string))
5656
host = strings.ToLower(rolesConfig["host"].(string))
5757
network = strings.ToLower(rolesConfig["network"].(string))
58+
port = strings.ToLower(rolesConfig["port"].(string))
5859
askBecomePass = rolesConfig["become"].(bool)
5960
} else {
6061
// Start survey.
@@ -79,6 +80,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
7980
username = deployAnswers.Username
8081
host = deployAnswers.Host
8182
network = deployAnswers.Network
83+
port = deployAnswers.BackendPort
8284
askBecomePass = deployAnswers.AskBecomePass
8385
}
8486

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

98100
// Check, if need to ask password for username.
@@ -101,7 +103,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
101103
options = []string{
102104
playbook,
103105
"-u", username,
104-
"-e", "host=" + host + " network_name=" + network,
106+
"-e", "host=" + host + " network_name=" + network + " backend_port=" + port,
105107
"--ask-become-pass",
106108
}
107109
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var (
4040
rolesConfig map[string]interface{} // parse Ansible roles config
4141
backend, frontend, webserver, database string // define project variables
4242
installAnsibleRoles, askBecomePass bool // install Ansible roles, ask become pass
43-
username, host, network string // define deploy variables
43+
username, host, network, port string // define deploy variables
4444
playbook string = "deploy-playbook.yml" // default Ansible playbook
4545
createAnswers registry.CreateAnswers // define answers variable for `create` command
4646
deployAnswers registry.DeployAnswers // define answers variable for `deploy` command

pkg/cgapp/git_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestGitClone(t *testing.T) {
1919
"successfully cloned project",
2020
args{
2121
rootFolder: "../../tmp",
22-
templateName: "github.com/create-go-app/postgres-docker",
22+
templateName: "github.com/create-go-app/fiber-go-template",
2323
},
2424
false,
2525
},

pkg/registry/configs/.cgapp.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ project:
99
# String:
1010
# - `net/http`
1111
# - `fiber`
12-
# - `echo`
13-
# - `gin`
1412
# User template: supported, set to URL (without protocol),
1513
# like `github.com/user/template`
1614
- backend: fiber
@@ -65,6 +63,10 @@ roles:
6563
# (Required)
6664
network: cgapp_network
6765

66+
# Port for backend Docker container (both in and out).
67+
# (Required)
68+
backend_port: 5000
69+
6870
# Filename of Ansible playbook in the root of the Create Go App project.
6971
# If you want to rename it, do it, but not to change destination of file!
7072
# (Required)

pkg/registry/configs/deploy-playbook.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
path: ./backend
2323
register: backend_folder
2424

25-
- name: Check, if ./frontend directory is exists (for static files)
26-
stat:
27-
path: ./frontend
28-
register: frontend_folder
29-
3025
- name: Check, if ./webserver directory is exists
3126
stat:
3227
path: ./webserver
@@ -52,12 +47,8 @@
5247
recreate: yes
5348
networks:
5449
- name: "{{ network_name }}"
55-
volumes:
56-
# If ./frontend folder is exists, playbook will include a `dist` folder to container,
57-
# or include a default placeholder webpage (to sure, what everything is working).
58-
- "{{ './frontend/dist:/static:ro' if frontend_folder.stat.exists else './backend/static:/static:ro' }}"
5950
ports:
60-
- "5000:5000"
51+
- "{{ backend_port }}:{{ backend_port }}"
6152
state: started
6253
# Run block only if ./backend is a folder and exists.
6354
when: backend_folder.stat.exists and backend_folder.stat.isdir

pkg/registry/defaults.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
const (
3636
// CLIVersion version of Create Go App CLI.
37-
CLIVersion = "1.7.1"
37+
CLIVersion = "1.7.2"
3838
// RegexpAnsiblePattern pattern for Ansible roles.
3939
RegexpAnsiblePattern = "^(deploy)$"
4040
// RegexpBackendPattern pattern for backend.
@@ -78,6 +78,7 @@ type DeployAnswers struct {
7878
Username string
7979
Host string
8080
Network string
81+
BackendPort string
8182
AskBecomePass bool `survey:"become"`
8283
AgreeDeployment bool `survey:"agree"`
8384
}
@@ -244,6 +245,14 @@ var (
244245
},
245246
Validate: survey.Required,
246247
},
248+
{
249+
Name: "port",
250+
Prompt: &survey.Input{
251+
Message: "Enter port of backend Docker container:",
252+
Default: "5000",
253+
},
254+
Validate: survey.Required,
255+
},
247256
{
248257
Name: "agree",
249258
Prompt: &survey.Confirm{

0 commit comments

Comments
 (0)