@@ -141,10 +141,13 @@ func (b *ByocAws) setUp(ctx context.Context) error {
141
141
if b .customDomain == "" {
142
142
domain , err := b .GetDelegateSubdomainZone (ctx )
143
143
if err != nil {
144
+ term .Debug (" - Failed to get subdomain zone:" , err )
144
145
// return err; FIXME: ignore this error for now
145
146
} else {
146
147
b .customDomain = b .getProjectDomain (domain .Zone )
147
- b .shouldDelegateSubdomain = true
148
+ if b .customDomain != "" {
149
+ b .shouldDelegateSubdomain = true
150
+ }
148
151
}
149
152
}
150
153
@@ -326,12 +329,12 @@ func (b *ByocAws) WhoAmI(ctx context.Context) (*defangv1.WhoAmIResponse, error)
326
329
}, nil
327
330
}
328
331
329
- func (ByocAws ) GetVersions (context.Context ) (* defangv1.Version , error ) {
332
+ func (* ByocAws ) GetVersions (context.Context ) (* defangv1.Version , error ) {
330
333
cdVersion := CdImage [strings .LastIndex (CdImage , ":" )+ 1 :]
331
334
return & defangv1.Version {Fabric : cdVersion }, nil
332
335
}
333
336
334
- func (b * ByocAws ) Get (ctx context.Context , s * defangv1.ServiceID ) (* defangv1.ServiceInfo , error ) {
337
+ func (b * ByocAws ) GetService (ctx context.Context , s * defangv1.ServiceID ) (* defangv1.ServiceInfo , error ) {
335
338
all , err := b .GetServices (ctx )
336
339
if err != nil {
337
340
return nil , err
@@ -349,9 +352,6 @@ func (b *ByocAws) bucketName() string {
349
352
}
350
353
351
354
func (b * ByocAws ) environment () map [string ]string {
352
- if b .pulumiProject == "" {
353
- panic ("pulumiProject not set" )
354
- }
355
355
region := b .driver .Region // TODO: this should be the destination region, not the CD region; make customizable
356
356
return map [string ]string {
357
357
// "AWS_REGION": region.String(), should be set by ECS (because of CD task role)
@@ -360,7 +360,7 @@ func (b *ByocAws) environment() map[string]string {
360
360
"DEFANG_ORG" : b .tenantID ,
361
361
"DOMAIN" : b .customDomain ,
362
362
"PRIVATE_DOMAIN" : b .privateDomain ,
363
- "PROJECT" : b .pulumiProject ,
363
+ "PROJECT" : b .pulumiProject , // may be empty
364
364
"PULUMI_BACKEND_URL" : fmt .Sprintf (`s3://%s?region=%s&awssdk=v2` , b .bucketName (), region ),
365
365
"PULUMI_CONFIG_PASSPHRASE" : pkg .Getenv ("PULUMI_CONFIG_PASSPHRASE" , "asdf" ), // TODO: make customizable
366
366
"STACK" : b .pulumiStack ,
@@ -398,11 +398,9 @@ func (b *ByocAws) Delete(ctx context.Context, req *defangv1.DeleteRequest) (*def
398
398
return & defangv1.DeleteResponse {Etag : etag }, nil
399
399
}
400
400
401
- // stackDir returns a stack-qualified name , like the Pulumi TS function `stackDir`
401
+ // stackDir returns a stack-qualified path , like the Pulumi TS function `stackDir`
402
402
func (b * ByocAws ) stackDir (name string ) string {
403
- if b .pulumiProject == "" {
404
- panic ("pulumiProject not set" )
405
- }
403
+ ensure (b .pulumiProject != "" , "pulumiProject not set" )
406
404
return fmt .Sprintf ("/%s/%s/%s/%s" , DefangPrefix , b .pulumiProject , b .pulumiStack , name ) // same as shared/common.ts
407
405
}
408
406
@@ -422,6 +420,7 @@ func (b *ByocAws) GetServices(ctx context.Context) (*defangv1.ListServicesRespon
422
420
423
421
s3Client := s3 .NewFromConfig (cfg )
424
422
// Path to the state file, Defined at: https://github.com/defang-io/defang-mvp/blob/main/pulumi/cd/byoc/aws/index.ts#L89
423
+ ensure (b .pulumiProject != "" , "pulumiProject not set" )
425
424
path := fmt .Sprintf ("projects/%s/%s/project.pb" , b .pulumiProject , b .pulumiStack )
426
425
427
426
term .Debug (" - Getting services from" , bucketName , path )
@@ -445,10 +444,7 @@ func (b *ByocAws) GetServices(ctx context.Context) (*defangv1.ListServicesRespon
445
444
}
446
445
447
446
func (b * ByocAws ) getSecretID (name string ) string {
448
- if b .pulumiProject == "" {
449
- panic ("pulumiProject not set" )
450
- }
451
- return fmt .Sprintf ("/%s/%s/%s/%s" , DefangPrefix , b .pulumiProject , b .pulumiStack , name ) // same as defang_service.ts
447
+ return b .stackDir (name ) // same as defang_service.ts
452
448
}
453
449
454
450
func (b * ByocAws ) PutConfig (ctx context.Context , secret * defangv1.SecretValue ) error {
@@ -556,6 +552,7 @@ func (b *ByocAws) update(ctx context.Context, service *defangv1.Service) (*defan
556
552
return nil , fmt .Errorf ("missing config %s" , missing ) // retryable CodeFailedPrecondition
557
553
}
558
554
555
+ ensure (b .pulumiProject != "" , "pulumiProject not set" )
559
556
si := & defangv1.ServiceInfo {
560
557
Service : service ,
561
558
Project : b .pulumiProject , // was: tenant
@@ -671,6 +668,9 @@ func (b *ByocAws) getPrivateFqdn(fqn qualifiedName) string {
671
668
}
672
669
673
670
func (b * ByocAws ) getProjectDomain (zone string ) string {
671
+ if b .pulumiProject == "" {
672
+ return "" // no project name => no custom domain
673
+ }
674
674
projectLabel := dnsSafeLabel (b .pulumiProject )
675
675
if projectLabel == dnsSafeLabel (b .tenantID ) {
676
676
return dnsSafe (zone ) // the zone will already have the tenant ID
@@ -791,3 +791,9 @@ func (b *ByocAws) LoadProjectName() (string, error) {
791
791
}
792
792
return p .Name , nil
793
793
}
794
+
795
+ func ensure (cond bool , msg string ) {
796
+ if ! cond {
797
+ panic (msg )
798
+ }
799
+ }
0 commit comments