@@ -77,6 +77,9 @@ type LocalRunner struct {
77
77
78
78
// labels is the list of labels to apply to each resource being created
79
79
labels map [string ]string
80
+
81
+ // logInternally outputs the logs of the service to the artifacts folder
82
+ logInternally bool
80
83
}
81
84
82
85
type task struct {
@@ -107,7 +110,7 @@ func newDockerClient() (*client.Client, error) {
107
110
}
108
111
109
112
// TODO: add a runner config struct
110
- func NewLocalRunner (out * output , manifest * Manifest , overrides map [string ]string , interactive bool , bindHostPortsLocally bool , networkName string , labels map [string ]string ) (* LocalRunner , error ) {
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 ) {
111
114
client , err := newDockerClient ()
112
115
if err != nil {
113
116
return nil , fmt .Errorf ("failed to create docker client: %w" , err )
@@ -124,23 +127,24 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
124
127
// Create the concrete instances to run
125
128
instances := []* instance {}
126
129
for _ , service := range manifest .Services () {
127
- log_output , err := out .LogOutput (service .Name )
128
- if err != nil {
129
- return nil , fmt .Errorf ("error getting log output: %w" , err )
130
- }
131
- logs := & serviceLogs {
132
- logRef : log_output ,
133
- path : log_output .Name (),
134
- }
135
130
component := FindComponent (service .ComponentName )
136
131
if component == nil {
137
132
return nil , fmt .Errorf ("component not found '%s'" , service .ComponentName )
138
133
}
139
134
instance := & instance {
140
135
service : service ,
141
- logs : logs ,
142
136
component : component ,
143
137
}
138
+ if logInternally {
139
+ log_output , err := out .LogOutput (service .Name )
140
+ if err != nil {
141
+ return nil , fmt .Errorf ("error getting log output: %w" , err )
142
+ }
143
+ instance .logs = & serviceLogs {
144
+ logRef : log_output ,
145
+ path : log_output .Name (),
146
+ }
147
+ }
144
148
instances = append (instances , instance )
145
149
}
146
150
@@ -213,6 +217,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
213
217
networkName : networkName ,
214
218
instances : instances ,
215
219
labels : labels ,
220
+ logInternally : logInternally ,
216
221
}
217
222
218
223
if interactive {
@@ -872,12 +877,14 @@ func (d *LocalRunner) trackContainerStatusAndLogs() {
872
877
case events .ActionStart :
873
878
d .updateTaskStatus (name , taskStatusStarted )
874
879
875
- // the container has started, we can track the logs now
876
- go func () {
877
- if err := d .trackLogs (name , event .Actor .ID ); err != nil {
878
- log .Warn ("error tracking logs" , "error" , err )
879
- }
880
- }()
880
+ if d .logInternally {
881
+ // the container has started, we can track the logs now
882
+ go func () {
883
+ if err := d .trackLogs (name , event .Actor .ID ); err != nil {
884
+ log .Warn ("error tracking logs" , "error" , err )
885
+ }
886
+ }()
887
+ }
881
888
case events .ActionDie :
882
889
d .updateTaskStatus (name , taskStatusDie )
883
890
log .Info ("container died" , "name" , name )
@@ -971,7 +978,9 @@ func (d *LocalRunner) Run() error {
971
978
972
979
// generate the output log file for each service so that it is available after Run is done
973
980
for _ , instance := range d .instances {
974
- d .tasks [instance .service .Name ].logs = instance .logs .logRef
981
+ if instance .logs != nil {
982
+ d .tasks [instance .service .Name ].logs = instance .logs .logRef
983
+ }
975
984
}
976
985
977
986
// First start the services that are running in docker-compose
0 commit comments