-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e7595
commit d8068c0
Showing
14 changed files
with
245 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package addons | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/marcinhlybin/docker-env/logger" | ||
) | ||
|
||
type Script struct { | ||
Name string | ||
Path string | ||
} | ||
|
||
func NewScript(name, path string) *Script { | ||
return &Script{ | ||
Name: name, | ||
Path: path, | ||
} | ||
} | ||
|
||
// Helper function to run a script | ||
func RunScript(name, path string) error { | ||
s := NewScript(name, path) | ||
return s.Run() | ||
} | ||
|
||
func (s *Script) Run() error { | ||
if s.Path == "" { | ||
return nil | ||
} | ||
|
||
// Check if script exists | ||
if _, err := os.Stat(s.Path); err != nil { | ||
return fmt.Errorf("cannot open %s script '%s': %w", s.Name, s.Path, err) | ||
} | ||
|
||
logger.Info("Running", s.Name, "scripts") | ||
return s.execute() | ||
} | ||
|
||
func (s *Script) execute() error { | ||
cmd := exec.Command("/bin/sh", s.Path) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("%s script failed: %w", s.Name, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.