Skip to content

Commit 49213fd

Browse files
committed
wip
1 parent b74a2a7 commit 49213fd

18 files changed

+8
-408
lines changed

src/pkg/cli/compose/convert.go

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -10,167 +10,6 @@ import (
1010
compose "github.com/compose-spec/compose-go/v2/types"
1111
)
1212

13-
// Deprecated: keep compose as-is
14-
func ConvertServices(serviceConfigs compose.Services) []*defangv1.Service {
15-
//
16-
// Publish updates
17-
//
18-
var services []*defangv1.Service
19-
for _, svccfg := range serviceConfigs {
20-
var healthcheck *defangv1.HealthCheck
21-
if svccfg.HealthCheck != nil && len(svccfg.HealthCheck.Test) > 0 && !svccfg.HealthCheck.Disable {
22-
healthcheck = &defangv1.HealthCheck{
23-
Test: svccfg.HealthCheck.Test,
24-
}
25-
if nil != svccfg.HealthCheck.Interval {
26-
healthcheck.Interval = uint32(*svccfg.HealthCheck.Interval / 1e9)
27-
}
28-
if nil != svccfg.HealthCheck.Timeout {
29-
healthcheck.Timeout = uint32(*svccfg.HealthCheck.Timeout / 1e9)
30-
}
31-
if nil != svccfg.HealthCheck.Retries {
32-
healthcheck.Retries = uint32(*svccfg.HealthCheck.Retries)
33-
}
34-
}
35-
36-
var deploy *defangv1.Deploy
37-
if svccfg.Deploy != nil {
38-
deploy = &defangv1.Deploy{}
39-
if svccfg.Deploy.Replicas != nil {
40-
deploy.Replicas = uint32(*svccfg.Deploy.Replicas)
41-
}
42-
43-
reservations := getResourceReservations(svccfg.Deploy.Resources)
44-
if reservations != nil {
45-
var devices []*defangv1.Device
46-
for _, d := range reservations.Devices {
47-
devices = append(devices, &defangv1.Device{
48-
Capabilities: d.Capabilities,
49-
Count: uint32(d.Count),
50-
Driver: d.Driver,
51-
})
52-
}
53-
deploy.Resources = &defangv1.Resources{
54-
Reservations: &defangv1.Resource{
55-
Cpus: float32(reservations.NanoCPUs),
56-
Memory: float32(reservations.MemoryBytes) / MiB,
57-
Devices: devices,
58-
},
59-
}
60-
}
61-
}
62-
63-
var build *defangv1.Build
64-
if svccfg.Build != nil {
65-
build = &defangv1.Build{
66-
Context: svccfg.Build.Context,
67-
Dockerfile: svccfg.Build.Dockerfile,
68-
ShmSize: float32(svccfg.Build.ShmSize) / MiB,
69-
Target: svccfg.Build.Target,
70-
}
71-
72-
if len(svccfg.Build.Args) > 0 {
73-
build.Args = make(map[string]string, len(svccfg.Build.Args))
74-
for key, value := range svccfg.Build.Args {
75-
if key == "" || value == nil {
76-
term.Warnf("service %q: skipping unset build argument %q", svccfg.Name, key)
77-
continue
78-
}
79-
build.Args[key] = *value
80-
}
81-
}
82-
}
83-
84-
// Extract environment variables
85-
var configs []*defangv1.Secret
86-
envs := make(map[string]string, len(svccfg.Environment))
87-
for key, value := range svccfg.Environment {
88-
if value == nil {
89-
// Add unset environment variables as "secrets"
90-
configs = append(configs, &defangv1.Secret{
91-
Source: key,
92-
})
93-
} else {
94-
envs[key] = *value
95-
}
96-
}
97-
98-
// Extract secret references; secrets are supposed to be files, not env, but it's kept for backward compatibility
99-
for i, secret := range svccfg.Secrets {
100-
if i == 0 { // only warn once
101-
term.Warnf("service %q: secrets will be exposed as environment variables, not files (use 'environment' instead)", svccfg.Name)
102-
}
103-
configs = append(configs, &defangv1.Secret{
104-
Source: secret.Source,
105-
})
106-
}
107-
108-
init := false
109-
if svccfg.Init != nil {
110-
init = *svccfg.Init
111-
}
112-
113-
var dnsRole string
114-
if dnsRoleVal := svccfg.Extensions["x-defang-dns-role"]; dnsRoleVal != nil {
115-
dnsRole = dnsRoleVal.(string) // already validated
116-
}
117-
118-
var staticFiles *defangv1.StaticFiles
119-
if staticFilesVal := svccfg.Extensions["x-defang-static-files"]; staticFilesVal != nil {
120-
if str, ok := staticFilesVal.(string); ok {
121-
staticFiles = &defangv1.StaticFiles{Folder: str}
122-
} else {
123-
obj := staticFilesVal.(map[string]interface{}) // already validated
124-
var redirects []string
125-
if r, ok := obj["redirects"].([]interface{}); ok {
126-
redirects = make([]string, len(r))
127-
for i, v := range r {
128-
redirects[i] = v.(string)
129-
}
130-
}
131-
staticFiles = &defangv1.StaticFiles{
132-
Folder: obj["folder"].(string),
133-
Redirects: redirects,
134-
}
135-
}
136-
}
137-
138-
var redis *defangv1.Redis
139-
if _, ok := svccfg.Extensions["x-defang-redis"]; ok {
140-
redis = &defangv1.Redis{}
141-
}
142-
143-
var postgres *defangv1.Postgres
144-
if _, ok := svccfg.Extensions["x-defang-postgres"]; ok {
145-
postgres = &defangv1.Postgres{}
146-
}
147-
148-
network := network(&svccfg)
149-
ports := convertPorts(svccfg.Ports)
150-
services = append(services, &defangv1.Service{
151-
Name: svccfg.Name,
152-
Image: svccfg.Image,
153-
Build: build,
154-
Internal: network == defangv1.Network_PRIVATE,
155-
Networks: network,
156-
Init: init,
157-
Ports: ports,
158-
Healthcheck: healthcheck,
159-
Deploy: deploy,
160-
Environment: envs,
161-
Secrets: configs,
162-
Command: svccfg.Command,
163-
Domainname: svccfg.DomainName,
164-
Platform: convertPlatform(svccfg.Platform),
165-
DnsRole: dnsRole,
166-
StaticFiles: staticFiles,
167-
Redis: redis,
168-
Postgres: postgres,
169-
})
170-
}
171-
return services
172-
}
173-
17413
func getResourceReservations(r compose.Resources) *compose.Resource {
17514
if r.Reservations == nil {
17615
// TODO: we might not want to default to all the limits, maybe only memory?

src/pkg/cli/compose/convert_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package compose
33
import (
44
"context"
55
"encoding/json"
6-
"slices"
76
"strings"
87
"testing"
98

10-
"github.com/DefangLabs/defang/src/pkg/cli/client"
119
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
1210
"github.com/compose-spec/compose-go/v2/loader"
1311
"github.com/compose-spec/compose-go/v2/types"
@@ -176,30 +174,3 @@ func TestComposeBlob(t *testing.T) {
176174
t.Errorf("expected empty blob, got %v", blob)
177175
}
178176
}
179-
180-
func TestConvert(t *testing.T) {
181-
testRunCompose(t, func(t *testing.T, path string) {
182-
loader := Loader{path}
183-
proj, err := loader.LoadCompose(context.Background())
184-
if err != nil {
185-
t.Fatal(err)
186-
}
187-
if err := FixupServices(context.Background(), client.MockClient{}, proj.Services, BuildContextIgnore); err != nil {
188-
t.Fatal(err)
189-
}
190-
191-
services := ConvertServices(proj.Services)
192-
// The order of the services is not guaranteed, so we sort the services before comparing
193-
slices.SortFunc(services, func(i, j *defangv1.Service) int { return strings.Compare(i.Name, j.Name) })
194-
195-
// Convert the protobuf services to pretty JSON for comparison (YAML would include all the zero values)
196-
actual, err := json.MarshalIndent(services, "", " ")
197-
if err != nil {
198-
t.Fatal(err)
199-
}
200-
201-
if err := compare(actual, path+".convert"); err != nil {
202-
t.Error(err)
203-
}
204-
})
205-
}

src/pkg/cli/composeUp.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,12 @@ func ComposeUp(ctx context.Context, c client.Client, force bool) (*defangv1.Depl
4646
return nil, project, err
4747
}
4848

49-
services := compose.ConvertServices(project.Services)
50-
if len(services) == 0 {
51-
return nil, project, &ComposeError{fmt.Errorf("no services found")}
52-
}
53-
5449
if DoDryRun {
55-
for _, service := range services {
56-
PrintObject(service.Name, service)
57-
}
50+
yaml, _ := project.MarshalYAML()
51+
fmt.Println(string(yaml))
5852
return nil, project, ErrDryRun
5953
}
6054

61-
for _, service := range services {
62-
term.Info("Deploying service", service.Name)
63-
}
64-
6555
bytes, err := project.MarshalYAML()
6656
if err != nil {
6757
return nil, project, err
@@ -77,10 +67,13 @@ func ComposeUp(ctx context.Context, c client.Client, force bool) (*defangv1.Depl
7767
return nil, project, err
7868
}
7969

70+
for _, service := range project.Services {
71+
term.Info("Deploying service", service.Name)
72+
}
73+
8074
resp, err := c.Deploy(ctx, &defangv1.DeployRequest{
81-
Project: project.Name,
82-
Services: services,
83-
Compose: str,
75+
Project: project.Name,
76+
Compose: str,
8477
})
8578
if err != nil {
8679
return nil, project, err

src/tests/Fancy-Proj_Dir/compose.yaml.convert

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/alttestproj/compose.yaml.convert

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/tests/configoverride/compose.yaml.convert

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/tests/empty/compose.yaml.convert

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/emptyenv/compose.yaml.convert

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/tests/longname/compose.yaml.convert

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/tests/networks/compose.yaml.convert

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/tests/noprojname/compose.yaml.convert

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/platforms/compose.yaml.convert

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/tests/profiles/compose.yaml.convert

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)