From b11e4a287544cef197a1ecf8a149f855c69623e1 Mon Sep 17 00:00:00 2001 From: Christoph Loy Date: Sun, 4 Sep 2022 11:05:10 +0200 Subject: [PATCH] Use restic version of host system in Docker container --- internal/backend.go | 11 ++++++++++- internal/utils.go | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/backend.go b/internal/backend.go index 40bb9d6..d23910f 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -6,6 +6,7 @@ import ( "fmt" "net/url" "os" + "os/exec" "strings" "github.com/cupcakearmy/autorestic/internal/colors" @@ -169,6 +170,11 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) { if hostname, err := os.Hostname(); err == nil { docker = append(docker, "--hostname", hostname) } + resticPath, err := GetResticPath() + if err != nil { + return -1, "", err + } + docker = append(docker, "--volume", resticPath+":/usr/bin/restic:ro") switch b.Type { case "local": actual := env["RESTIC_REPOSITORY"] @@ -180,6 +186,9 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) { case "gs": // No additional setup needed case "rclone": + if rclonePath, err := exec.LookPath("rclone"); err == nil { + docker = append(docker, "--volume", rclonePath+":/usr/bin/rclone:ro") + } // Read host rclone config and mount it into the container code, configFile, err := ExecuteCommand(ExecuteOptions{Command: "rclone"}, "config", "file") if err != nil { @@ -194,6 +203,6 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) { for key, value := range env { docker = append(docker, "--env", key+"="+value) } - docker = append(docker, "cupcakearmy/autorestic:"+VERSION, "-c", strings.Join(args, " ")) + docker = append(docker, "alpine:3", "-c", strings.Join(args, " ")) return ExecuteCommand(options, docker...) } diff --git a/internal/utils.go b/internal/utils.go index c8bf799..7972a42 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -21,6 +21,10 @@ func CheckIfResticIsCallable() bool { return CheckIfCommandIsCallable(flags.RESTIC_BIN) } +func GetResticPath() (result string, err error) { + return exec.LookPath(flags.RESTIC_BIN) +} + type ExecuteOptions struct { Command string Envs map[string]string