mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-12-06 01:28:03 +01:00
Possibility to use -u (user) option in docker exec (#203)
* Add user option for docker exec * Add test for user option * Return test version for image * remove gitea config file * refactor tests * remove comments & fix image name * add docs * cleanup * Update README.md with suggested correction Co-authored-by: Frederik Ring <frederik.ring@gmail.com> * fix backup command & bind folder instead of volume --------- Co-authored-by: tao <generaltao.md@gmail.com> Co-authored-by: Frederik Ring <frederik.ring@gmail.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (s *script) exec(containerRef string, command string) ([]byte, []byte, error) {
|
||||
func (s *script) exec(containerRef string, command string, user string) ([]byte, []byte, error) {
|
||||
args, _ := argv.Argv(command, nil, nil)
|
||||
commandEnv := []string{
|
||||
fmt.Sprintf("COMMAND_RUNTIME_ARCHIVE_FILEPATH=%s", s.file),
|
||||
@@ -31,6 +31,7 @@ func (s *script) exec(containerRef string, command string) ([]byte, []byte, erro
|
||||
AttachStdin: true,
|
||||
AttachStderr: true,
|
||||
Env: commandEnv,
|
||||
User: user,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("exec: error creating container exec: %w", err)
|
||||
@@ -159,8 +160,11 @@ func (s *script) runLabeledCommands(label string) error {
|
||||
cmd, _ = c.Labels["docker-volume-backup.exec-post"]
|
||||
}
|
||||
|
||||
userLabelName := fmt.Sprintf("%s.user", label)
|
||||
user := c.Labels[userLabelName]
|
||||
|
||||
s.logger.Infof("Running %s command %s for container %s", label, cmd, strings.TrimPrefix(c.Names[0], "/"))
|
||||
stdout, stderr, err := s.exec(c.ID, cmd)
|
||||
stdout, stderr, err := s.exec(c.ID, cmd, user)
|
||||
if s.c.ExecForwardOutput {
|
||||
os.Stderr.Write(stderr)
|
||||
os.Stdout.Write(stdout)
|
||||
|
||||
Reference in New Issue
Block a user