4
4
"context"
5
5
"errors"
6
6
"fmt"
7
- "os"
8
- "os/exec"
9
7
"strings"
10
8
11
9
"github.com/DefangLabs/defang/src/pkg"
@@ -17,25 +15,6 @@ import (
17
15
composeTypes "github.com/compose-spec/compose-go/v2/types"
18
16
)
19
17
20
- const (
21
- CdDefaultImageTag = "public-beta" // for when a project has no cd version, this would be a old deployment
22
- CdLatestImageTag = "public-beta" // Update this to the latest CD service major version number whenever cd major is changed
23
- CdTaskPrefix = "defang-cd" // WARNING: renaming this practically deletes the Pulumi state
24
- )
25
-
26
- var (
27
- DefangPrefix = pkg .Getenv ("DEFANG_PREFIX" , "Defang" ) // prefix for all resources created by Defang
28
- )
29
-
30
- // This function was copied from Fabric controller and slightly modified to work with BYOC
31
- func DnsSafeLabel (fqn string ) string {
32
- return strings .ReplaceAll (DnsSafe (fqn ), "." , "-" )
33
- }
34
-
35
- func DnsSafe (fqdn string ) string {
36
- return strings .ToLower (fqdn )
37
- }
38
-
39
18
type ErrMultipleProjects struct {
40
19
ProjectNames []string
41
20
}
@@ -82,37 +61,6 @@ func MakeEnv(key string, value any) string {
82
61
return fmt .Sprintf ("%s=%q" , key , value )
83
62
}
84
63
85
- func runLocalCommand (ctx context.Context , dir string , env []string , cmd ... string ) error {
86
- command := exec .CommandContext (ctx , cmd [0 ], cmd [1 :]... )
87
- command .Dir = dir
88
- command .Env = env
89
- command .Stdout = os .Stdout
90
- command .Stderr = os .Stderr
91
- return command .Run ()
92
- }
93
-
94
- func DebugPulumi (ctx context.Context , env []string , cmd ... string ) error {
95
- // Locally we use the "dev" script from package.json to run Pulumi commands, which uses ts-node
96
- localCmd := append ([]string {"npm" , "run" , "dev" }, cmd ... )
97
- term .Debug (strings .Join (append (env , localCmd ... ), " " ))
98
-
99
- dir := os .Getenv ("DEFANG_PULUMI_DIR" )
100
- if dir == "" {
101
- return nil // show the shell command, but use regular Pulumi command in cloud task
102
- }
103
-
104
- // Run the Pulumi command locally
105
- env = append ([]string {
106
- "PATH=" + os .Getenv ("PATH" ),
107
- "USER=" + pkg .GetCurrentUser (), // needed for Pulumi
108
- }, env ... )
109
- if err := runLocalCommand (ctx , dir , env , localCmd ... ); err != nil {
110
- return err
111
- }
112
- // We always return an error to stop the CLI from "tailing" the cloud logs
113
- return errors .New ("local pulumi command succeeded; stopping" )
114
- }
115
-
116
64
func (b * ByocBaseClient ) GetProjectLastCDImage (ctx context.Context , projectName string ) (string , error ) {
117
65
projUpdate , err := b .projectBackend .GetProjectUpdate (ctx , projectName )
118
66
if err != nil {
@@ -126,11 +74,6 @@ func (b *ByocBaseClient) GetProjectLastCDImage(ctx context.Context, projectName
126
74
return projUpdate .CdVersion , nil
127
75
}
128
76
129
- func ExtractImageTag (fullQualifiedImageURI string ) string {
130
- index := strings .LastIndex (fullQualifiedImageURI , ":" )
131
- return fullQualifiedImageURI [index + 1 :]
132
- }
133
-
134
77
func (b * ByocBaseClient ) Debug (context.Context , * defangv1.DebugRequest ) (* defangv1.DebugResponse , error ) {
135
78
return nil , client .ErrNotImplemented ("AI debugging is not yet supported for BYOC" )
136
79
}
@@ -139,11 +82,6 @@ func (b *ByocBaseClient) SetCDImage(image string) {
139
82
b .CDImage = image
140
83
}
141
84
142
- func (b * ByocBaseClient ) GetVersions (context.Context ) (* defangv1.Version , error ) {
143
- // we want only the latest version of the CD service this CLI was compiled to expect
144
- return & defangv1.Version {Fabric : CdLatestImageTag }, nil
145
- }
146
-
147
85
func (b * ByocBaseClient ) ServiceDNS (name string ) string {
148
86
return DnsSafeLabel (name ) // TODO: consider merging this with getPrivateFqdn
149
87
}
@@ -194,7 +132,7 @@ func (b *ByocBaseClient) GetServiceInfos(ctx context.Context, projectName, deleg
194
132
serviceInfo .Etag = etag // same etag for all services
195
133
serviceInfoMap [service .Name ] = & Node {
196
134
Name : service .Name ,
197
- Deps : getDependencies ( service ),
135
+ Deps : service . GetDependencies ( ),
198
136
ServiceInfo : serviceInfo ,
199
137
}
200
138
}
@@ -234,14 +172,6 @@ func topologicalSort(nodes map[string]*Node) []*defangv1.ServiceInfo {
234
172
return serviceInfos
235
173
}
236
174
237
- func getDependencies (service composeTypes.ServiceConfig ) []string {
238
- deps := []string {}
239
- for depServiceName := range service .DependsOn {
240
- deps = append (deps , depServiceName )
241
- }
242
- return deps
243
- }
244
-
245
175
// This function was based on update function from Fabric controller and slightly modified to work with BYOC
246
176
func (b * ByocBaseClient ) update (ctx context.Context , projectName , delegateDomain string , service composeTypes.ServiceConfig ) (* defangv1.ServiceInfo , error ) {
247
177
if err := compose .ValidateService (& service ); err != nil {
@@ -250,9 +180,10 @@ func (b *ByocBaseClient) update(ctx context.Context, projectName, delegateDomain
250
180
251
181
pkg .Ensure (projectName != "" , "ProjectName not set" )
252
182
si := & defangv1.ServiceInfo {
253
- Etag : pkg .RandomID (), // TODO: could be hash for dedup/idempotency
254
- Project : projectName , // was: tenant
255
- Service : & defangv1.Service {Name : service .Name },
183
+ Etag : pkg .RandomID (), // TODO: could be hash for dedup/idempotency
184
+ Project : projectName , // was: tenant
185
+ Service : & defangv1.Service {Name : service .Name },
186
+ Domainname : service .DomainName ,
256
187
}
257
188
258
189
hasHost := false
@@ -340,7 +271,3 @@ func (b ByocBaseClient) GetPrivateFqdn(projectName string, fqn string) string {
340
271
safeFqn := DnsSafeLabel (fqn )
341
272
return fmt .Sprintf ("%s.%s" , safeFqn , GetPrivateDomain (projectName )) // TODO: consider merging this with ServiceDNS
342
273
}
343
-
344
- func GetPrivateDomain (projectName string ) string {
345
- return DnsSafeLabel (projectName ) + ".internal"
346
- }
0 commit comments