Skip to content

Commit

Permalink
Merge pull request #14 from dung13890/develop
Browse files Browse the repository at this point in the history
refs #init yml
  • Loading branch information
dung13890 authored Feb 20, 2021
2 parents 41c44c8 + e266f0c commit 3e7b69e
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Test binary, built with `go test -c`
*.test
*.yml

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# deploy-tool

## Demo

![](docs/images/deploy.gif?raw=true)

*Note: [init](docs/images/init.gif?raw=true) | [ping](docs/images/ping.gif?raw=true)*


## Run with docker for development
```sh
docker-compose up -d
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type deploy struct {
cluster *cmdDep.Cluster
}

func DeployInit() *cli.Command {
func NewDeploy() *cli.Command {
return &cli.Command{
Name: "deploy",
Aliases: []string{"d"},
Expand Down
102 changes: 102 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package cmd

import (
"errors"
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/dung13890/deploy-tool/config"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"log"
"os"
"path/filepath"
"text/template"
)

type answers struct {
Project string
Ip string
Repo string
}

func NewInit() *cli.Command {
return &cli.Command{
Name: "init",
Aliases: []string{"i"},
Usage: "Setup new project",
Action: func(ctx *cli.Context) error {
a := &answers{}
if err := a.exec(); err != nil {
log.Fatal(err)
}
return nil
},
}
}

func (a *answers) exec() error {
// Create question setup yml file
qs := []*survey.Question{
{
Name: "project",
Prompt: &survey.Input{Message: "Please setup project name:"},
Validate: survey.Required,
},
{
Name: "ip",
Prompt: &survey.Input{
Message: "Please setup IP Remote:",
Default: "127.0.0.1",
},
},
{
Name: "repo",
Prompt: &survey.Input{
Message: "Please setup url repository:",
Default: "git@github.com:repo/example.git",
},
},
}

if err := survey.Ask(qs, a); err != nil {
return err
}

if err := a.createFile(a.Project); err != nil {
return err
}

success := color.New(color.FgHiGreen, color.Bold).PrintlnFunc()
success(fmt.Sprintf("Successfully generate file %s.yml", a.Project))

return nil
}

func (a *answers) createFile(filename string) (err error) {
// Get Current path
dir, err := os.Getwd()
if err != nil {
return
}

filename = fmt.Sprintf("%s.yml", filename)

// Check exists file config
if _, err := os.Stat(filepath.Join(dir, filename)); err == nil || os.IsExist(err) {
return errors.New(fmt.Sprintf("Warning: File config %s is exists.", filename))
}
// Create File config yml
f, err := os.Create(filepath.Join(dir, filename))
defer f.Close()
if err != nil {
return
}
// Parse template to template yml
t, err := template.New("index").Parse(config.SourceYaml)
if err != nil {
return
}
t.Execute(f, a)

return nil
}
2 changes: 1 addition & 1 deletion cmd/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ping struct {
log bool
}

func PingInit() *cli.Command {
func NewPing() *cli.Command {
return &cli.Command{
Name: "ping",
Aliases: []string{"p"},
Expand Down
29 changes: 0 additions & 29 deletions config.yml

This file was deleted.

30 changes: 30 additions & 0 deletions config/yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package config

var SourceYaml = `server:
address: "{{ .Ip }}"
user: "ec2-user"
port: 22
dir: "/data/sites"
project: "{{ .Project }}"
repository:
url: "{{ .Repo }}"
branch: "master"
# tag: "1.0.2"
shared:
folders:
- "vendor"
- "node_modules"
files:
- ".env"
tasks:
- "echo 'Hello!!'"
cluster:
hosts:
# - "127.0.0.1"
rsync:
excludes:
- ".env"
- "*.log"
cmds:
- "uname -a"
`
Binary file added docs/images/deploy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/init.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/ping.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/dung13890/deploy-tool
go 1.15

require (
github.com/AlecAivazis/survey/v2 v2.2.7
github.com/briandowns/spinner v1.12.0
github.com/cheggaaa/pb/v3 v3.0.5 // indirect
github.com/fatih/color v1.10.0
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/AlecAivazis/survey v1.8.8 h1:Y4yypp763E8cbqb5RBqZhGgkCFLRFnbRBHrxnpMMsgQ=
github.com/AlecAivazis/survey/v2 v2.2.7 h1:5NbxkF4RSKmpywYdcRgUmos1o+roJY8duCLZXbVjoig=
github.com/AlecAivazis/survey/v2 v2.2.7/go.mod h1:9DYvHgXtiXm6nCn+jXnOXLKbH+Yo9u8fAS/SduGdoPk=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/briandowns/spinner v1.12.0 h1:72O0PzqGJb6G3KgrcIOtL/JAGGZ5ptOMCn9cUHmqsmw=
Expand All @@ -8,9 +12,14 @@ github.com/cheggaaa/pb/v3 v3.0.5 h1:lmZOti7CraK9RSjzExsY53+WWfub9Qv13B5m4ptEoPE=
github.com/cheggaaa/pb/v3 v3.0.5/go.mod h1:X1L61/+36nz9bjIsrDU52qHKOQukUQe2Ge+YvGuquCw=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -20,6 +29,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand All @@ -31,14 +42,18 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
Expand All @@ -47,6 +62,7 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbq
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
23 changes: 16 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ import (
"github.com/urfave/cli/v2"
"log"
"os"
"time"
)

func main() {
cli.AppHelpTemplate = config.AppHelpTemplate
cli.CommandHelpTemplate = config.CommandHelpTemplate
ping := cmd.PingInit()
deploy := cmd.DeployInit()
app := cli.NewApp()
app.EnableBashCompletion = true
app.Commands = []*cli.Command{
ping,
deploy,
ping := cmd.NewPing()
deploy := cmd.NewDeploy()
init := cmd.NewInit()

app := &cli.App{
Name: "doo",
Usage: "Deployment for your project",
HelpName: "doo",
Compiled: time.Now(),
EnableBashCompletion: true,
Commands: []*cli.Command{
init,
ping,
deploy,
},
}
err := app.Run(os.Args)
if err != nil {
Expand Down

0 comments on commit 3e7b69e

Please sign in to comment.