@@ -80,6 +80,9 @@ type LocalRunner struct {
80
80
81
81
// logInternally outputs the logs of the service to the artifacts folder
82
82
logInternally bool
83
+
84
+ // platform is the docker platform to use for the services
85
+ platform string
83
86
}
84
87
85
88
type task struct {
@@ -109,24 +112,35 @@ func newDockerClient() (*client.Client, error) {
109
112
return client , nil
110
113
}
111
114
112
- // TODO: add a runner config struct
113
- func NewLocalRunner (out * output , manifest * Manifest , overrides map [string ]string , interactive bool , bindHostPortsLocally bool , networkName string , labels map [string ]string , logInternally bool ) (* LocalRunner , error ) {
115
+ type RunnerConfig struct {
116
+ Out * output
117
+ Manifest * Manifest
118
+ Overrides map [string ]string
119
+ Interactive bool
120
+ BindHostPortsLocally bool
121
+ NetworkName string
122
+ Labels map [string ]string
123
+ LogInternally bool
124
+ Platform string
125
+ }
126
+
127
+ func NewLocalRunner (cfg * RunnerConfig ) (* LocalRunner , error ) {
114
128
client , err := newDockerClient ()
115
129
if err != nil {
116
130
return nil , fmt .Errorf ("failed to create docker client: %w" , err )
117
131
}
118
132
119
133
// merge the overrides with the manifest overrides
120
- if overrides == nil {
121
- overrides = make (map [string ]string )
134
+ if cfg . Overrides == nil {
135
+ cfg . Overrides = make (map [string ]string )
122
136
}
123
- for k , v := range manifest .overrides {
124
- overrides [k ] = v
137
+ for k , v := range cfg . Manifest .overrides {
138
+ cfg . Overrides [k ] = v
125
139
}
126
140
127
141
// Create the concrete instances to run
128
142
instances := []* instance {}
129
- for _ , service := range manifest .Services {
143
+ for _ , service := range cfg . Manifest .Services {
130
144
component := FindComponent (service .ComponentName )
131
145
if component == nil {
132
146
return nil , fmt .Errorf ("component not found '%s'" , service .ComponentName )
@@ -135,8 +149,8 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
135
149
service : service ,
136
150
component : component ,
137
151
}
138
- if logInternally {
139
- log_output , err := out .LogOutput (service .Name )
152
+ if cfg . LogInternally {
153
+ log_output , err := cfg . Out .LogOutput (service .Name )
140
154
if err != nil {
141
155
return nil , fmt .Errorf ("error getting log output: %w" , err )
142
156
}
@@ -160,11 +174,11 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
160
174
return nil , fmt .Errorf ("service '%s' must implement the ReleaseService interface" , ss .Name )
161
175
}
162
176
releaseArtifact := releaseService .ReleaseArtifact ()
163
- bin , err := DownloadRelease (out .homeDir , releaseArtifact )
177
+ bin , err := DownloadRelease (cfg . Out .homeDir , releaseArtifact )
164
178
if err != nil {
165
179
return nil , fmt .Errorf ("failed to download release artifact for service '%s': %w" , ss .Name , err )
166
180
}
167
- overrides [ss .Name ] = bin
181
+ cfg . Overrides [ss .Name ] = bin
168
182
}
169
183
}
170
184
@@ -173,7 +187,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
173
187
// - a path to an executable: In that case, we need to run it on the host machine
174
188
// and use the override map <- We only check this case, and if it is not a path, we assume
175
189
// it is a docker image. If it is not a docker image either, the error will be catched during the execution
176
- for k , v := range overrides {
190
+ for k , v := range cfg . Overrides {
177
191
if _ , err := os .Stat (v ); err != nil {
178
192
// this is a path to an executable, remove it from the overrides since we
179
193
// assume it s a docker image and add it to manifest
@@ -182,45 +196,46 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
182
196
return nil , fmt .Errorf ("invalid override docker image %s, expected image:tag" , v )
183
197
}
184
198
185
- srv := manifest .MustGetService (k )
199
+ srv := cfg . Manifest .MustGetService (k )
186
200
srv .Image = parts [0 ]
187
201
srv .Tag = parts [1 ]
188
202
189
- delete (overrides , k )
203
+ delete (cfg . Overrides , k )
190
204
continue
191
205
}
192
206
}
193
207
194
208
tasks := map [string ]* task {}
195
- for _ , svc := range manifest .Services {
209
+ for _ , svc := range cfg . Manifest .Services {
196
210
tasks [svc .Name ] = & task {
197
211
status : taskStatusPending ,
198
212
logs : nil ,
199
213
}
200
214
}
201
215
202
- if networkName == "" {
203
- networkName = defaultNetworkName
216
+ if cfg . NetworkName == "" {
217
+ cfg . NetworkName = defaultNetworkName
204
218
}
205
219
d := & LocalRunner {
206
- out : out ,
207
- manifest : manifest ,
220
+ out : cfg . Out ,
221
+ manifest : cfg . Manifest ,
208
222
client : client ,
209
223
reservedPorts : map [int ]bool {},
210
- overrides : overrides ,
224
+ overrides : cfg . Overrides ,
211
225
handles : []* exec.Cmd {},
212
226
tasks : tasks ,
213
227
taskUpdateCh : make (chan struct {}),
214
228
exitErr : make (chan error , 2 ),
215
- bindHostPortsLocally : bindHostPortsLocally ,
229
+ bindHostPortsLocally : cfg . BindHostPortsLocally ,
216
230
sessionID : uuid .New ().String (),
217
- networkName : networkName ,
231
+ networkName : cfg . NetworkName ,
218
232
instances : instances ,
219
- labels : labels ,
220
- logInternally : logInternally ,
233
+ labels : cfg .Labels ,
234
+ logInternally : cfg .LogInternally ,
235
+ platform : cfg .Platform ,
221
236
}
222
237
223
- if interactive {
238
+ if cfg . Interactive {
224
239
go d .printStatus ()
225
240
226
241
select {
@@ -656,6 +671,10 @@ func (d *LocalRunner) toDockerComposeService(s *Service) (map[string]interface{}
656
671
"labels" : labels ,
657
672
}
658
673
674
+ if d .platform != "" {
675
+ service ["platform" ] = d .platform
676
+ }
677
+
659
678
if len (envs ) > 0 {
660
679
service ["environment" ] = envs
661
680
}
0 commit comments