Skip to content

Commit

Permalink
Merge pull request #36 from zeropsio/deploySource
Browse files Browse the repository at this point in the history
add push --source argument
  • Loading branch information
jansaidl authored Jan 4, 2022
2 parents 09cc3f1 + 3901272 commit f902901
Show file tree
Hide file tree
Showing 8 changed files with 5,356 additions and 3,660 deletions.
1 change: 1 addition & 0 deletions src/cliAction/buildDeploy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {

type RunConfig struct {
ProjectName string
SourceName string
ServiceStackName string
PathsForPacking []string
WorkingDir string
Expand Down
11 changes: 1 addition & 10 deletions src/cliAction/buildDeploy/handler_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,8 @@ func (h *Handler) Deploy(ctx context.Context, config RunConfig) error {

fmt.Println(i18n.BuildDeployDeployingStart)

temporaryShutdown := false
if serviceStack.GetStatus() == zeropsApiProtocol.ServiceStackStatus_SERVICE_STACK_STATUS_READY_TO_DEPLOY ||
serviceStack.GetStatus() == zeropsApiProtocol.ServiceStackStatus_SERVICE_STACK_STATUS_ACTION_FAILED {
temporaryShutdown = true
}

fmt.Printf(i18n.BuildDeployTemporaryShutdown+"\n", temporaryShutdown)

deployResponse, err := h.apiGrpcClient.PutAppVersionDeploy(ctx, &zeropsApiProtocol.PutAppVersionDeployRequest{
Id: appVersion.GetId(),
TemporaryShutdown: temporaryShutdown,
Id: appVersion.GetId(),
})
if err := utils.HandleGrpcApiError(deployResponse, err); err != nil {
return err
Expand Down
11 changes: 9 additions & 2 deletions src/cliAction/buildDeploy/handler_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"fmt"
"io/ioutil"

"github.com/zerops-io/zcli/src/i18n"
"github.com/zerops-io/zcli/src/utils"
"github.com/zerops-io/zcli/src/zeropsApiProtocol"

"github.com/zerops-io/zcli/src/i18n"
)

func (h *Handler) Push(ctx context.Context, config RunConfig) error {
Expand All @@ -20,6 +19,10 @@ func (h *Handler) Push(ctx context.Context, config RunConfig) error {
return err
}

if config.SourceName == "" {
config.SourceName = serviceStack.GetName()
}

fmt.Println(i18n.BuildDeployCreatingPackageStart)

files, err := h.zipClient.FindGitFiles(config.WorkingDir)
Expand Down Expand Up @@ -80,6 +83,10 @@ func (h *Handler) Push(ctx context.Context, config RunConfig) error {
deployResponse, err := h.apiGrpcClient.PutAppVersionBuildAndDeploy(ctx, &zeropsApiProtocol.PutAppVersionBuildAndDeployRequest{
Id: appVersion.GetId(),
BuildConfigContent: base64.StdEncoding.EncodeToString(buildConfigContent),
Source: &zeropsApiProtocol.StringNull{
Value: config.SourceName,
Valid: true,
},
})
if err := utils.HandleGrpcApiError(deployResponse, err); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func pushCmd() *cobra.Command {
ZipFilePath: params.GetString(cmd, "zipFilePath"),
WorkingDir: params.GetString(cmd, "workingDir"),
VersionName: params.GetString(cmd, "versionName"),
SourceName: params.GetString(cmd, "source"),
ProjectName: args[0],
ServiceStackName: args[1],
})
Expand All @@ -68,6 +69,7 @@ func pushCmd() *cobra.Command {
params.RegisterString(cmd, "workingDir", "./", i18n.BuildWorkingDir)
params.RegisterString(cmd, "zipFilePath", "", i18n.BuildZipFilePath)
params.RegisterString(cmd, "versionName", "", i18n.BuildVersionName)
params.RegisterString(cmd, "source", "", i18n.SourceName)

return cmd
}
2 changes: 1 addition & 1 deletion src/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (

// flags description
BuildVersionName = "custom version name"
SourceName = "zerops.yml source service"
BuildWorkingDir = "working dir, all files path are relative to this directory"
BuildZipFilePath = "save final zip file"

Expand All @@ -44,7 +45,6 @@ const (
BuildDeployProjectNotFound = "project not found"
BuildDeployProjectsWithSameName = "there are multiple projects with same name"
BuildDeployServiceStatus = "service status: %s"
BuildDeployTemporaryShutdown = "temporaryShutdown: %t"
BuildDeployCreatingPackageStart = "creating package"
BuildDeployCreatingPackageDone = "package created"
BuildDeployPackageSavedInto = "package file saved into: %s"
Expand Down
11 changes: 5 additions & 6 deletions src/utils/grpcErrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package utils

import (
"errors"
"fmt"

"github.com/zerops-io/zcli/src/i18n"

"google.golang.org/grpc/codes"

"google.golang.org/grpc/status"

"github.com/zerops-io/zcli/src/zeropsApiProtocol"
"github.com/zerops-io/zcli/src/zeropsVpnProtocol"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func WithCustomTimeoutMessage(message string) HandleGrpcErrorOption {
Expand Down Expand Up @@ -50,7 +48,8 @@ func HandleGrpcApiError(
return err
}
if response.GetError().GetCode() != zeropsApiProtocol.ErrorCode_NO_ERROR {
return errors.New(response.GetError().GetMessage())

return errors.New(fmt.Sprintf("%s [%s]", response.GetError().GetMessage(), string(response.GetError().GetMeta())))
}

return nil
Expand Down
8,687 changes: 5,111 additions & 3,576 deletions src/zeropsApiProtocol/zeropsApiProtocol.pb.go

Large diffs are not rendered by default.

Loading

0 comments on commit f902901

Please sign in to comment.