Skip to content

Commit

Permalink
Merge branch 'main' into eric-show-CanIUse-error-text
Browse files Browse the repository at this point in the history
  • Loading branch information
lionello authored Dec 20, 2024
2 parents 2c04c8c + 978167d commit 74ade2c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
26 changes: 13 additions & 13 deletions src/pkg/cli/client/byoc/aws/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ type ByocAws struct {

ecsEventHandlers []ECSEventHandler
handlersLock sync.RWMutex
lastCdEtag types.ETag
lastCdStart time.Time
lastCdTaskArn ecs.TaskArn
cdEtag types.ETag
cdStart time.Time
cdTaskArn ecs.TaskArn
}

var _ client.Provider = (*ByocAws)(nil)
Expand Down Expand Up @@ -270,9 +270,9 @@ func (b *ByocAws) deploy(ctx context.Context, req *defangv1.DeployRequest, cmd s
if err != nil {
return nil, err
}
b.lastCdEtag = etag
b.lastCdStart = time.Now()
b.lastCdTaskArn = taskArn
b.cdEtag = etag
b.cdStart = time.Now()
b.cdTaskArn = taskArn

for _, si := range serviceInfos {
if si.UseAcmeCert {
Expand Down Expand Up @@ -533,9 +533,9 @@ func (b *ByocAws) Delete(ctx context.Context, req *defangv1.DeleteRequest) (*def
return nil, AnnotateAwsError(err)
}
etag := ecs.GetTaskID(taskArn) // TODO: this is the CD task ID, not the etag
b.lastCdEtag = etag
b.lastCdStart = time.Now()
b.lastCdTaskArn = taskArn
b.cdEtag = etag
b.cdStart = time.Now()
b.cdTaskArn = taskArn
return &defangv1.DeleteResponse{Etag: etag}, nil
}

Expand Down Expand Up @@ -664,7 +664,7 @@ func (b *ByocAws) Query(ctx context.Context, req *defangv1.DebugRequest) error {
service = req.Services[0]
}

since := b.lastCdStart // TODO: get start time from req.Etag
since := b.cdStart // TODO: get start time from req.Etag
if since.IsZero() {
since = time.Now().Add(-time.Hour)
}
Expand Down Expand Up @@ -737,7 +737,7 @@ func (b *ByocAws) Follow(ctx context.Context, req *defangv1.TailRequest) (client
service = req.Services[0]
}
eventStream, err = ecs.TailLogGroups(ctx, req.Since.AsTime(), b.getLogGroupInputs(etag, req.Project, service, logType)...)
taskArn = b.lastCdTaskArn
taskArn = b.cdTaskArn
}
if err != nil {
return nil, AnnotateAwsError(err)
Expand Down Expand Up @@ -772,8 +772,8 @@ func (b *ByocAws) getLogGroupInputs(etag types.ETag, projectName string, service
if logType.Has(logs.LogTypeBuild) {
cdTail := ecs.LogGroupInput{LogGroupARN: b.driver.LogGroupARN} // TODO: filter by etag
// If we know the CD task ARN, only tail the logstream for that CD task
if b.lastCdTaskArn != nil && b.lastCdEtag == etag {
cdTail.LogStreamNames = []string{ecs.GetCDLogStreamForTaskID(ecs.GetTaskID(b.lastCdTaskArn))}
if b.cdTaskArn != nil && b.cdEtag == etag {
cdTail.LogStreamNames = []string{ecs.GetCDLogStreamForTaskID(ecs.GetTaskID(b.cdTaskArn))}
}
groups = append(groups, cdTail)
term.Debug("Query CD logs", cdTail.LogGroupARN, cdTail.LogStreamNames)
Expand Down
34 changes: 17 additions & 17 deletions src/pkg/cli/client/byoc/do/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ var (
type ByocDo struct {
*byoc.ByocBaseClient

buildRepo string
client *godo.Client
driver *appPlatform.DoApp
lastCdAppID string
lastCdDeploymentID string
lastCdEtag types.ETag
// lastCdStart time.Time
buildRepo string
client *godo.Client
driver *appPlatform.DoApp
cdAppID string
cdDeploymentID string
cdEtag types.ETag
// cdStart time.Time
}

var _ client.Provider = (*ByocDo)(nil)
Expand Down Expand Up @@ -208,7 +208,7 @@ func (b *ByocDo) deploy(ctx context.Context, req *defangv1.DeployRequest, cmd st
return nil, err
}

b.lastCdEtag = etag
b.cdEtag = etag
return &defangv1.DeployResponse{
Services: serviceInfos,
Etag: etag,
Expand All @@ -226,7 +226,7 @@ func (b *ByocDo) BootstrapCommand(ctx context.Context, req client.BootstrapComma
}

etag := pkg.RandomID()
b.lastCdEtag = etag
b.cdEtag = etag
return etag, nil
}

Expand Down Expand Up @@ -376,10 +376,10 @@ func (b *ByocDo) PutConfig(ctx context.Context, config *defangv1.PutConfigReques
func (b *ByocDo) Follow(ctx context.Context, req *defangv1.TailRequest) (client.ServerStream[defangv1.TailResponse], error) {
var appID, deploymentID string

if req.Etag != "" && req.Etag == b.lastCdEtag {
if req.Etag != "" && req.Etag == b.cdEtag {
// Use the last known app and deployment ID from the last CD command
appID = b.lastCdAppID
deploymentID = b.lastCdDeploymentID
appID = b.cdAppID
deploymentID = b.cdDeploymentID
}

if deploymentID == "" || appID == "" {
Expand Down Expand Up @@ -515,14 +515,14 @@ func (i DoAccountInfo) Details() string {
}

func (b *ByocDo) Subscribe(ctx context.Context, req *defangv1.SubscribeRequest) (client.ServerStream[defangv1.SubscribeResponse], error) {
if req.Etag != b.lastCdEtag || b.lastCdAppID == "" {
if req.Etag != b.cdEtag || b.cdAppID == "" {
return nil, errors.ErrUnsupported // TODO: fetch the deployment ID for the given etag
}
ctx, cancel := context.WithCancel(ctx) // canceled by subscribeStream.Close()
return &subscribeStream{
appID: b.lastCdAppID,
appID: b.cdAppID,
b: b,
deploymentID: b.lastCdDeploymentID,
deploymentID: b.cdDeploymentID,
ctx: ctx,
cancel: cancel,
queue: make(chan *defangv1.SubscribeResponse, 10),
Expand Down Expand Up @@ -627,8 +627,8 @@ func (b *ByocDo) runCdCommand(ctx context.Context, projectName, delegateDomain s
return nil, err
}

b.lastCdAppID = app.ID
b.lastCdDeploymentID = app.PendingDeployment.ID
b.cdAppID = app.ID
b.cdDeploymentID = app.PendingDeployment.ID
return app, nil
}

Expand Down
22 changes: 11 additions & 11 deletions src/pkg/cli/client/byoc/gcp/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ type ByocGcp struct {
uploadServiceAccount string
delegateDomainZone string

lastCdExecution string
lastCdEtag string
cdExecution string
cdEtag string
}

func NewByocProvider(ctx context.Context, tenantName types.TenantName) *ByocGcp {
Expand Down Expand Up @@ -337,7 +337,7 @@ func (b *ByocGcp) runCdCommand(ctx context.Context, cmd cdCommand) (string, erro
if err != nil {
return "", err
}
b.lastCdExecution = execution
b.cdExecution = execution
// fmt.Printf("CD Execution: %s\n", execution)
return execution, nil
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func (b *ByocGcp) deploy(ctx context.Context, req *defangv1.DeployRequest, comma
return nil, err
}

b.lastCdEtag = etag
b.cdEtag = etag
if command == "preview" {
etag = execution // Only wait for the preview command cd job to finish
}
Expand Down Expand Up @@ -477,8 +477,8 @@ func (b *ByocGcp) Subscribe(ctx context.Context, req *defangv1.SubscribeRequest)
if err != nil {
return nil, err
}
if req.Etag == b.lastCdEtag {
ss.AddJobExecutionUpdate(path.Base(b.lastCdExecution))
if req.Etag == b.cdEtag {
ss.AddJobExecutionUpdate(path.Base(b.cdExecution))
}
ss.AddJobStatusUpdate(req.Project, req.Etag, req.Services)
ss.AddServiceStatusUpdate(req.Project, req.Etag, req.Services)
Expand All @@ -489,12 +489,12 @@ func (b *ByocGcp) Subscribe(ctx context.Context, req *defangv1.SubscribeRequest)
}

func (b *ByocGcp) Follow(ctx context.Context, req *defangv1.TailRequest) (client.ServerStream[defangv1.TailResponse], error) {
if req.Etag == b.lastCdExecution { // Only follow CD log, we need to subscribe to cd activities to detect when the job is done
if req.Etag == b.cdExecution { // Only follow CD log, we need to subscribe to cd activities to detect when the job is done
ss, err := NewSubscribeStream(ctx, b.driver)
if err != nil {
return nil, err
}
ss.AddJobExecutionUpdate(path.Base(b.lastCdExecution))
ss.AddJobExecutionUpdate(path.Base(b.cdExecution))
if err := ss.Start(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -524,11 +524,11 @@ func (b *ByocGcp) Follow(ctx context.Context, req *defangv1.TailRequest) (client
if err != nil {
return nil, err
}
if req.Etag == b.lastCdEtag || req.Etag == b.lastCdExecution {
ls.AddJobExecutionLog(path.Base(b.lastCdExecution), req.Since.AsTime()) // CD log
if req.Etag == b.cdEtag || req.Etag == b.cdExecution {
ls.AddJobExecutionLog(path.Base(b.cdExecution), req.Since.AsTime()) // CD log
}

if req.Etag != b.lastCdExecution { // No need to tail kaniko and service log if there is only cd running
if req.Etag != b.cdExecution { // No need to tail kaniko and service log if there is only cd running
ls.AddJobLog(req.Project, req.Etag, req.Services, req.Since.AsTime()) // Kaniko logs
ls.AddServiceLog(req.Project, req.Etag, req.Services, req.Since.AsTime()) // Service logs
}
Expand Down

0 comments on commit 74ade2c

Please sign in to comment.