Skip to content

Commit 4d0ffb1

Browse files
author
Vic Shóstak
authored
Merge pull request #16 from create-go-app/dev
Dev -> v1.5.2
2 parents b41db70 + 9279b1c commit 4d0ffb1

File tree

14 files changed

+166
-98
lines changed

14 files changed

+166
-98
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ insert_final_newline = true
1212
indent_style = tab
1313
indent_size = 4
1414

15-
[{Dockerfile,Makefile,*.yml,*.yaml}]
15+
[{Dockerfile,*.yml,*.yaml}]
1616
indent_style = tab
1717
indent_size = 2

README.md

Lines changed: 5 additions & 5 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.5.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.11+-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.5.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.11+-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](https://create-go.app/quick-start/)
1010

@@ -13,7 +13,7 @@ First of all, [download](https://golang.org/dl/) and install **Go**. Version `1.
1313
Next, download the **latest** version of the Create Go App CLI to your system:
1414

1515
```bash
16-
go get -u github.com/create-go-app/cli
16+
go get github.com/create-go-app/cli
1717
```
1818

1919
Installation is done by using the [`go build`](https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies) command with `$GOPATH/bin`:
@@ -44,7 +44,7 @@ If you don't want to install Create Go App CLI to your system, you feel free to
4444
docker run --rm -it -v ${PWD}:${PWD} -w ${PWD} koddr/cgapp:latest
4545
```
4646

47-
With this Docker image, you do **not** have to worry about installing tools/CLI of frontend UI libraries/frameworks. Everything is **already included** to this Docker image: `create-react-app`, `preact-cli`, `vue-cli`, `ng-cli` and `degit` (for Svelte and Sapper).
47+
With this Docker image, you do **not** have to worry about installing tools/CLI of frontend UI libraries/frameworks. Everything is **already included**: `create-react-app`, `preact-cli`, `vue-cli`, `ng-cli` and `degit` (for Svelte and Sapper).
4848

4949
Available commands for official Docker image:
5050

@@ -261,9 +261,9 @@ cgapp deploy --use-config
261261

262262
## 🤔 Why another CLI?
263263

264-
Yes, when we started this project, we asked ourselves this question too and... came to the conclusion, that about **8-10** routine steps in each project can be automated with a smart CLI.
264+
When we started this project, we asked ourselves this question too and... came to the conclusion, that approximately 8 out of 10 routine operations at the start of a new project and/or the deployment of an existing one **can be automated**. And it would be better to have all the necessary functions inside one CLI. That's why we transferred all our experience to the Create Go App CLI, which we use ourselves!
265265

266-
The Create Go App project allow you to prepare and deploy your project **without** any unnecessary headaches.
266+
So, yes, this CLI gives you the ability to prepare everything you need to **start a new project** (as `create-react-app` for the React.js ecosystem does) and **deploy an existing project** to a remote server in configured and fully isolated Docker containers.
267267

268268
## ⭐️ Project assistance
269269

cmd/create.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ var runCreateCmd = func(cmd *cobra.Command, args []string) {
114114
os.Exit(1)
115115
}
116116

117-
// Create Ansible playbook and download roles, if not skipped.
117+
// Create Ansible playbook with tasks, if not skipped.
118118
if installAnsibleRoles {
119-
cgapp.SendMsg(true, "*", "Create Ansible playbook and roles...", "cyan", true)
119+
cgapp.SendMsg(true, "*", "Create Ansible playbook with tasks...", "cyan", true)
120120

121121
// Create playbook.
122122
fileToMake := map[string][]byte{
@@ -126,20 +126,6 @@ var runCreateCmd = func(cmd *cobra.Command, args []string) {
126126
cgapp.SendMsg(true, "[ERROR]", err.Error(), "red", true)
127127
os.Exit(1)
128128
}
129-
130-
// Create Ansible roles.
131-
if err := cgapp.CreateProjectFromRegistry(
132-
&registry.Project{
133-
Type: "roles",
134-
Name: "deploy",
135-
RootFolder: currentDir,
136-
},
137-
registry.Repositories,
138-
registry.RegexpAnsiblePattern,
139-
); err != nil {
140-
cgapp.SendMsg(true, "[ERROR]", err.Error(), "red", true)
141-
os.Exit(1)
142-
}
143129
}
144130

145131
// Create backend files.

cmd/deploy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"github.com/spf13/cobra"
3636
)
3737

38-
// deployCmd represents the `deploy` command
38+
// deployCmd represents the `deploy` command.
3939
var deployCmd = &cobra.Command{
4040
Use: "deploy",
4141
Aliases: []string{"serve"},
@@ -44,7 +44,7 @@ var deployCmd = &cobra.Command{
4444
Run: runDeployCmd,
4545
}
4646

47-
// runDeployCmd represents runner for the `deploy` command
47+
// runDeployCmd represents runner for the `deploy` command.
4848
var runDeployCmd = func(cmd *cobra.Command, args []string) {
4949
// Start message.
5050
cgapp.SendMsg(true, "* * *", "Deploying project via Create Go App CLI v"+registry.CLIVersion+"...", "yellow", true)
@@ -112,7 +112,7 @@ var runDeployCmd = func(cmd *cobra.Command, args []string) {
112112
os.Exit(1)
113113
}
114114

115-
// Stop timer
115+
// Stop timer.
116116
stopTimer := time.Since(startTimer).String()
117117

118118
// End message.

cmd/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ import (
3232
"github.com/spf13/cobra"
3333
)
3434

35-
// initCmd represents the init command
35+
// initCmd represents the init command.
3636
var initCmd = &cobra.Command{
3737
Use: "init",
3838
Short: "Init a configuration file for the Create Go App project",
3939
Long: "\nInit a configuration file for the Create Go App project.",
4040
Run: runInitCmd,
4141
}
4242

43+
// runInitCmd represents runner for the `init` command.
4344
var runInitCmd = func(cmd *cobra.Command, args []string) {
4445
// Get current directory.
4546
currentDir, _ := os.Getwd()

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var (
5757
}
5858
)
5959

60-
// rootCmd represents the base command when called without any subcommands
60+
// rootCmd represents the base command when called without any subcommands.
6161
var rootCmd = &cobra.Command{
6262
Use: "cgapp",
6363
Version: registry.CLIVersion,
@@ -94,7 +94,7 @@ func initConfig() {
9494
os.Exit(1)
9595
}
9696

97-
// Parse configs
97+
// Parse configs.
9898
_ = viper.UnmarshalKey("project", &projectConfig)
9999
_ = viper.UnmarshalKey("roles", &rolesConfig)
100100
}

configs/.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ insert_final_newline = true
1414
indent_style = tab
1515
indent_size = 4
1616

17-
[{Dockerfile,Makefile,*.yml,*.yaml}]
17+
[{Dockerfile,*.yml,*.yaml}]
1818
indent_style = tab
1919
indent_size = 2

configs/deploy-playbook.yml

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,117 @@
66
- hosts: "{{ host }}"
77
become: yes
88

9-
roles:
10-
# Build & run project's backend
11-
- deploy/cgapp_backend
12-
# Configure and run project's webserver
13-
- deploy/cgapp_webserver
14-
# Configure and run project's database
15-
- deploy/cgapp_database
9+
tasks:
10+
#
11+
# Create a new Docker network for connect all project elements into one network.
12+
#
13+
- name: Create a new Docker network ({{ network_name }})
14+
docker_network:
15+
name: "{{ network_name }}"
16+
17+
#
18+
# Check all necessary project folders for future use.
19+
#
20+
- name: Check, if ./backend directory is exists
21+
stat:
22+
path: ./backend
23+
register: backend_folder
24+
25+
- name: Check, if ./frontend directory is exists (for static files)
26+
stat:
27+
path: ./frontend
28+
register: frontend_folder
29+
30+
- name: Check, if ./webserver directory is exists
31+
stat:
32+
path: ./webserver
33+
register: webserver_folder
34+
35+
- name: Check, if ./database directory is exists
36+
stat:
37+
path: ./database
38+
register: database_folder
39+
40+
#
41+
# The block that builds and runs the backend part of the project.
42+
#
43+
- name: Backend block
44+
block:
45+
- name: Builds Docker image for backend
46+
docker_image:
47+
name: cgapp_backend # name of the backend image
48+
build:
49+
path: ./backend # folder with Dockerfile
50+
pull: yes
51+
source: build
52+
53+
- name: Runs Docker container with backend
54+
docker_container:
55+
name: cgapp-backend # name of the backend container
56+
image: cgapp_backend:latest
57+
recreate: yes
58+
networks:
59+
- name: "{{ network_name }}"
60+
volumes:
61+
# If ./frontend folder is exists, playbook will include a `dist` folder to container,
62+
# or include a default placeholder webpage (to sure, what everything is working).
63+
- "{{ './frontend/dist:/static:ro' if frontend_folder.stat.exists else './backend/static:/static:ro' }}"
64+
ports:
65+
- "5000:5000"
66+
state: started
67+
# Run block only if ./backend is a folder and exists.
68+
when: backend_folder.stat.exists and backend_folder.stat.isdir
69+
70+
#
71+
# The block that builds and runs the webserver part of the project.
72+
#
73+
- name: Webserver block
74+
block:
75+
- name: Builds Docker image for webserver
76+
docker_image:
77+
name: cgapp_webserver # name of the webserver image
78+
build:
79+
path: ./webserver
80+
pull: yes
81+
source: build
82+
83+
- name: Runs Docker container with webserver
84+
docker_container:
85+
name: cgapp-webserver # name of the webserver container
86+
image: cgapp_webserver:latest
87+
recreate: yes
88+
networks:
89+
- name: "{{ network_name }}"
90+
env:
91+
APP_DOMAIN: "{{ host }}"
92+
ports:
93+
- "80:80"
94+
state: started
95+
# Run block only if ./webserver is a folder and exists.
96+
when: webserver_folder.stat.exists and webserver_folder.stat.isdir
97+
98+
#
99+
# The block that builds and runs the database part of the project.
100+
#
101+
- name: Database block
102+
block:
103+
- name: Builds Docker image for database
104+
docker_image:
105+
name: cgapp_database # name of the database image
106+
build:
107+
path: ./database # folder with Dockerfile
108+
pull: yes
109+
source: build
110+
111+
- name: Runs Docker container with database
112+
docker_container:
113+
name: cgapp-database # name of the database container
114+
image: cgapp_database:latest
115+
recreate: yes
116+
networks:
117+
- name: "{{ network_name }}"
118+
ports:
119+
- "5432:5432"
120+
state: started
121+
# Run block only if ./database is a folder and exists.
122+
when: database_folder.stat.exists and database_folder.stat.isdir

pkg/cgapp/create.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ func CreateProjectFromRegistry(p *registry.Project, r map[string]*registry.Repos
4747
// Create path in project root folder.
4848
folder := filepath.Join(p.RootFolder, p.Type)
4949

50-
// Re-define folder for Ansible roles
51-
if p.Type == "roles" {
52-
folder = filepath.Join(p.RootFolder, p.Type, p.Name)
53-
}
54-
5550
// Create match expration.
5651
match, err := regexp.MatchString(m, p.Name)
5752
if err != nil {

pkg/cgapp/create_test.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,16 @@ func TestCreateProjectFromRegistry(t *testing.T) {
5757
},
5858
false,
5959
},
60-
{
61-
"successfully created Ansible deploy roles",
62-
args{
63-
p: &registry.Project{
64-
Type: "roles",
65-
Name: "deploy",
66-
RootFolder: "../../tmp",
67-
},
68-
r: registry.Repositories,
69-
m: registry.RegexpAnsiblePattern,
70-
},
71-
false,
72-
},
7360
{
7461
"failed to create (not valid repository)",
7562
args{
7663
p: &registry.Project{
77-
Type: "roles",
78-
Name: "deploy",
64+
Type: "backend",
65+
Name: "echo",
7966
RootFolder: "../../tmp",
8067
},
8168
r: map[string]*registry.Repository{
82-
"roles": {
69+
"backend": {
8370
List: map[string]string{},
8471
},
8572
},
@@ -91,12 +78,12 @@ func TestCreateProjectFromRegistry(t *testing.T) {
9178
"failed to create (not valid repository with wrong name)",
9279
args{
9380
p: &registry.Project{
94-
Type: "roles",
81+
Type: "backend",
9582
Name: "wrong-name",
9683
RootFolder: "../../tmp",
9784
},
9885
r: map[string]*registry.Repository{
99-
"roles": {
86+
"backend": {
10087
List: map[string]string{},
10188
},
10289
},
@@ -108,8 +95,8 @@ func TestCreateProjectFromRegistry(t *testing.T) {
10895
"failed to create (repositories is nil)",
10996
args{
11097
p: &registry.Project{
111-
Type: "roles",
112-
Name: "deploy",
98+
Type: "backend",
99+
Name: "echo",
113100
RootFolder: "../../tmp",
114101
},
115102
r: nil,
@@ -130,8 +117,8 @@ func TestCreateProjectFromRegistry(t *testing.T) {
130117
"failed to create (pattern is nil)",
131118
args{
132119
p: &registry.Project{
133-
Type: "roles",
134-
Name: "deploy",
120+
Type: "backend",
121+
Name: "echo",
135122
RootFolder: "../../tmp",
136123
},
137124
r: registry.Repositories,

0 commit comments

Comments
 (0)