From 2e265376120eb1ca40c30d4e900762e43acfb512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vic=20Sh=C3=B3stak?= Date: Wed, 21 Apr 2021 14:18:11 +0300 Subject: [PATCH 01/74] Add Traefik proxy to webservers --- README.md | 2 +- cmd/create.go | 31 ++++++++++++++----------------- pkg/registry/defaults.go | 9 +++++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 8ad6ec0..a64f025 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

Create a new production-ready project with backend (Golang), frontend (JavaScript, TypeScript)
and deploy automation (Ansible, Docker) by running one CLI command.

Focus on writing code and thinking of business-logic! The CLI will take care of the rest.

-

cli version go version go cover go report license

+

cli version go version go cover go report license

## ⚑️ Quick start diff --git a/cmd/create.go b/cmd/create.go index e62d2f0..8051a66 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -137,26 +137,23 @@ var runCreateCmd = func(cmd *cobra.Command, args []string) { } } - // Docker containers. if webserver != "none" { - + // Docker containers. cgapp.SendMsg(true, "* * *", "Configuring Docker containers...", "yellow", false) - if webserver != "none" { - // Create container with a web/proxy server. - cgapp.SendMsg(true, "*", "Create container with web/proxy server...", "cyan", true) - if err := cgapp.CreateProjectFromRegistry( - ®istry.Project{ - Type: "webserver", - Name: webserver, - RootFolder: currentDir, - }, - registry.Repositories, - registry.RegexpWebServerPattern, - ); err != nil { - cgapp.SendMsg(true, "[ERROR]", err.Error(), "red", true) - os.Exit(1) - } + // Create container with a web/proxy server. + cgapp.SendMsg(true, "*", "Create container with web/proxy server...", "cyan", true) + if err := cgapp.CreateProjectFromRegistry( + ®istry.Project{ + Type: "webserver", + Name: webserver, + RootFolder: currentDir, + }, + registry.Repositories, + registry.RegexpWebServerPattern, + ); err != nil { + cgapp.SendMsg(true, "[ERROR]", err.Error(), "red", true) + os.Exit(1) } } diff --git a/pkg/registry/defaults.go b/pkg/registry/defaults.go index e0b399f..ffde285 100644 --- a/pkg/registry/defaults.go +++ b/pkg/registry/defaults.go @@ -12,7 +12,7 @@ import ( const ( // CLIVersion version of Create Go App CLI. - CLIVersion = "1.7.5" + CLIVersion = "1.8.0" // RegexpAnsiblePattern pattern for Ansible roles. RegexpAnsiblePattern = "^(deploy)$" // RegexpBackendPattern pattern for backend. @@ -20,7 +20,7 @@ const ( // RegexpFrontendPattern pattern for backend. RegexpFrontendPattern = "^(p?react:?|vue(:?[\\w]+)?(:?[\\w-_0-9\\/]+)?|angular|svelte|sapper:?)" // RegexpWebServerPattern pattern for web/proxy servers. - RegexpWebServerPattern = "^(nginx)$" + RegexpWebServerPattern = "^(nginx|traefik)$" ) // Project struct for describe project. @@ -99,7 +99,8 @@ var ( // Docker containers with web/proxy servers. "webserver": { List: map[string]string{ - "nginx": "github.com/create-go-app/nginx-docker", + "nginx": "github.com/create-go-app/nginx-docker", + "traefik": "github.com/create-go-app/traefik-docker", }, }, } @@ -170,7 +171,7 @@ var ( Name: "webserver", Prompt: &survey.Select{ Message: "Choose a web/proxy server:", - Options: []string{"none", "Nginx"}, + Options: []string{"none", "Nginx", "Traefik"}, Default: "none", }, }, From 52762c94ac767cf18c5efa2fca21e02c7525a73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vic=20Sh=C3=B3stak?= Date: Wed, 21 Apr 2021 14:27:32 +0300 Subject: [PATCH 02/74] Add Traefik to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a64f025..55ee42e 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ So, yes, this CLI gives you the ability to prepare everything you need to **star **Web/Proxy server:** - [x] [`nginx`](https://create-go.app/docker-containers/nginx/) β€” Docker container with [Nginx](https://nginx.org). +- [x] [`traefik`](https://create-go.app/docker-containers/traefik/) β€” Docker container with [Traefik Proxy](https://traefik.io/traefik/). ## πŸ‘€ Custom templates & containers? From a4363d40ebe764e0c16b8a97b7cd69060a53d6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vic=20Sh=C3=B3stak?= Date: Mon, 26 Apr 2021 01:55:13 +0300 Subject: [PATCH 03/74] Refactoring & Re-design CLI; Road to cgapp v2 --- README.md | 164 +++++++----------- main.go => cmd/cgapp/main.go | 0 cmd/create.go | 127 +++++--------- cmd/deploy.go | 81 ++------- cmd/generate.go | 79 +++++++++ cmd/init.go | 47 ----- cmd/root.go | 40 +---- go.mod | 3 +- go.sum | 21 +-- pkg/cgapp/create.go | 39 ++--- pkg/cgapp/create_test.go | 69 -------- pkg/cgapp/exec.go | 17 +- pkg/cgapp/files.go | 74 +++++--- pkg/cgapp/files_test.go | 82 +++++++-- pkg/cgapp/git.go | 14 +- pkg/cgapp/utils.go | 17 +- pkg/cgapp/utils_test.go | 51 ------ pkg/registry/configs/.cgapp.yml | 4 +- pkg/registry/configs/deploy-playbook.yml | 82 --------- pkg/registry/defaults.go | 96 +++++----- pkg/registry/{configs => misc}/.editorconfig | 0 pkg/registry/{configs => misc}/.gitattributes | 0 pkg/registry/{configs => misc}/.gitignore | 6 + pkg/registry/{configs => misc}/Makefile | 0 pkg/registry/roles/backend/tasks/main.yml | 59 +++++++ pkg/registry/roles/docker/tasks/main.yml | 57 ++++++ pkg/registry/roles/traefik/tasks/main.yml | 89 ++++++++++ .../roles/traefik/templates/traefik.yml.j2 | 52 ++++++ pkg/registry/templates/hosts.ini.tmpl | 28 +++ pkg/registry/templates/playbook.yml.tmpl | 18 ++ 30 files changed, 727 insertions(+), 689 deletions(-) rename main.go => cmd/cgapp/main.go (100%) create mode 100644 cmd/generate.go delete mode 100644 cmd/init.go delete mode 100644 pkg/registry/configs/deploy-playbook.yml rename pkg/registry/{configs => misc}/.editorconfig (100%) rename pkg/registry/{configs => misc}/.gitattributes (100%) rename pkg/registry/{configs => misc}/.gitignore (87%) rename pkg/registry/{configs => misc}/Makefile (100%) create mode 100644 pkg/registry/roles/backend/tasks/main.yml create mode 100755 pkg/registry/roles/docker/tasks/main.yml create mode 100755 pkg/registry/roles/traefik/tasks/main.yml create mode 100755 pkg/registry/roles/traefik/templates/traefik.yml.j2 create mode 100644 pkg/registry/templates/hosts.ini.tmpl create mode 100755 pkg/registry/templates/playbook.yml.tmpl diff --git a/README.md b/README.md index 55ee42e..be9e099 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ First of all, [download](https://golang.org/dl/) and install **Go**. Version `1. Installation is done by using the [`go install`](https://golang.org/cmd/go/#hdr-Compile_and_install_packages_and_dependencies) command and rename installed binary in `$GOPATH/bin`: ```bash -go install -ldflags="-s -w" github.com/create-go-app/cli && mv $GOPATH/bin/cli $GOPATH/bin/cgapp +CGO_ENABLED=0 go install -ldflags="-s -w" github.com/create-go-app/cli/cmd/cgapp@latest ``` Also, macOS and GNU/Linux users available way to install via [Homebrew](https://brew.sh/): @@ -32,10 +32,14 @@ Let's create a new project via **interactive console UI** (or **CUI** for short) cgapp create ``` -Okay, it works! Now, you can run this project on your **local machine** or deploy to a **remote server**. Project works in isolated Docker containers and automates via Ansible playbook: +Okay, it works! Now, you can create deploy config for this project and then ship it to your **remote server**. Project works in isolated Docker containers and automates via Ansible playbooks and roles: ```bash -cgapp deploy +cgapp deploy init + +# ... + +cgapp deploy start ``` That's all you need to start! πŸŽ‰ @@ -52,7 +56,6 @@ With this Docker image, you do **not** have to worry about installing tools/CLI Available commands for [official Docker image](https://create-go.app/detailed-guides/official-docker-image/): -- [x] [`init`](https://create-go.app/detailed-guides/commands-and-options/#init) - [x] [`create`](https://create-go.app/detailed-guides/commands-and-options/#create) > πŸ”” Please note: a [`deploy`](https://create-go.app/detailed-guides/commands-and-options/#deploy) command is currently unavailable in this image. @@ -76,7 +79,6 @@ Unfortunately, we are unable to include all helpful documentation to the `README - [CLI Installation](https://create-go.app/detailed-guides/installation/) - [Alternative installations](https://create-go.app/detailed-guides/installation/#alternative-installations) - [Understanding CLI commands and options](https://create-go.app/detailed-guides/commands-and-options/) - - [`init`](https://create-go.app/detailed-guides/commands-and-options/#init) - [`create`](https://create-go.app/detailed-guides/commands-and-options/#create) - [`deploy`](https://create-go.app/detailed-guides/commands-and-options/#deploy) - [Working with the official Docker image](https://create-go.app/detailed-guides/official-docker-image/) @@ -91,96 +93,6 @@ Unfortunately, we are unable to include all helpful documentation to the `README ## βš™οΈ Commands & Options -### `init` - -CLI command for generate a default `.cgapp.yml` config file in current folder: - -```bash -cgapp init -``` - -- πŸ“Ί Preview: https://recordit.co/yvlnIu8Lyp -- πŸ“– Docs: https://create-go.app/detailed-guides/commands-and-options/#init - -
-Generated config file - -
- -```yaml -# Project config. -project: - # Backend for your project. - # (Required) - # String: - # - `net/http` - # - `fiber` - # User template: supported, set to URL (without protocol), - # like `github.com/user/template` - - backend: fiber - - # Frontend for your project. - # (Optional, to skip set to `none`) - # String: - # - `react` - # - `react: