Skip to content

Commit

Permalink
Prototype of automated deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
sibprogrammer committed Jun 7, 2021
1 parent f8f2fe0 commit 28d195b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actions/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func UploadDirectory(host types.Server, domain types.Domain, ovw bool, dry bool,
}

return filepath.Walk(dir, func(p string, info os.FileInfo, err error) error {
if info.IsDir() && (info.Name() == ".git" || info.Name() == ".idea") {
return filepath.SkipDir
}

pathPart := strings.TrimPrefix(p, dir)
if pathPart == "." {
return nil
Expand Down
63 changes: 63 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 1999-2021. Plesk International GmbH.

package cmd

import (
"errors"
"fmt"
"github.com/plesk/pleskapp/plesk/actions"
"github.com/plesk/pleskapp/plesk/config"
"github.com/plesk/pleskapp/plesk/locales"
"github.com/plesk/pleskapp/plesk/types"
"github.com/spf13/cobra"
"os"
"path"
"strings"
)

var deployCmd = &cobra.Command{
Use: "deploy [SERVER]",
Short: locales.L.Get("deploy.description"),
RunE: func(cmd *cobra.Command, args []string) error {
workDir, _ := os.Getwd()
appName := path.Base(workDir)
fmt.Println("App name:", appName)

server, err := config.GetServerByArgs(args)
if err != nil {
return err
}

if 0 == len(server.Info.IP.IPv4) {
return errors.New("IPv4 address is required")
}
defaultIp := server.Info.IP.IPv4[0]
fmt.Printf("IP: %v\n", defaultIp)

domainName := fmt.Sprintf("%s.%s.plesk.page", appName, strings.ReplaceAll(defaultIp, ".", "-"))
fmt.Println("Domain name:", domainName)

var domain *types.Domain
domain, err = config.GetDomain(*server, domainName)
if err != nil {
fmt.Printf("Creating the domain %s...\n", domainName)
err = actions.DomainAdd(*server, domainName, types.ServerIPAddresses{
IPv4: []string{defaultIp},
})
if err != nil {
return err
}
fmt.Println("Domain has been created.")
} else {
fmt.Printf("Domain %s has been found.\n", domainName)
}

fmt.Println("Uploading the content...")
err = actions.UploadDirectory(*server, *domain, true, false, workDir, nil)
if err != nil {
return err
}

return nil
},
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Execute() error {
webCmd,
completionCmd,
pleskCmd,
deployCmd,
)

return rootCmd.Execute()
Expand Down
2 changes: 2 additions & 0 deletions locales/locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func init() {
"web.description": "Run local web server to serve current directory",

"completion.description": "Output shell completion code for the specified shell",

"deploy.description": "Deploy the app in the current directory to default server",
},
}

Expand Down

0 comments on commit 28d195b

Please sign in to comment.