@@ -20,6 +20,7 @@ import (
20
20
"github.com/DefangLabs/defang/src/pkg/clouds/aws/ecs"
21
21
"github.com/DefangLabs/defang/src/pkg/clouds/aws/ecs/cfn"
22
22
"github.com/DefangLabs/defang/src/pkg/http"
23
+ "github.com/DefangLabs/defang/src/pkg/quota"
23
24
"github.com/DefangLabs/defang/src/pkg/term"
24
25
"github.com/DefangLabs/defang/src/pkg/types"
25
26
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
@@ -31,6 +32,8 @@ import (
31
32
"github.com/aws/aws-sdk-go-v2/service/sts"
32
33
"github.com/aws/smithy-go/ptr"
33
34
"github.com/bufbuild/connect-go"
35
+ "github.com/compose-spec/compose-go/v2/loader"
36
+ compose "github.com/compose-spec/compose-go/v2/types"
34
37
"google.golang.org/protobuf/proto"
35
38
)
36
39
@@ -116,12 +119,18 @@ func (b *ByocAws) Deploy(ctx context.Context, req *defangv1.DeployRequest) (*def
116
119
return nil , err
117
120
}
118
121
122
+ p , err := loader .LoadWithContext (ctx , compose.ConfigDetails {ConfigFiles : []compose.ConfigFile {{Content : []byte (req .Compose )}}})
123
+ if err != nil {
124
+ return nil , err
125
+ }
126
+
119
127
etag := pkg .RandomID ()
120
- if len (req .Services ) > b .Quota .Services {
128
+ if len (p .Services ) > b .Quota .Services {
121
129
return nil , errors .New ("maximum number of services reached" )
122
130
}
131
+
123
132
serviceInfos := []* defangv1.ServiceInfo {}
124
- for _ , service := range req .Services {
133
+ for _ , service := range p .Services {
125
134
serviceInfo , err := b .update (ctx , service )
126
135
if err != nil {
127
136
return nil , err
@@ -185,7 +194,7 @@ func (b *ByocAws) Deploy(ctx context.Context, req *defangv1.DeployRequest) (*def
185
194
186
195
for _ , si := range serviceInfos {
187
196
if si .UseAcmeCert {
188
- term .Infof ("To activate TLS certificate for %v, run 'defang cert gen'" , si .Service .Domainname )
197
+ term .Infof ("To activate TLS certificate for %v, run 'defang cert gen'" , si .Service .Name )
189
198
}
190
199
}
191
200
@@ -504,35 +513,38 @@ func (b *ByocAws) Tail(ctx context.Context, req *defangv1.TailRequest) (client.S
504
513
}
505
514
506
515
// This function was copied from Fabric controller and slightly modified to work with BYOC
507
- func (b * ByocAws ) update (ctx context.Context , service * defangv1. Service ) (* defangv1.ServiceInfo , error ) {
508
- if err := b .Quota .Validate (service ); err != nil {
516
+ func (b * ByocAws ) update (ctx context.Context , service compose. ServiceConfig ) (* defangv1.ServiceInfo , error ) {
517
+ if err := b .Quota .Validate (& service ); err != nil {
509
518
return nil , err
510
519
}
511
520
512
- // Check to make sure all required secrets are present in the secrets store
513
- missing , err := b .checkForMissingSecrets (ctx , service .Secrets )
521
+ // Check to make sure all required configs are present in the configs store
522
+ var configs []string
523
+ for config , value := range service .Environment {
524
+ if value == nil {
525
+ configs = append (configs , config )
526
+ }
527
+ }
528
+ err := b .checkForMissingSecrets (ctx , configs )
514
529
if err != nil {
515
530
return nil , err
516
531
}
517
- if missing != nil {
518
- return nil , fmt .Errorf ("missing config %q" , missing ) // retryable CodeFailedPrecondition
519
- }
520
532
521
533
ensure (b .PulumiProject != "" , "pulumiProject not set" )
522
534
si := & defangv1.ServiceInfo {
523
- Service : service ,
535
+ Service : & defangv1. ServiceID { Name : service . Name } ,
524
536
Project : b .PulumiProject , // was: tenant
525
537
Etag : pkg .RandomID (), // TODO: could be hash for dedup/idempotency
526
538
}
527
539
528
540
hasHost := false
529
541
hasIngress := false
530
542
fqn := service .Name
531
- if service .StaticFiles == nil {
543
+ if sf := service .Extensions [ "x-defang-static-files" ]; sf == nil {
532
544
for _ , port := range service .Ports {
533
- hasIngress = hasIngress || port .Mode == defangv1 .Mode_INGRESS
534
- hasHost = hasHost || port .Mode == defangv1 .Mode_HOST
535
- si .Endpoints = append (si .Endpoints , b .getEndpoint (fqn , port ))
545
+ hasIngress = hasIngress || port .Mode == quota .Mode_INGRESS
546
+ hasHost = hasHost || port .Mode == quota .Mode_HOST
547
+ si .Endpoints = append (si .Endpoints , b .getEndpoint (fqn , & port ))
536
548
}
537
549
} else {
538
550
si .PublicFqdn = b .getPublicFqdn (fqn )
@@ -546,14 +558,15 @@ func (b *ByocAws) update(ctx context.Context, service *defangv1.Service) (*defan
546
558
si .PrivateFqdn = b .getPrivateFqdn (fqn )
547
559
}
548
560
549
- if service .Domainname != "" {
550
- if ! hasIngress && service .StaticFiles == nil {
561
+ if service .DomainName != "" {
562
+ if ! hasIngress && service .Extensions [ "x-defang-static-files" ] == nil {
551
563
return nil , errors .New ("domainname requires at least one ingress port" ) // retryable CodeFailedPrecondition
552
564
}
553
- // Do a DNS lookup for Domainname and confirm it's indeed a CNAME to the service's public FQDN
554
- cname , _ := net .LookupCNAME (service .Domainname )
565
+ // Do a DNS lookup for DomainName and confirm it's indeed a CNAME to the service's public FQDN
566
+ cname , _ := net .LookupCNAME (service .DomainName )
555
567
if strings .TrimSuffix (cname , "." ) != si .PublicFqdn {
556
- zoneId , err := b .findZone (ctx , service .Domainname , service .DnsRole )
568
+ dnsRole , _ := service .Extensions ["x-defang-dns-role" ].(string )
569
+ zoneId , err := b .findZone (ctx , service .DomainName , dnsRole )
557
570
if err != nil {
558
571
return nil , err
559
572
}
@@ -569,29 +582,29 @@ func (b *ByocAws) update(ctx context.Context, service *defangv1.Service) (*defan
569
582
570
583
si .NatIps = b .publicNatIps // TODO: even internal services use NAT now
571
584
si .Status = "UPDATE_QUEUED"
572
- if si . Service .Build != nil {
585
+ if service .Build != nil {
573
586
si .Status = "BUILD_QUEUED" // in SaaS, this gets overwritten by the ECS events for "kaniko"
574
587
}
575
588
return si , nil
576
589
}
577
590
578
591
// This function was copied from Fabric controller and slightly modified to work with BYOC
579
- func (b * ByocAws ) checkForMissingSecrets (ctx context.Context , secrets []* defangv1. Secret ) ( * defangv1. Secret , error ) {
592
+ func (b * ByocAws ) checkForMissingSecrets (ctx context.Context , secrets []string ) error {
580
593
if len (secrets ) == 0 {
581
- return nil , nil // no secrets to check
594
+ return nil // no secrets to check
582
595
}
583
596
prefix := b .getSecretID ("" )
584
597
sorted , err := b .driver .ListSecretsByPrefix (ctx , prefix )
585
598
if err != nil {
586
- return nil , err
599
+ return err
587
600
}
588
601
for _ , secret := range secrets {
589
- fqn := b .getSecretID (secret . Source )
602
+ fqn := b .getSecretID (secret )
590
603
if ! searchSecret (sorted , fqn ) {
591
- return secret , nil // secret not found
604
+ return fmt . Errorf ( "missing config %q" , secret )
592
605
}
593
606
}
594
- return nil , nil // all secrets found
607
+ return nil // all secrets found
595
608
}
596
609
597
610
// This function was copied from Fabric controller
@@ -605,8 +618,8 @@ func searchSecret(sorted []qualifiedName, fqn qualifiedName) bool {
605
618
type qualifiedName = string // legacy
606
619
607
620
// This function was copied from Fabric controller and slightly modified to work with BYOC
608
- func (b * ByocAws ) getEndpoint (fqn qualifiedName , port * defangv1. Port ) string {
609
- if port .Mode == defangv1 .Mode_HOST {
621
+ func (b * ByocAws ) getEndpoint (fqn qualifiedName , port * compose. ServicePortConfig ) string {
622
+ if port .Mode == quota .Mode_HOST {
610
623
privateFqdn := b .getPrivateFqdn (fqn )
611
624
return fmt .Sprintf ("%s:%d" , privateFqdn , port .Target )
612
625
}
@@ -675,8 +688,8 @@ func (b *ByocAws) DeleteConfig(ctx context.Context, secrets *defangv1.Secrets) e
675
688
return nil
676
689
}
677
690
678
- func (b * ByocAws ) Restart (ctx context.Context , names ... string ) (types. ETag , error ) {
679
- return "" , client .ErrNotImplemented ("not yet implemented for BYOC; please use the AWS ECS dashboard" ) // FIXME: implement this for BYOC
691
+ func (b * ByocAws ) Restart (ctx context.Context , names ... string ) error {
692
+ return client .ErrNotImplemented ("not yet implemented for BYOC; please use the AWS ECS dashboard" ) // FIXME: implement this for BYOC
680
693
}
681
694
682
695
func (b * ByocAws ) BootstrapList (ctx context.Context ) ([]string , error ) {
0 commit comments