Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/pkg/cli/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func CdCommand(ctx context.Context, projectName string, provider client.Provider
}
}

etag, err := provider.CdCommand(ctx, client.CdCommandRequest{Project: projectName, Command: command, StatesUrl: statesUrl, EventsUrl: eventsUrl})
if err != nil || etag == "" {
cd, err := provider.CdCommand(ctx, client.CdCommandRequest{Project: projectName, Command: command, StatesUrl: statesUrl, EventsUrl: eventsUrl})
if err != nil || cd == nil || cd.ETag == "" {
return "", err
}
Comment thread
lionello marked this conversation as resolved.

Expand All @@ -57,17 +57,19 @@ func CdCommand(ctx context.Context, projectName string, provider client.Provider
case client.CdCommandRefresh:
err := putDeploymentAndStack(ctx, provider, fabric, nil, putDeploymentParams{
Action: action,
ETag: etag,
CdId: cd.CdId,
CdType: cd.CdType,
ETag: cd.ETag,
EventsUrl: eventsUrl,
ProjectName: projectName,
StatesUrl: statesUrl,
EventsUrl: eventsUrl,
})
if err != nil {
term.Debug("Failed to record deployment:", err)
term.Warn("Unable to update deployment history; deployment will proceed anyway.")
}
}
return etag, nil
return cd.ETag, nil
}

