Skip to content

Commit

Permalink
Merge pull request #851 from aziontech/dev
Browse files Browse the repository at this point in the history
Deploy to Production - 2024/06/19
  • Loading branch information
PatrickMenoti authored Jun 20, 2024
2 parents 7faefb2 + 639e110 commit c0c6d36
Show file tree
Hide file tree
Showing 52 changed files with 383 additions and 1,101 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ To download azion CLI through Homebrew, run:
brew install azion
``````

##### Test Azion CLI with docker
You can find the URL for each package in our Releases page https://github.com/aziontech/azion/releases
```sh
docker run -it --rm alpine:latest sh -c '
cd && \
wget https://github.com/aziontech/azion/releases/download/1.28.1/azion_1.28.1_linux_arm64.apk && \
apk add --allow-untrusted azion_1.28.1_linux_arm64.apk && \
azion version; \
exec sh'
```

## Building Locally

```sh
Expand Down
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
1 change: 1 addition & 0 deletions messages/build/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ var (
FlagPolyfill = "Use node polyfills in build"
FlagEntry = "Code entrypoint; (default: ./main.js)"
IsFirewall = "Indicates whether the function to be run is intended for the Edge Firewall"
ProjectConfFlag = "Relative path to where your custom azion.json and args.json files are stored"
)
1 change: 1 addition & 0 deletions messages/delete/edge_application/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var (
CascadeSuccess = "Remote resources deleted successfully"
FlagId = "Unique identifier of the Edge Application"
AskInput = "Enter the ID of the Edge Application you wish to delete:"
CONFDIRFLAG = "Relative path to where your custom azion.json and args.json files are stored"
)
70 changes: 36 additions & 34 deletions messages/deploy/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@ package deploy

var (
// deploy cmd
DeployUsage = "deploy"
DeployShortDescription = "Deploys an Edge Application"
DeployLongDescription = "Deploys an Edge Application"
DeploySuccessful = "Your Edge Application was deployed successfully\n"
SimpleDeploySuccessful = "Your simple Edge Application was deployed successfully\n"
DeployOutputDomainSuccess = "\nTo visualize your application access the Domain: %v\n"
EdgeApplicationDeployDomainHint = "You may now edit your Domain and add your own CNAMES. To do this you may run 'azion domain update' command and also configure your DNS\n"
DeployOutputCachePurge = "Domain cache was purged\n"
DeployOutputEdgeFunctionCreate = "Created Edge Function %v with ID %v\n"
DeployOutputEdgeFunctionUpdate = "Updated Edge Function %v with ID %v\n"
DeployOutputEdgeApplicationCreate = "Created Edge Application %v with ID %v\n"
DeployOutputEdgeApplicationUpdate = "Updated Edge Application %v with ID %v\n"
DeployOutputDomainCreate = "Created Domain %v with ID %v\n"
DeployOutputDomainUpdate = "Updated Domain %v with ID %v\n"
EdgeApplicationDeployPathFlag = "Path to where your static files are stored"
OriginsSuccessful = "Created Origin for Edge Application\n"
OriginsUpdateSuccessful = "Updated Origin for Edge Application %v with ID %v \n"
CacheSettingsSuccessful = "Created Cache Settings for Edge Application\n"
BucketSuccessful = "Created Bucket %s\n"
RulesEngineSuccessful = "Created Rules Engine for Edge Application\n"
DeployFlagHelp = "Displays more information about the deploy command"
DeployFlagAuto = "If sent, the entire flow of the command will be run without interruptions"
DeployFlagNoPrompt = "If sent, whenever the CLI would display an interactive prompt due to an error, it instead just returns the error"
DeployPropagation = "Your application is being deployed to all Azion Edge Locations and it might take a few minutes.\n"
UploadStart = "Uploading static files\n"
UploadSuccessful = "\nUpload completed successfully!\n"
BucketInUse = "This bucket's name is already in use, please try another one\n"
AppInUse = "This Edge Application's name is already in use, please try another one\n"
DomainInUse = "This domain's name is already in use, please try another one\n"
FuncInUse = "This Edge Function's name is already in use, please try another one\n"
FuncInstInUse = "This function instance's name is already in use, please try another one\n"
AskInputName = "Type the new name:"
ProjectNameMessage = "Using the same name as your project to create the bucket\n"
AskCreateCacheSettings = `Azion CLI offers to create the following Cache Settings specifications:
DeployUsage = "deploy"
DeployShortDescription = "Deploys an Edge Application"
DeployLongDescription = "Deploys an Edge Application"
DeploySuccessful = "Your Edge Application was deployed successfully\n"
SimpleDeploySuccessful = "Your simple Edge Application was deployed successfully\n"
DeployOutputDomainSuccess = "\nTo visualize your application access the Domain: %v\n"
EdgeApplicationDeployDomainHint = "You may now edit your Domain and add your own CNAMES. To do this you may run 'azion domain update' command and also configure your DNS\n"
DeployOutputCachePurge = "Domain cache was purged\n"
DeployOutputEdgeFunctionCreate = "Created Edge Function %v with ID %v\n"
DeployOutputEdgeFunctionUpdate = "Updated Edge Function %v with ID %v\n"
DeployOutputEdgeApplicationCreate = "Created Edge Application %v with ID %v\n"
DeployOutputEdgeApplicationUpdate = "Updated Edge Application %v with ID %v\n"
DeployOutputDomainCreate = "Created Domain %v with ID %v\n"
DeployOutputDomainUpdate = "Updated Domain %v with ID %v\n"
EdgeApplicationDeployPathFlag = "Path to where your static files are stored"
EdgeApplicationDeployProjectConfFlag = "Relative path to where your custom azion.json and args.json files are stored"
OriginsSuccessful = "Created Origin for Edge Application\n"
OriginsUpdateSuccessful = "Updated Origin for Edge Application %v with ID %v \n"
CacheSettingsSuccessful = "Created Cache Settings for Edge Application\n"
BucketSuccessful = "Created Bucket %s\n"
RulesEngineSuccessful = "Created Rules Engine for Edge Application\n"
DeployFlagHelp = "Displays more information about the deploy command"
DeployFlagAuto = "If sent, the entire flow of the command will be run without interruptions"
DeployFlagNoPrompt = "If sent, whenever the CLI would display an interactive prompt due to an error, it instead just returns the error"
DeployFlagSkipBuild = "If sent, the build command will not be called during the deploy process"
DeployPropagation = "Your application is being deployed to all Azion Edge Locations and it might take a few minutes.\n"
UploadStart = "Uploading static files\n"
UploadSuccessful = "\nUpload completed successfully!\n"
BucketInUse = "This bucket's name is already in use, please try another one\n"
AppInUse = "This Edge Application's name is already in use, please try another one\n"
DomainInUse = "This domain's name is already in use, please try another one\n"
FuncInUse = "This Edge Function's name is already in use, please try another one\n"
FuncInstInUse = "This function instance's name is already in use, please try another one\n"
AskInputName = "Type the new name:"
ProjectNameMessage = "Using the same name as your project to create the bucket\n"
AskCreateCacheSettings = `Azion CLI offers to create the following Cache Settings specifications:
- Browser Cache Settings: Override Cache Settings
- Maximum TTL for Browser Cache Settings (in seconds): 7200
- Edge Application Cache Settings: Override Cache Settings
Expand Down
3 changes: 2 additions & 1 deletion messages/link/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ var (
)

const (
FLAG_REMOTE = "Clones a remote repository to be linked to an Azion Edge Application"
FLAG_REMOTE = "Clones a remote repository to be linked to an Azion Edge Application"
FLAGPATHCONF = "Relative path to where your custom azion.json and args.json files are stored"
)
6 changes: 6 additions & 0 deletions messages/manifest/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ var (
ErrorCacheNotFound = errors.New("Could not find this cache setting")
ErrorFunctionNotFound = errors.New("Could not find this edge function")
ErrorOriginNotFound = errors.New("Could not find this origin")
ErrorCreateOrigin = errors.New("Failed to create the origin")
ErrorCreateCache = errors.New("Failed to create the cache setting")
ErrorCreateRule = errors.New("Failed to create the rule in Rules Engine")
ErrorUpdateOrigin = errors.New("Failed to update the origin")
ErrorUpdateCache = errors.New("Failed to update the cache setting")
ErrorUpdateRule = errors.New("Failed to update the rule in Rules Engine")
)
5 changes: 5 additions & 0 deletions messages/sync/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sync

var (
ERRORSYNC = "Failed to synchronize local resources with remote resources: %s"
)
10 changes: 10 additions & 0 deletions messages/sync/messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sync

const (
USAGE = "sync"
SHORTDESCRIPTION = "Synchronizes the local azion.json file with remote resources"
LONGDESCRIPTION = "Synchronizes your local file containing your existing application resources configuration with remote resources"
SYNCMESSAGERULE = "Adding out of sync rule '%s' to your azion.json file\n"
HELPFLAG = "Displays more information about the sync command"
CONFDIRFLAG = "Relative path to where your custom azion.json and args.json files are stored"
)
2 changes: 1 addition & 1 deletion pkg/api/rules_engine/rules_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Client) Create(ctx context.Context, edgeApplicationID int64, phase stri

if err != nil {
if httpResp != nil {
logger.Debug("Error while updating a Rules Engine", zap.Error(err))
logger.Debug("Error while creating a Rules Engine", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
Expand Down
14 changes: 8 additions & 6 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ type BuildCmd struct {
CommandRunInteractive func(f *cmdutil.Factory, comm string) error
CommandRunner func(f *cmdutil.Factory, comm string, envVars []string) (string, error)
FileReader func(path string) ([]byte, error)
ConfigRelativePath string
GetAzionJsonContent func() (*contracts.AzionApplicationOptions, error)
WriteAzionJsonContent func(conf *contracts.AzionApplicationOptions) error
GetAzionJsonContent func(pathConf string) (*contracts.AzionApplicationOptions, error)
WriteAzionJsonContent func(conf *contracts.AzionApplicationOptions, confPath string) 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 @@ -57,6 +55,7 @@ func NewCobraCmd(build *BuildCmd) *cobra.Command {
buildCmd.Flags().StringVar(&fields.NodePolyfills, "use-node-polyfills", "", msg.FlagPolyfill)
buildCmd.Flags().StringVar(&fields.OwnWorker, "use-own-worker", "", msg.FlagWorker)
buildCmd.Flags().BoolVar(&fields.IsFirewall, "firewall", false, msg.IsFirewall)
buildCmd.Flags().StringVar(&fields.ProjectPath, "config-dir", "azion", msg.ProjectConfFlag)

return buildCmd
}
Expand All @@ -74,18 +73,21 @@ func NewBuildCmd(f *cmdutil.Factory) *BuildCmd {
CommandRunner: func(f *cmdutil.Factory, comm string, envVars []string) (string, error) {
return utils.CommandRunInteractiveWithOutput(f, comm, envVars)
},
ConfigRelativePath: "/azion/config.json",
EnvLoader: utils.LoadEnvVarsFromFile,
GetAzionJsonContent: utils.GetAzionJsonContent,
WriteAzionJsonContent: utils.WriteAzionJsonContent,
WriteFile: os.WriteFile,
Stat: os.Stat,
GetWorkDir: utils.GetWorkingDir,
f: f,
VersionID: utils.Timestamp,
}
}

func (cmd *BuildCmd) Run(fields *contracts.BuildInfo) error {
return cmd.run(fields)
}

func (cmd *BuildCmd) ExternalRun(fields *contracts.BuildInfo, confPath string) error {
fields.ProjectPath = confPath
return cmd.run(fields)
}
48 changes: 2 additions & 46 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 All @@ -25,7 +24,7 @@ func (cmd *BuildCmd) run(fields *contracts.BuildInfo) error {
func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo) error {
var err error

conf, err := cmd.GetAzionJsonContent()
conf, err := cmd.GetAzionJsonContent(fields.ProjectPath)
if err != nil {
logger.Debug("Error while building your project", zap.Error(err))
return msg.ErrorBuilding
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, fields)

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
}
8 changes: 2 additions & 6 deletions pkg/cmd/build/vulcan.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.uber.org/zap"
)

func vulcan(cmd *BuildCmd, conf *contracts.AzionApplicationOptions, vulcanParams string) error {
func vulcan(cmd *BuildCmd, conf *contracts.AzionApplicationOptions, vulcanParams string, fields *contracts.BuildInfo) error {
// checking if vulcan major is correct
vulcanVer, err := cmd.CommandRunner(cmd.f, "npm show edge-functions version", []string{})
if err != nil {
Expand All @@ -31,11 +31,7 @@ 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)
err = cmd.WriteAzionJsonContent(conf, fields.ProjectPath)
if err != nil {
logger.Debug("Error while writing azion.json file", zap.Error(err))
return utils.ErrorWritingAzionJsonFile
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/delete/edge_application/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func (del *DeleteCmd) Cascade(ctx context.Context) error {
azionJson, err := del.GetAzion()
azionJson, err := del.GetAzion(ProjectConf)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return msg.ErrorMissingAzionJson
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/delete/edge_application/edge_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"go.uber.org/zap"
)

var ProjectConf string

type DeleteCmd struct {
Io *iostreams.IOStreams
GetAzion func() (*contracts.AzionApplicationOptions, error)
GetAzion func(confPath string) (*contracts.AzionApplicationOptions, error)
f *cmdutil.Factory
UpdateJson func(cmd *DeleteCmd) error
}
Expand Down Expand Up @@ -61,6 +63,7 @@ func NewCobraCmd(delete *DeleteCmd) *cobra.Command {
cmd.Flags().Int64Var(&application_id, "application-id", 0, msg.FlagId)
cmd.Flags().Bool("cascade", true, msg.CascadeFlag)
cmd.Flags().BoolP("help", "h", false, msg.HelpFlag)
cmd.Flags().StringVar(&ProjectConf, "config-dir", "azion", msg.CONFDIRFLAG)

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/delete/edge_application/edge_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestCreate(t *testing.T) {
f, stdout, _ := testutils.NewFactory(mock)

del := NewDeleteCmd(f)
del.GetAzion = func() (*contracts.AzionApplicationOptions, error) {
del.GetAzion = func(confPath string) (*contracts.AzionApplicationOptions, error) {
return options, nil
}
del.UpdateJson = func(cmd *DeleteCmd) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/deploy/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (cmd *DeployCmd) doBucket(client *api.Client, ctx context.Context, conf *co
}

logger.FInfo(cmd.Io.Out, fmt.Sprintf(msg.BucketSuccessful, conf.Bucket))
return cmd.WriteAzionJsonContent(conf)
return cmd.WriteAzionJsonContent(conf, ProjectConf)
}

func askForInput(msg string, defaultIn string) (string, error) {
Expand Down
Loading

0 comments on commit c0c6d36

Please sign in to comment.