@@ -184,34 +184,6 @@ func (m *Manager) Stop(projectName string) error {
184184 return nil
185185}
186186
187- func (m * Manager ) Restart (projectName string ) error {
188- // Find all containers with this project name
189- args := filters .NewArgs ()
190- args .Add ("label" , fmt .Sprintf ("com.docker.compose.project=%s" , projectName ))
191-
192- containers , err := m .cli .ContainerList (m .ctx , container.ListOptions {Filters : args , All : true })
193- if err != nil {
194- return err
195- }
196-
197- if len (containers ) == 0 {
198- return fmt .Errorf ("no containers found for project %s" , projectName )
199- }
200-
201- timeout := 10
202- var errs []string
203- for _ , c := range containers {
204- if err := m .cli .ContainerRestart (m .ctx , c .ID , container.StopOptions {Timeout : & timeout }); err != nil {
205- errs = append (errs , fmt .Sprintf ("%s: %v" , c .Names [0 ], err ))
206- }
207- }
208-
209- if len (errs ) > 0 {
210- return fmt .Errorf ("errors restarting containers: %s" , strings .Join (errs , "; " ))
211- }
212- return nil
213- }
214-
215187func (m * Manager ) GetConfig (projectName string ) (string , error ) {
216188 // Find one container to get config path
217189 args := filters .NewArgs ()
@@ -253,6 +225,34 @@ func (m *Manager) GetConfig(projectName string) (string, error) {
253225 return sb .String (), nil
254226}
255227
228+ func (m * Manager ) getConfigPaths (projectName string ) ([]string , error ) {
229+ args := filters .NewArgs ()
230+ args .Add ("label" , fmt .Sprintf ("com.docker.compose.project=%s" , projectName ))
231+
232+ containers , err := m .cli .ContainerList (m .ctx , container.ListOptions {Filters : args , All : true , Limit : 1 })
233+ if err != nil {
234+ return nil , err
235+ }
236+
237+ if len (containers ) == 0 {
238+ return nil , fmt .Errorf ("project '%s' not found or has no active containers to read configuration from" , projectName )
239+ }
240+
241+ configFiles := containers [0 ].Labels ["com.docker.compose.project.config_files" ]
242+ if configFiles == "" {
243+ return nil , fmt .Errorf ("no config files label found for project '%s'" , projectName )
244+ }
245+
246+ var paths []string
247+ for f := range strings .SplitSeq (configFiles , "," ) {
248+ path := strings .TrimSpace (f )
249+ if path != "" {
250+ paths = append (paths , path )
251+ }
252+ }
253+ return paths , nil
254+ }
255+
256256func (m * Manager ) Logs (projectName string , since string , tail string , timestamps bool ) (io.ReadCloser , error ) {
257257 args := []string {"compose" , "-p" , projectName , "logs" , "-f" }
258258 if tail != "" && tail != "all" {
@@ -282,6 +282,58 @@ func (m *Manager) Logs(projectName string, since string, tail string, timestamps
282282 return & cmdReadCloser {pipe : stdout , cmd : cmd }, nil
283283}
284284
285+ func (m * Manager ) Down (projectName string ) error {
286+ var args []string
287+ args = append (args , "compose" , "-p" , projectName , "down" )
288+
289+ cmd := exec .Command ("docker" , args ... )
290+ output , err := cmd .CombinedOutput ()
291+ if err != nil {
292+ return fmt .Errorf ("error running docker compose down: %v, output: %s" , err , string (output ))
293+ }
294+ return nil
295+ }
296+
297+ func (m * Manager ) Up (projectName string ) error {
298+ paths , err := m .getConfigPaths (projectName )
299+ if err != nil {
300+ return fmt .Errorf ("failed to up project: %v" , err )
301+ }
302+
303+ args := []string {"compose" , "-p" , projectName }
304+ for _ , path := range paths {
305+ args = append (args , "-f" , path )
306+ }
307+ args = append (args , "up" , "-d" , "--force-recreate" )
308+
309+ cmd := exec .Command ("docker" , args ... )
310+ output , err := cmd .CombinedOutput ()
311+ if err != nil {
312+ return fmt .Errorf ("error running docker compose up: %v\n Output: %s" , err , string (output ))
313+ }
314+ return nil
315+ }
316+
317+ func (m * Manager ) Build (projectName string ) error {
318+ paths , err := m .getConfigPaths (projectName )
319+ if err != nil {
320+ return fmt .Errorf ("failed to build project: %v" , err )
321+ }
322+
323+ args := []string {"compose" , "-p" , projectName }
324+ for _ , path := range paths {
325+ args = append (args , "-f" , path )
326+ }
327+ args = append (args , "up" , "-d" , "--build" )
328+
329+ cmd := exec .Command ("docker" , args ... )
330+ output , err := cmd .CombinedOutput ()
331+ if err != nil {
332+ return fmt .Errorf ("error running docker compose up --build: %v\n Output: %s" , err , string (output ))
333+ }
334+ return nil
335+ }
336+
285337type cmdReadCloser struct {
286338 pipe io.ReadCloser
287339 cmd * exec.Cmd
@@ -297,4 +349,3 @@ func (c *cmdReadCloser) Close() error {
297349 }
298350 return c .pipe .Close ()
299351}
300-
0 commit comments