@@ -77,6 +77,9 @@ type LocalRunner struct {
7777
7878 // labels is the list of labels to apply to each resource being created
7979 labels map [string ]string
80+
81+ // logInternally outputs the logs of the service to the artifacts folder
82+ logInternally bool
8083}
8184
8285type task struct {
@@ -107,7 +110,7 @@ func newDockerClient() (*client.Client, error) {
107110}
108111
109112// 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 ) {
111114 client , err := newDockerClient ()
112115 if err != nil {
113116 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
124127 // Create the concrete instances to run
125128 instances := []* instance {}
126129 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- }
135130 component := FindComponent (service .ComponentName )
136131 if component == nil {
137132 return nil , fmt .Errorf ("component not found '%s'" , service .ComponentName )
138133 }
139134 instance := & instance {
140135 service : service ,
141- logs : logs ,
142136 component : component ,
143137 }
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+ }
144148 instances = append (instances , instance )
145149 }
146150
@@ -213,6 +217,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
213217 networkName : networkName ,
214218 instances : instances ,
215219 labels : labels ,
220+ logInternally : logInternally ,
216221 }
217222
218223 if interactive {
@@ -872,12 +877,14 @@ func (d *LocalRunner) trackContainerStatusAndLogs() {
872877 case events .ActionStart :
873878 d .updateTaskStatus (name , taskStatusStarted )
874879
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+ }
881888 case events .ActionDie :
882889 d .updateTaskStatus (name , taskStatusDie )
883890 log .Info ("container died" , "name" , name )
@@ -971,7 +978,9 @@ func (d *LocalRunner) Run() error {
971978
972979 // generate the output log file for each service so that it is available after Run is done
973980 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+ }
975984 }
976985
977986 // First start the services that are running in docker-compose
0 commit comments