func deleteSubdomain(ctx context.Context, projectName string, provider client.Provider, fabric client.FabricClient) error {
Expand Down
24 changes: 14 additions & 10 deletions src/pkg/cli/client/byoc/aws/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ func (b *ByocAws) GetDeploymentStatus(ctx context.Context) (bool, error) {
return done, nil
}

func (b *ByocAws) Deploy(ctx context.Context, req *client.DeployRequest) (*defangv1.DeployResponse, error) {
func (b *ByocAws) Deploy(ctx context.Context, req *client.DeployRequest) (*client.DeployResponse, error) {
return b.deploy(ctx, req, "up")
}

func (b *ByocAws) Preview(ctx context.Context, req *client.DeployRequest) (*defangv1.DeployResponse, error) {
func (b *ByocAws) Preview(ctx context.Context, req *client.DeployRequest) (*client.DeployResponse, error) {
return b.deploy(ctx, req, "preview")
}

func (b *ByocAws) deploy(ctx context.Context, req *client.DeployRequest, cmd string) (*defangv1.DeployResponse, error) {
func (b *ByocAws) deploy(ctx context.Context, req *client.DeployRequest, cmd string) (*client.DeployResponse, error) {
cfg, err := b.driver.LoadConfig(ctx)
if err != nil {
return nil, AnnotateAwsError(err)
Expand Down Expand Up @@ -292,9 +292,13 @@ func (b *ByocAws) deploy(ctx context.Context, req *client.DeployRequest, cmd str
}
}

return &defangv1.DeployResponse{
Services: serviceInfos, // TODO: Should we use the retrieved services instead?
Etag: etag,
return &client.DeployResponse{
CdType: defangv1.CdType_CD_TYPE_AWS_CODEBUILD_BUILDID,
CdId: *cdBuildId,
DeployResponse: &defangv1.DeployResponse{
Services: serviceInfos, // TODO: Should we use the retrieved services instead?
Etag: etag,
},
}, nil
Comment thread
lionello marked this conversation as resolved.
}

Expand Down Expand Up @@ -902,9 +906,9 @@ func (b *ByocAws) TearDownCD(ctx context.Context) error {
return b.driver.TearDown(ctx)
}

func (b *ByocAws) CdCommand(ctx context.Context, req client.CdCommandRequest) (string, error) {
func (b *ByocAws) CdCommand(ctx context.Context, req client.CdCommandRequest) (*client.CdCommandResponse, error) {
if err := b.SetUpCD(ctx, false); err != nil {
return "", err
return nil, err
}
etag := types.NewEtag()
cmd := cdCommand{
Expand All @@ -916,12 +920,12 @@ func (b *ByocAws) CdCommand(ctx context.Context, req client.CdCommandRequest) (s
}
cdBuildId, err := b.runCdCommand(ctx, cmd)
if err != nil {
return "", AnnotateAwsError(err)
return nil, AnnotateAwsError(err)
}
b.cdEtag = etag
b.cdStart = time.Now()
b.cdBuildId = cdBuildId
return etag, nil
return &client.CdCommandResponse{ETag: etag, CdType: defangv1.CdType_CD_TYPE_AWS_CODEBUILD_BUILDID, CdId: *cdBuildId}, nil
}

func (b *ByocAws) DeleteConfig(ctx context.Context, secrets *defangv1.Secrets) error {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/cli/client/byoc/baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (mp ErrMultipleProjects) Error() string {
}

type ProjectBackend interface {
CdCommand(context.Context, client.CdCommandRequest) (types.ETag, error)
CdCommand(context.Context, client.CdCommandRequest) (*client.CdCommandResponse, error)
CdList(context.Context, bool) (iter.Seq[state.Info], error)
GetPrivateDomain(projectName string) string
GetProjectUpdate(context.Context, string) (*defangv1.ProjectUpdate, error)
Expand Down
32 changes: 20 additions & 12 deletions src/pkg/cli/client/byoc/do/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ func (b *ByocDo) GetProjectUpdate(ctx context.Context, projectName string) (*def
return &projUpdate, nil
}

func (b *ByocDo) Preview(ctx context.Context, req *client.DeployRequest) (*defangv1.DeployResponse, error) {
func (b *ByocDo) Preview(ctx context.Context, req *client.DeployRequest) (*client.DeployResponse, error) {
return b.deploy(ctx, req, "preview")
}

func (b *ByocDo) Deploy(ctx context.Context, req *client.DeployRequest) (*defangv1.DeployResponse, error) {
func (b *ByocDo) Deploy(ctx context.Context, req *client.DeployRequest) (*client.DeployResponse, error) {
return b.deploy(ctx, req, "up")
}

func (b *ByocDo) deploy(ctx context.Context, req *client.DeployRequest, cmd string) (*defangv1.DeployResponse, error) {
func (b *ByocDo) deploy(ctx context.Context, req *client.DeployRequest, cmd string) (*client.DeployResponse, error) {
// If multiple Compose files were provided, req.Compose is the merged representation of all the files
project, err := compose.LoadFromContent(ctx, req.Compose, "")
if err != nil {
Expand Down Expand Up @@ -205,15 +205,19 @@ func (b *ByocDo) deploy(ctx context.Context, req *client.DeployRequest, cmd stri
statesUrl: req.StatesUrl,
eventsUrl: req.EventsUrl,
}
_, err = b.runCdCommand(ctx, cdCmd)
app, err := b.runCdCommand(ctx, cdCmd)
if err != nil {
return nil, err
}

b.cdEtag = etag
return &defangv1.DeployResponse{
Services: serviceInfos,
Etag: etag,
return &client.DeployResponse{
DeployResponse: &defangv1.DeployResponse{
Services: serviceInfos,
Etag: etag,
},
CdType: defangv1.CdType_CD_TYPE_DO_APPPLATFORM_DEPLOYMENTID,
CdId: app.PendingDeployment.ID,
}, nil
}

Expand All @@ -233,9 +237,9 @@ func (b *ByocDo) GetDeploymentStatus(ctx context.Context) (bool, error) {
}
}

func (b *ByocDo) CdCommand(ctx context.Context, req client.CdCommandRequest) (string, error) {
func (b *ByocDo) CdCommand(ctx context.Context, req client.CdCommandRequest) (*client.CdCommandResponse, error) {
if err := b.SetUpCD(ctx, false); err != nil {
return "", err
return nil, err
}

etag := types.NewEtag()
Expand All @@ -247,13 +251,17 @@ func (b *ByocDo) CdCommand(ctx context.Context, req client.CdCommandRequest) (st
statesUrl: req.StatesUrl,
eventsUrl: req.EventsUrl,
}
_, err := b.runCdCommand(ctx, cmd)
app, err := b.runCdCommand(ctx, cmd)
if err != nil {
return "", err
return nil, err
}

b.cdEtag = etag
return etag, nil
return &client.CdCommandResponse{
CdType: defangv1.CdType_CD_TYPE_DO_APPPLATFORM_DEPLOYMENTID,
CdId: app.PendingDeployment.ID,
ETag: etag,
}, nil
}

func (b *ByocDo) CdList(ctx context.Context, _allRegions bool) (iter.Seq[state.Info], error) {
Expand Down
49 changes: 29 additions & 20 deletions src/pkg/cli/client/byoc/gcp/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type ByocGcp struct {
uploadServiceAccount string
delegateDomainZone string

cdExecution string
cdBuildId string
}

func NewByocProvider(ctx context.Context, tenantName types.TenantLabel, stack string) *ByocGcp {
Expand Down Expand Up @@ -373,9 +373,9 @@ func (b *ByocGcp) AccountInfo(ctx context.Context) (*client.AccountInfo, error)
}, nil
}

func (b *ByocGcp) CdCommand(ctx context.Context, req client.CdCommandRequest) (types.ETag, error) {
func (b *ByocGcp) CdCommand(ctx context.Context, req client.CdCommandRequest) (*client.CdCommandResponse, error) {
if err := b.SetUpCD(ctx, false); err != nil {
return "", err
return nil, err
}
etag := types.NewEtag()
cmd := cdCommand{
Expand All @@ -385,11 +385,15 @@ func (b *ByocGcp) CdCommand(ctx context.Context, req client.CdCommandRequest) (t
statesUrl: req.StatesUrl,
eventsUrl: req.EventsUrl,
}
err := b.runCdCommand(ctx, cmd) // TODO: make domain optional for defang cd
buildId, err := b.runCdCommand(ctx, cmd) // TODO: make domain optional for defang cd
if err != nil {
return "", err
return nil, err
}
return etag, nil
return &client.CdCommandResponse{
CdId: buildId,
CdType: defangv1.CdType_CD_TYPE_GCP_CLOUDBUILD_BUILDID,
ETag: etag,
}, nil
}

type cdCommand struct {
Expand All @@ -409,11 +413,11 @@ type CloudBuildStep struct {
Env []string `yaml:"env,omitempty"`
}

func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) error {
func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) (string, error) {
defangStateUrl := `gs://` + b.bucket
pulumiBackendKey, pulumiBackendValue, err := byoc.GetPulumiBackend(defangStateUrl)
if err != nil {
return err
return "", err
}
env := map[string]string{
"DEFANG_CD_IMAGE": b.CDImage, // used by down/destroy to schedule cleanup job with the same image
Expand Down Expand Up @@ -466,7 +470,7 @@ func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) error {
debugEnv = append(debugEnv, k+"="+v)
}
if err := byoc.DebugPulumiGolang(ctx, debugEnv, cmd.command...); err != nil {
return err
return "", err
}
}

Expand All @@ -483,10 +487,10 @@ func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) error {
},
})
if err != nil {
return err
return "", err
}
term.Debugf("Starting CD in cloudbuild at: %v", time.Now().Format(time.RFC3339))
execution, err := b.driver.RunCloudBuild(ctx, gcp.CloudBuildArgs{
buildId, err := b.driver.RunCloudBuild(ctx, gcp.CloudBuildArgs{
Steps: string(steps),
ServiceAccount: &b.cdServiceAccount,
Tags: []string{
Expand All @@ -495,11 +499,11 @@ func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) error {
},
})
if err != nil {
return err
return "", err
}
b.cdExecution = execution
b.cdBuildId = buildId

return nil
return buildId, nil
}

func (b *ByocGcp) CreateUploadURL(ctx context.Context, req *defangv1.UploadURLRequest) (*defangv1.UploadURLResponse, error) {
Expand All @@ -516,19 +520,19 @@ func (b *ByocGcp) CreateUploadURL(ctx context.Context, req *defangv1.UploadURLRe
}
return &defangv1.UploadURLResponse{Url: url}, nil
}
func (b *ByocGcp) Deploy(ctx context.Context, req *client.DeployRequest) (*defangv1.DeployResponse, error) {
func (b *ByocGcp) Deploy(ctx context.Context, req *client.DeployRequest) (*client.DeployResponse, error) {
return b.deploy(ctx, req, "up")
}

func (b *ByocGcp) Preview(ctx context.Context, req *client.DeployRequest) (*defangv1.DeployResponse, error) {
func (b *ByocGcp) Preview(ctx context.Context, req *client.DeployRequest) (*client.DeployResponse, error) {
return b.deploy(ctx, req, "preview")
}

func (b *ByocGcp) GetDeploymentStatus(ctx context.Context) (bool, error) {
return b.driver.GetBuildStatus(ctx, b.cdExecution)
return b.driver.GetBuildStatus(ctx, b.cdBuildId)
}

func (b *ByocGcp) deploy(ctx context.Context, req *client.DeployRequest, command string) (*defangv1.DeployResponse, error) {
func (b *ByocGcp) deploy(ctx context.Context, req *client.DeployRequest, command string) (*client.DeployResponse, error) {
// If multiple Compose files were provided, req.Compose is the merged representation of all the files
project, err := compose.LoadFromContent(ctx, req.Compose, "")
if err != nil {
Expand Down Expand Up @@ -590,11 +594,16 @@ func (b *ByocGcp) deploy(ctx context.Context, req *client.DeployRequest, command
statesUrl: req.StatesUrl,
eventsUrl: req.EventsUrl,
}
if err := b.runCdCommand(ctx, cdCmd); err != nil {
buildId, err := b.runCdCommand(ctx, cdCmd)
if err != nil {
return nil, err
}

return &defangv1.DeployResponse{Etag: etag, Services: serviceInfos}, nil
return &client.DeployResponse{
CdId: buildId,
CdType: defangv1.CdType_CD_TYPE_GCP_CLOUDBUILD_BUILDID,
DeployResponse: &defangv1.DeployResponse{Etag: etag, Services: serviceInfos},
}, nil
}

func (b *ByocGcp) Subscribe(ctx context.Context, req *defangv1.SubscribeRequest) (iter.Seq2[*defangv1.SubscribeResponse, error], error) {
Expand Down
12 changes: 6 additions & 6 deletions src/pkg/cli/client/byoc/gcp/byoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestSetUpCD(t *testing.T) {
command: []string{"up", payload},
}

if err := b.runCdCommand(ctx, cmd); err != nil {
if _, err := b.runCdCommand(ctx, cmd); err != nil {
t.Errorf("CdCommand() error = %v, want nil", err)
}
}
Expand Down Expand Up @@ -108,9 +108,9 @@ func (m *MockGcpLoggingTailer) Next(ctx context.Context) (*loggingpb.LogEntry, e

func TestGetLogStream(t *testing.T) {
tests := []struct {
name string
req *defangv1.TailRequest
cdExecution string
name string
req *defangv1.TailRequest
cdBuildId string
}{
// TODO: use golang 1.25 synctest to avoid needing a fixed Since in every test case
{name: "no_args", req: &defangv1.TailRequest{}},
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestGetLogStream(t *testing.T) {
LogType: uint32(logs.LogTypeAll),
Etag: "test-etag",
},
cdExecution: "test-execution-id",
cdBuildId: "test-execution-id",
},
}

Expand All @@ -173,7 +173,7 @@ func TestGetLogStream(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := NewByocProvider(ctx, "testTenantID", "")
b.cdExecution = tt.cdExecution
b.cdBuildId = tt.cdBuildId

driver := &MockGcpLogsClient{
lister: &MockGcpLoggingLister{},
Expand Down
17 changes: 11 additions & 6 deletions src/pkg/cli/client/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func (g *PlaygroundProvider) GetStackName() string {
return g.Stack
}

func (g *PlaygroundProvider) Deploy(ctx context.Context, req *DeployRequest) (*defangv1.DeployResponse, error) {
func (g *PlaygroundProvider) Deploy(ctx context.Context, req *DeployRequest) (*DeployResponse, error) {
if os.Getenv("DEFANG_PULUMI_DIR") != "" {
return nil, errors.New("DEFANG_PULUMI_DIR is set, but not supported by the Playground provider")
}
return getMsg(g.GetFabricClient().Deploy(ctx, connect.NewRequest(&req.DeployRequest)))
resp, err := getMsg(g.GetFabricClient().Deploy(ctx, connect.NewRequest(&req.DeployRequest)))
return &DeployResponse{DeployResponse: resp}, err
}

func (g *PlaygroundProvider) GetDeploymentStatus(ctx context.Context) (bool, error) {
Expand All @@ -54,7 +55,7 @@ func (*PlaygroundProvider) Driver() string {
return "playground"
}

func (g *PlaygroundProvider) Preview(ctx context.Context, req *DeployRequest) (*defangv1.DeployResponse, error) {
func (g *PlaygroundProvider) Preview(ctx context.Context, req *DeployRequest) (*DeployResponse, error) {
req.Preview = true
return g.Deploy(ctx, req)
}
Expand Down Expand Up @@ -125,11 +126,15 @@ func serverStreamIter[T any](stream ServerStream[T]) iter.Seq2[*T, error] {
}
}

func (g *PlaygroundProvider) CdCommand(ctx context.Context, req CdCommandRequest) (types.ETag, error) {
func (g *PlaygroundProvider) CdCommand(ctx context.Context, req CdCommandRequest) (*CdCommandResponse, error) {
if req.Command == CdCommandDestroy {
return g.destroy(ctx, &defangv1.DestroyRequest{Project: req.Project})
etag, err := g.destroy(ctx, &defangv1.DestroyRequest{Project: req.Project})
if err != nil {
return nil, err
}
return &CdCommandResponse{ETag: etag}, nil
}
return "", errors.New("the CD command is not valid for the Defang playground; did you forget --stack or --provider?")
return nil, errors.New("the CD command is not valid for the Defang playground; did you forget --stack or --provider?")
}

func (g *PlaygroundProvider) destroy(ctx context.Context, req *defangv1.DestroyRequest) (types.ETag, error) {
Expand Down
Loading
Loading