Skip to content

Commit c7df4e4

Browse files
committed
fix: ports and expose overriding issue
1 parent 3d7b0bf commit c7df4e4

1 file changed

Lines changed: 14 additions & 27 deletions

File tree

pkg/compose/compose.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ type Service struct {
1616
Command string `yaml:"command,omitempty"`
1717
ContainerName string `yaml:"container_name,omitempty"`
1818
Environment map[string]string `yaml:"environment,omitempty"`
19+
Expose []string `yaml:"expose,omitempty"`
1920
Image string `yaml:"image"`
20-
Ports []string `yaml:"ports,omitempty"`
2121
Restart string `yaml:"restart,omitempty"`
22+
Ports []string `yaml:"ports,omitempty"`
2223
Volumes []string `yaml:"volumes,omitempty"`
2324
}
2425

@@ -33,19 +34,21 @@ func NewCompose(options ...Option) *Compose {
3334
Services: map[string]Service{
3435
fmt.Sprintf("%s_redis", prefix): {
3536
ContainerName: fmt.Sprintf("%s_redis", prefix),
37+
Expose: []string{"6397"},
3638
Image: "redis:7-alpine",
3739
},
3840
fmt.Sprintf("%s_cockroachdb", prefix): {
41+
Command: "start-single-node --cluster-name=node --insecure",
3942
ContainerName: fmt.Sprintf("%s_cockroachdb", prefix),
43+
Expose: []string{"26257", "8080"},
4044
Image: "cockroachdb/cockroach:v23.2.5",
41-
Ports: []string{"26257:26257", "8080:8080"},
4245
Volumes: []string{fmt.Sprintf("%s:/cockroach/cockroach-data", cockroachdbVolume)},
43-
Command: "start-single-node --cluster-name=node --insecure",
4446
},
4547
fmt.Sprintf("%s_core", prefix): {
48+
Command: "--module=core",
4649
ContainerName: fmt.Sprintf("%s_core", prefix),
50+
Ports: []string{"8080:80"},
4751
Image: "rss3/node",
48-
Command: "--module=core",
4952
},
5053
},
5154
Volumes: map[string]*string{
@@ -65,13 +68,8 @@ func SetNodeVersion(version string) Option {
6568
services := c.Services
6669
for k, v := range services {
6770
if strings.Contains(v.Image, "rss3/node") {
68-
services[k] = Service{
69-
ContainerName: v.ContainerName,
70-
Image: fmt.Sprintf("rss3/node:%s", version),
71-
Environment: v.Environment,
72-
Volumes: v.Volumes,
73-
Command: v.Command,
74-
}
71+
v.Image = fmt.Sprintf("rss3/node:%s", version)
72+
c.Services[k] = v
7573
}
7674
}
7775

@@ -84,13 +82,8 @@ func SetNodeVolume() Option {
8482
services := c.Services
8583
for k, v := range services {
8684
if strings.Contains(v.Image, "rss3/node") {
87-
services[k] = Service{
88-
ContainerName: v.ContainerName,
89-
Image: v.Image,
90-
Environment: v.Environment,
91-
Volumes: []string{"${PWD}/config:/etc/rss3/node"},
92-
Command: v.Command,
93-
}
85+
v.Volumes = append(v.Volumes, "${PWD}/config:/etc/rss3/node")
86+
c.Services[k] = v
9487
}
9588
}
9689

@@ -102,14 +95,8 @@ func SetRestartPolicy() Option {
10295
return func(c *Compose) {
10396
services := c.Services
10497
for k, v := range services {
105-
services[k] = Service{
106-
ContainerName: v.ContainerName,
107-
Image: v.Image,
108-
Environment: v.Environment,
109-
Volumes: v.Volumes,
110-
Command: v.Command,
111-
Restart: "unless-stopped",
112-
}
98+
v.Restart = "unless-stopped"
99+
c.Services[k] = v
113100
}
114101

115102
c.Services = services
@@ -123,9 +110,9 @@ func WithWorkers(workers []*config.Module) Option {
123110
for _, worker := range workers {
124111
name := fmt.Sprintf("node-%s", worker.ID)
125112
services[name] = Service{
113+
Command: fmt.Sprintf("--module=worker --worker.id=%s", worker.ID),
126114
ContainerName: name,
127115
Image: "rss3/node",
128-
Command: fmt.Sprintf("--module=worker --worker.id=%s", worker.ID),
129116
}
130117
}
131118

0 commit comments

Comments
 (0)