Skip to content

Commit

Permalink
refactor: move functions from build to deploy cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed Jun 14, 2024
1 parent e5c98e4 commit 29e5dfe
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 964 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.4
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc v1.0.0
github.com/aziontech/azionapi-go-sdk v0.130.0
github.com/aziontech/azionapi-go-sdk v0.133.0
github.com/aziontech/go-thoth v0.0.0-20240228144710-d061a88cc39f
github.com/aziontech/tablecli v0.0.0-20240513193320-c4dbf16b013a
github.com/fatih/color v1.17.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aziontech/azionapi-go-sdk v0.130.0 h1:mKoOzPC6GJCRl5f7FZsyflc3JRKZ9nMRNMO+dly71E4=
github.com/aziontech/azionapi-go-sdk v0.130.0/go.mod h1:cA5DY/VP4X5Eu11LpQNzNn83ziKjja7QVMIl4J45feA=
github.com/aziontech/azionapi-go-sdk v0.133.0 h1:xwDJd0kY3oQBMwnSZifVry43x46qnhOaQ3vnAmjmWsQ=
github.com/aziontech/azionapi-go-sdk v0.133.0/go.mod h1:cA5DY/VP4X5Eu11LpQNzNn83ziKjja7QVMIl4J45feA=
github.com/aziontech/go-thoth v0.0.0-20240228144710-d061a88cc39f h1:b0IX6tpiiG+QzCVOBqwYEHP5gPeeESq57A5ZXiYyDS4=
github.com/aziontech/go-thoth v0.0.0-20240228144710-d061a88cc39f/go.mod h1:v4AMg2JrM68ckr2nt7c7PRuOELek/JbVRa62+inlprQ=
github.com/aziontech/tablecli v0.0.0-20240513193320-c4dbf16b013a h1:jKR7y/1ePDPZkfKgqj7gUK9XB7KRHsyHci8tJXD3YTM=
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type BuildCmd struct {
WriteAzionJsonContent func(conf *contracts.AzionApplicationOptions) error
EnvLoader func(path string) ([]string, error)
Stat func(path string) (fs.FileInfo, error)
VersionID func() string
GetWorkDir func() (string, error)
f *cmdutil.Factory
}
Expand Down Expand Up @@ -82,7 +81,6 @@ func NewBuildCmd(f *cmdutil.Factory) *BuildCmd {
Stat: os.Stat,
GetWorkDir: utils.GetWorkingDir,
f: f,
VersionID: utils.Timestamp,
}
}

Expand Down
46 changes: 1 addition & 45 deletions pkg/cmd/build/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
msg "github.com/aziontech/azion-cli/messages/build"
"github.com/aziontech/azion-cli/pkg/contracts"
"github.com/aziontech/azion-cli/pkg/logger"
"github.com/aziontech/azion-cli/utils"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -65,49 +64,6 @@ func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo) error {
vulcanParams += " --firewall "
}

err = checkArgsJson(cmd)
if err != nil {
return err
}

if conf.Preset == "simple" {
logger.FInfo(cmd.Io.Out, msg.BuildSimple)
return nil
}

if conf.Preset == "static" {
versionID := cmd.VersionID()
conf.Prefix = versionID

err = cmd.WriteAzionJsonContent(conf)
if err != nil {
return nil
}
logger.FInfo(cmd.Io.Out, msg.BuildSimple)
return nil
}

if conf.Preset != "nextjs" {
return vulcan(cmd, conf, vulcanParams)
}
return vulcan(cmd, conf, vulcanParams)

return utils.ErrorUnsupportedType
}

func checkArgsJson(cmd *BuildCmd) error {
workingDir, err := cmd.GetWorkDir()
if err != nil {
return err
}

workDirPath := workingDir + "/azion/args.json"
_, err = cmd.FileReader(workDirPath)
if err != nil {
if err := cmd.WriteFile(workDirPath, []byte("{}"), 0644); err != nil {
logger.Debug("Error while trying to create args.json file", zap.Error(err))
return fmt.Errorf(utils.ErrorCreateFile.Error(), workDirPath)
}
}

return nil
}
4 changes: 0 additions & 4 deletions pkg/cmd/build/vulcan.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func vulcan(cmd *BuildCmd, conf *contracts.AzionApplicationOptions, vulcanParams
return fmt.Errorf(msg.ErrorVulcanExecute.Error(), err.Error())
}

versionID := cmd.VersionID()

conf.Prefix = versionID

err = cmd.WriteAzionJsonContent(conf)
if err != nil {
logger.Debug("Error while writing azion.json file", zap.Error(err))
Expand Down
19 changes: 15 additions & 4 deletions pkg/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type DeployCmd struct {
F *cmdutil.Factory
Unmarshal func(data []byte, v interface{}) error
Interpreter func() *manifestInt.ManifestInterpreter
VersionID func() string
}

var (
Expand All @@ -63,6 +64,7 @@ func NewDeployCmd(f *cmdutil.Factory) *DeployCmd {
Unmarshal: json.Unmarshal,
F: f,
Interpreter: manifestInt.NewManifestInterpreter,
VersionID: utils.Timestamp,
}
}

Expand All @@ -74,10 +76,10 @@ func NewCobraCmd(deploy *DeployCmd) *cobra.Command {
SilenceUsage: true,
SilenceErrors: true,
Example: heredoc.Doc(`
$ azion deploy --help
$ azion deploy --path dist/storage
$ azion deploy --auto
`),
$ azion deploy --help
$ azion deploy --path dist/storage
$ azion deploy --auto
`),
RunE: func(cmd *cobra.Command, args []string) error {
return deploy.Run(deploy.F)
},
Expand Down Expand Up @@ -118,6 +120,15 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error {
return err
}

versionID := cmd.VersionID()

conf.Prefix = versionID

err = checkArgsJson(cmd)
if err != nil {
return err
}

clients := NewClients(f)
interpreter := cmd.Interpreter()

Expand Down
18 changes: 18 additions & 0 deletions pkg/cmd/deploy/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,21 @@ func checkToken(f *cmdutil.Factory) error {

return nil
}

func checkArgsJson(cmd *DeployCmd) error {
workingDir, err := cmd.GetWorkDir()
if err != nil {
return err
}

workDirPath := workingDir + "/azion/args.json"
_, err = cmd.FileReader(workDirPath)
if err != nil {
if err := cmd.WriteFile(workDirPath, []byte("{}"), 0644); err != nil {
logger.Debug("Error while trying to create args.json file", zap.Error(err))
return fmt.Errorf(utils.ErrorCreateFile.Error(), workDirPath)
}
}

return nil
}
5 changes: 0 additions & 5 deletions pkg/cmd/edge_functions_instances/create/.fixtures/create.json

This file was deleted.

9 changes: 0 additions & 9 deletions pkg/cmd/edge_functions_instances/create/.fixtures/resp.json

This file was deleted.

84 changes: 0 additions & 84 deletions pkg/cmd/edge_functions_instances/create/create.go

This file was deleted.

90 changes: 0 additions & 90 deletions pkg/cmd/edge_functions_instances/create/create_test.go

This file was deleted.

Loading

0 comments on commit 29e5dfe

Please sign in to comment.